forked from facebookarchive/scribe
-
Notifications
You must be signed in to change notification settings - Fork 0
/
conf.h
77 lines (68 loc) · 3.04 KB
/
conf.h
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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
// Copyright (c) 2007-2008 Facebook
//
// Licensed 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.
//
// See accompanying file LICENSE or visit the Scribe site at:
// http://developers.facebook.com/scribe/
//
// @author Bobby Johnson
// @author Jason Sobel
#ifndef SCRIBE_CONF_H
#define SCRIBE_CONF_H
#include "common.h"
/*
* This class reads and parses a configuration
* describing a hierarchy of store objects.
*
* It reads a conf file with a proprietary format, although it could
* be changed to xml (or anything else that supports hierarchy) by only
* changing the code in this class.
*/
class StoreConf;
typedef boost::shared_ptr<StoreConf> pStoreConf;
typedef std::map<std::string, std::string> string_map_t;
typedef std::map<std::string, pStoreConf> store_conf_map_t;
std::ostream& operator<<(std::ostream& os, const StoreConf& storeConf);
class StoreConf {
friend std::ostream& operator<<(std::ostream& os, const StoreConf& storeConf);
public:
StoreConf();
virtual ~StoreConf();
// Return value is true if the key exists, and false if it doesn't.
// This doesn't check for garbage ints or empty strings.
// The return parameter is untouched if the key isn't found.
void getAllStores(std::vector<pStoreConf>& _return);
bool getStore(const std::string& storeName, pStoreConf& _return);
bool getInt(const std::string& intName, long int& _return) const;
bool getUnsigned(const std::string& intName, unsigned long int& _return) const;
bool getUnsignedLongLong(const std::string& intName, unsigned long long& _return) const;
bool getFloat(const std::string& floatName, float & _return) const;
bool getString(const std::string& stringName, std::string& _return) const;
void setString(const std::string& stringName, const std::string& value);
void setUnsigned(const std::string& intName, unsigned long value);
void setUnsignedLongLong(const std::string& intName, unsigned long long value);
// Reads configuration from a file and throws an exception if it fails.
void parseConfig(const std::string& filename);
void setParent(pStoreConf parent);
private:
string_map_t values;
store_conf_map_t stores;
pStoreConf parent;
static bool parseStore(/*in,out*/ std::queue<std::string>& raw_config,
/*out*/ StoreConf* parsed_config);
static std::string trimString(const std::string& str);
bool readConfFile(const std::string& filename, std::queue<std::string>& _return);
std::ostream& print(std::ostream& os, uint32_t depth, bool useSpace = true,
uint32_t tabw = 2) const;
};
#endif //!defined SCRIBE_CONF_H