storage.h 1.0 KB
Newer Older
S
superjom 已提交
1 2
#ifndef VISUALDL_STORAGE_STORAGE_H
#define VISUALDL_STORAGE_STORAGE_H
S
superjom 已提交
3

S
superjom 已提交
4 5
#include <glog/logging.h>
#include <vector>
S
superjom 已提交
6

S
superjom 已提交
7
#include "visualdl/storage/storage.pb.h"
S
superjom 已提交
8
#include "visualdl/storage/tablet.h"
S
superjom 已提交
9 10 11

namespace visualdl {

12
/*
S
superjom 已提交
13
 * Helper for operations on storage::Storage.
14
 */
S
superjom 已提交
15 16 17
struct Storage {
  Storage() {}
  Storage(storage::Storage* x) : data_(x) {
18 19
    time_t t;
    time(&t);
S
superjom 已提交
20
    data_->set_timestamp(t);
21 22
  }

S
superjom 已提交
23 24 25
  std::vector<std::string> Modes() {
    return std::vector<std::string>(data_->modes().begin(),
                                    data_->modes().end());
S
Superjom 已提交
26
  }
27

S
superjom 已提交
28
  void AddMode(const std::string& x) { *data_->add_modes() = x; }
29

S
superjom 已提交
30 31 32 33 34 35
  Tablet AddTablet(const std::string& x) {
    AddTag(x);
    CHECK(tablets_.count(x) == 0) << "tablet [" << x << "] has existed";
    tablets_[x] = storage::Tablet();
    return Tablet(&tablets_[x]);
  }
36

S
superjom 已提交
37 38
protected:
  void AddTag(const std::string& x) { *data_->add_tags() = x; }
39

40 41
private:
  std::map<std::string, storage::Tablet> tablets_;
S
superjom 已提交
42
  storage::Storage* data_{nullptr};
43 44 45
};

}  // namespace visualdl
S
superjom 已提交
46

S
superjom 已提交
47
#endif