| 301 |
ashish |
1 |
// Copyright (c) 2007-2008 Facebook
|
|
|
2 |
//
|
|
|
3 |
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
4 |
// you may not use this file except in compliance with the License.
|
|
|
5 |
// You may obtain a copy of the License at
|
|
|
6 |
//
|
|
|
7 |
// http://www.apache.org/licenses/LICENSE-2.0
|
|
|
8 |
//
|
|
|
9 |
// Unless required by applicable law or agreed to in writing, software
|
|
|
10 |
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
11 |
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
12 |
// See the License for the specific language governing permissions and
|
|
|
13 |
// limitations under the License.
|
|
|
14 |
//
|
|
|
15 |
// See accompanying file LICENSE or visit the Scribe site at:
|
|
|
16 |
// http://developers.facebook.com/scribe/
|
|
|
17 |
//
|
|
|
18 |
// @author Bobby Johnson
|
|
|
19 |
// @author Jason Sobel
|
|
|
20 |
|
|
|
21 |
#ifndef SCRIBE_CONF_H
|
|
|
22 |
#define SCRIBE_CONF_H
|
|
|
23 |
|
|
|
24 |
#include <string>
|
|
|
25 |
#include <vector>
|
|
|
26 |
#include <queue>
|
|
|
27 |
#include <iostream>
|
|
|
28 |
#include <fstream>
|
|
|
29 |
|
|
|
30 |
#include "src/gen-cpp/scribe.h"
|
|
|
31 |
|
|
|
32 |
/*
|
|
|
33 |
* This class reads and parses a configuration
|
|
|
34 |
* describing a hierarchy of store objects.
|
|
|
35 |
*
|
|
|
36 |
* It reads a conf file with a proprietary format, although it could
|
|
|
37 |
* be changed to xml (or anything else that supports hierarchy) by only
|
|
|
38 |
* changing the code in this class.
|
|
|
39 |
*/
|
|
|
40 |
class StoreConf;
|
|
|
41 |
typedef boost::shared_ptr<StoreConf> pStoreConf;
|
|
|
42 |
typedef std::map<std::string, std::string> string_map_t;
|
|
|
43 |
typedef std::map<std::string, pStoreConf> store_conf_map_t;
|
|
|
44 |
|
|
|
45 |
class StoreConf {
|
|
|
46 |
|
|
|
47 |
public:
|
|
|
48 |
StoreConf();
|
|
|
49 |
virtual ~StoreConf();
|
|
|
50 |
|
|
|
51 |
// Return value is true if the key exists, and false if it doesn't.
|
|
|
52 |
// This doesn't check for garbage ints or empty strings.
|
|
|
53 |
// The return parameter is untouched if the key isn't found.
|
|
|
54 |
void getAllStores(std::vector<pStoreConf>& _return);
|
|
|
55 |
bool getStore(const std::string& storeName, pStoreConf& _return);
|
|
|
56 |
bool getInt(const std::string& intName, long int& _return);
|
|
|
57 |
bool getUnsigned(const std::string& intName, unsigned long int& _return);
|
|
|
58 |
bool getString(const std::string& stringName, std::string& _return);
|
|
|
59 |
|
|
|
60 |
void setString(const std::string& stringName, const std::string& value);
|
|
|
61 |
void setUnsigned(const std::string& intName, unsigned long value);
|
|
|
62 |
|
|
|
63 |
// Reads configuration from a file and throws an exception if it fails.
|
|
|
64 |
void parseConfig(const std::string& filename);
|
|
|
65 |
|
|
|
66 |
private:
|
|
|
67 |
string_map_t values;
|
|
|
68 |
store_conf_map_t stores;
|
|
|
69 |
|
|
|
70 |
static bool parseStore(/*in,out*/ std::queue<std::string>& raw_config,
|
|
|
71 |
/*out*/ StoreConf* parsed_config);
|
|
|
72 |
static std::string trimString(const std::string& str);
|
|
|
73 |
bool readConfFile(const std::string& filename, std::queue<std::string>& _return);
|
|
|
74 |
};
|
|
|
75 |
|
|
|
76 |
#endif //!defined SCRIBE_CONF_H
|