OSDN Git Service

trunk整理
[ultramonkey-l7/ultramonkey-l7-v3.git] / l7vsd / unit_tests / l7vs_logger / parameter_stub / parameter_impl.h
1 #ifndef __PARAMETER_IMPL_H__
2 #define __PARAMETER_IMPL_H__
3
4 #include "parameter_enum.h"
5 #include <iostream>
6 #include <string>
7 #include <map>
8 #include <boost/program_options.hpp>
9 #include "error_code.h"
10 #include "logger_enum.h"
11
12 #include <boost/function.hpp>
13 #include <boost/noncopyable.hpp>
14 #include <boost/thread.hpp>
15
16
17 namespace l7vs
18 {
19         struct  component{
20                 std::string     section;
21                 void            (*function)();
22                 component(){ section = ""; function = NULL;}
23                 component( std::string str, void (*p_func)() ){ section = str; function = p_func;}
24                 component& operator=(const component& in_comp){ section = in_comp.section; function = in_comp.function;return *this;}
25         };
26         class ParameterImpl
27         {
28 protected:
29         typedef std::map< std::string, int >                    int_map_type;
30         typedef std::map< std::string, std::string >            string_map_type;
31         typedef std::multimap< std::string, std::string >       multistring_map_type;
32
33         //! parameter data of string
34         string_map_type                                                 stringMap;
35         //! parameter data of multi string
36         multistring_map_type                                            multistringMap;
37         //! parameter data of int
38         int_map_type                                                    intMap;
39         //! create mutex
40         boost::mutex                                                    create_mutex;
41         //! read / write mutex
42         boost::mutex                                                    param_mutex;
43         //! componenttag to section name map
44         std::map< PARAMETER_COMPONENT_TAG, std::string >
45                                                                                         tag_section_table_map;
46         //! constractor
47         ParameterImpl(){}
48         //! destractor
49         ~ParameterImpl(){}
50 public:
51         //! instansgetter
52         //! @return instance
53         static ParameterImpl & get_instance(){
54                 static ParameterImpl instance;
55                 return instance;
56         }
57         //! initialize
58         //! @return true success
59         //! @return false failer
60         bool    init();
61
62         //! target component read
63         //!     @param[in]      component tag
64         //! @return false failer
65         //! @return true success
66         bool    read_file( const PARAMETER_COMPONENT_TAG );
67
68         //! target component read specified filename
69         //!     @param[in]      component tag
70         //!     @param[in]      file name
71         //! @return false failer
72         //! @return true success
73         bool    read_specified_file( const PARAMETER_COMPONENT_TAG, const std::string& filenamez );
74
75         //! int value getter
76         //! @param[in]  component tag
77         //! @param[in]  keystring
78         //! @param[out] errorcode
79         //! @return             int value
80         int     get_int( const PARAMETER_COMPONENT_TAG, const std::string&, error_code& );
81
82         //! string value getter
83         //! @param[in]  component tag
84         //! @param[in]  keystring
85         //! @param[out] errorcode
86         //! @return             string value
87         std::string     get_string( const PARAMETER_COMPONENT_TAG, const std::string&, error_code& );
88
89         //! multistring value getter
90         //! @param[in]  component tag
91         //! @param[in]  keystring
92         //! @param[inout]       multistring map
93         //! @param[out] errorcode
94         //! @return     last foundstring value
95         std::string     get_multistring( const PARAMETER_COMPONENT_TAG, const std::string&, multistring_map_type&, error_code& );
96
97         void    setIntValue(const PARAMETER_COMPONENT_TAG comp, const std::string& key, const int value);
98
99         void    setStringValue(const PARAMETER_COMPONENT_TAG comp, const std::string& key, const std::string& value);
100
101         void    deleteIntValue(const PARAMETER_COMPONENT_TAG comp, const std::string& key);
102         void    deleteStringValue(const PARAMETER_COMPONENT_TAG comp, const std::string& key);
103
104
105         };
106 };
107 #endif  //__PARAMETER_IMPL_H__