作者: 韩晨旭 10225101440 李畅 10225102463
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

40 lines
961 B

  1. #ifndef STORAGE_LEVELDB_FIELDS_H_
  2. #define STORAGE_LEVELDB_FIELDS_H_
  3. #include <map>
  4. #include <string>
  5. #include <vector>
  6. #include "leveldb/slice.h"
  7. namespace leveldb {
  8. using Field = std::pair<std::string, std::string>;
  9. using FieldArray = std::vector<std::pair<std::string, std::string>>;
  10. class Fields {
  11. public:
  12. // 从FieldArray构建Fields
  13. explicit Fields(const FieldArray& field_array);
  14. // 从LevelDB存储的Value中解码出Fields
  15. explicit Fields(const Slice& fields_str);
  16. Fields() = default;
  17. ~Fields();
  18. // 重载[]运算符简便对字段的修改和访问操作
  19. std::string& operator[](const std::string& field_name);
  20. // 获取当前Fields对应的FieldArray
  21. FieldArray GetFieldArray() const;
  22. // 将Fields编码为存入LevelDB的Value
  23. std::string Serialize() const;
  24. private:
  25. std::map<std::string, std::string> _fields;
  26. };
  27. } // namespace leveldb
  28. #endif //STORAGE_LEVELDB_FIELDS_H_