ConfigNode.h 2.2 KB
Newer Older
G
groot 已提交
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63
/*******************************************************************************
 * Copyright 上海赜睿信息科技有限公司(Zilliz) - All Rights Reserved
 * Unauthorized copying of this file, via any medium is strictly prohibited.
 * Proprietary and confidential.
 ******************************************************************************/
#pragma once

#include <vector>
#include <string>
#include <map>

namespace zilliz {
namespace vecwise {
namespace server {

class ConfigNode;
typedef std::vector<ConfigNode> ConfigNodeArr;

class ConfigNode {
 public:
    void Combine(const ConfigNode& target);

    //key/value pair config
    void SetValue(const std::string &key, const std::string &value);

    std::string GetValue(const std::string &param_key, const std::string &default_val = "") const;
    bool GetBoolValue(const std::string &param_key, bool default_val = false) const;
    int32_t GetInt32Value(const std::string &param_key, int32_t default_val = 0) const;
    int64_t GetInt64Value(const std::string &param_key, int64_t default_val = 0) const;
    float GetFloatValue(const std::string &param_key, float default_val = 0.0) const;
    double GetDoubleValue(const std::string &param_key, double default_val = 0.0) const;

    const std::map<std::string, std::string>& GetConfig() const;
    void ClearConfig();

    //key/object config
    void AddChild(const std::string &type_name, const ConfigNode &config);
    ConfigNode GetChild(const std::string &type_name) const;
    ConfigNode& GetChild(const std::string &type_name);
    void GetChildren(ConfigNodeArr &arr) const;

    const std::map<std::string, ConfigNode>& GetChildren() const;
    void ClearChildren();

    //key/sequence config
    void AddSequenceItem(const std::string &key, const std::string &item);
    std::vector<std::string> GetSequence(const std::string &key) const;

    const std::map<std::string, std::vector<std::string> >& GetSequences() const;
    void ClearSequences();

    void PrintAll(const std::string &prefix = "") const;
    std::string DumpString(const std::string &prefix = "") const;

 private:
    std::map<std::string, std::string> config_;
    std::map<std::string, ConfigNode> children_;
    std::map<std::string, std::vector<std::string> > sequences_;
};

}
}
}