| title | C++ |
|---|---|
| description | C++ 加载器指南。 |
| lead | C++ 加载器指南。 |
| date | 2022-03-10 08:00:00 +0800 |
| lastmod | 2022-03-10 08:00:00 +0800 |
| draft | false |
| images | |
| weight | 3220 |
| toc | true |
const ProtobufMessage& Data()
获取内部的 protobuf 消息数据。
const MapValueType* Get(k1 KEY1, k2 KEY2...) const
获取第 N 级的映射值。请注意,这仅适用于每个级别消息的第一个映射字段。
前提条件:你需要将元表选项
OrderedMap设置为true。请参阅 元表选项:OrderedMap。
const OrderedMapValueType* GetOrderedMap(k1 KEY1, k2 KEY2...) const
获取第 N 级的有序映射值。请注意,这仅适用于每个级别消息的第一个映射字段。
前提条件:你需要适当设置元表选项
Index。请参阅 元表选项:Index。
如果索引名称是 Chapter,则访问器如下:
const Index_ChapterMap& FindChapter() const:获取整个哈希映射。const vector<ParentType>* FindChapter(k1 KEY1, k2 KEY2...) const:通过键查找值。一个键可能对应多个值,这些值通过向量返回。const ParentType* FindFirstChapter(k1 KEY1, k2 KEY2...) const:通过键查找第一个值。
前提条件:你需要适当设置元表选项
OrderedIndex。请参阅 元表选项:OrderedIndex。
如果有序索引名称是 Chapter,则访问器如下:
const OrderedIndex_ChapterMap& FindChapter() const:获取整个有序映射。const vector<ParentType>* FindChapter(k1 KEY1, k2 KEY2...) const:通过键查找值。一个键可能对应多个值,这些值通过向量返回。const ParentType* FindFirstChapter(k1 KEY1, k2 KEY2...) const:通过键查找第一个值。
如果内置 API 不足以满足你的业务逻辑,你可以添加一个自定义消息器,在其中可以基于加载的配置对象编写预处理逻辑。
示例:cpp-tableau-loader/hub/custom
custom_xxx_conf.h:
#pragma once
#include "protoconf/hub.pc.h"
#include "protoconf/xxx_conf.pc.h"
class CustomXXXConf : public tableau::Messager {
public:
static const std::string& Name() { return kCustomName; };
virtual bool Load(const std::string& dir, tableau::Format fmt,
const tableau::LoadOptions* options = nullptr) override {
return true;
}
virtual bool ProcessAfterLoadAll(const tableau::Hub& hub) override;
private:
static const std::string kCustomName;
// TODO: 添加自定义数据字段。
};custom_xxx_conf.cpp:
#include "hub/custom/xxx/custom_xxx_conf.h"
const std::string CustomXXXConf::kCustomName = "CustomXXXConf";
bool CustomItemConf::ProcessAfterLoadAll(const tableau::Hub& hub) {
// TODO: 在此处实现。
return true;
}使用此 protoc 插件的示例: cpp-tableau-loader/gen.sh。
请查看 cpp-tableau-loader。