ConfigNode.h 2.8 KB
Newer Older
J
jinhai 已提交
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
// Licensed to the Apache Software Foundation (ASF) under one
// or more contributor license agreements.  See the NOTICE file
// distributed with this work for additional information
// regarding copyright ownership.  The ASF licenses this file
// to you under the Apache License, Version 2.0 (the
// "License"); you may not use this file except in compliance
// with the License.  You may obtain a copy of the License at
//
//   http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing,
// software distributed under the License is distributed on an
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
// KIND, either express or implied.  See the License for the
// specific language governing permissions and limitations
// under the License.

G
groot 已提交
18 19 20
#pragma once

#include <map>
S
starlord 已提交
21 22
#include <string>
#include <vector>
G
groot 已提交
23

J
jinhai 已提交
24
namespace milvus {
G
groot 已提交
25 26 27 28 29 30 31
namespace server {

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

class ConfigNode {
 public:
S
starlord 已提交
32 33
    void
    Combine(const ConfigNode& target);
G
groot 已提交
34

S
starlord 已提交
35 36 37
    // key/value pair config
    void
    SetValue(const std::string& key, const std::string& value);
G
groot 已提交
38

S
starlord 已提交
39 40 41 42 43 44 45 46 47 48 49 50
    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;
G
groot 已提交
51

S
starlord 已提交
52 53 54 55
    const std::map<std::string, std::string>&
    GetConfig() const;
    void
    ClearConfig();
G
groot 已提交
56

S
starlord 已提交
57 58 59 60 61 62 63 64 65
    // 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;
G
groot 已提交
66

S
starlord 已提交
67 68 69 70
    const std::map<std::string, ConfigNode>&
    GetChildren() const;
    void
    ClearChildren();
G
groot 已提交
71

S
starlord 已提交
72 73 74 75 76
    // key/sequence config
    void
    AddSequenceItem(const std::string& key, const std::string& item);
    std::vector<std::string>
    GetSequence(const std::string& key) const;
G
groot 已提交
77

S
starlord 已提交
78 79 80 81
    const std::map<std::string, std::vector<std::string> >&
    GetSequences() const;
    void
    ClearSequences();
G
groot 已提交
82

S
starlord 已提交
83 84 85 86
    void
    PrintAll(const std::string& prefix = "") const;
    std::string
    DumpString(const std::string& prefix = "") const;
G
groot 已提交
87 88 89 90 91 92 93

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

S
starlord 已提交
94 95
}  // namespace server
}  // namespace milvus