Update doc revision and pdf cover.
[apps/low-level-can-service.git] / CAN-binder / libs / ini-config / ini-config.hpp
1 /*
2  * Copyright (C) 2015, 2016 ,2017 "IoT.bzh"
3  * Author "Loïc Collignon" <loic.collignon@iot.bzh>
4  *
5  * Licensed under the Apache License, Version 2.0 (the "License");
6  * you may not use this file except in compliance with the License.
7  * You may obtain a copy of the License at
8  *
9  *       http://www.apache.org/licenses/LICENSE-2.0
10  *
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an "AS IS" BASIS,
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  * See the License for the specific language governing permissions and
15  * limitations under the License.
16  */
17
18 #ifndef INI_CONFIG_HPP
19 #define INI_CONFIG_HPP
20
21 #include <string>
22 #include <fstream>
23 #include <map>
24 #include <regex>
25 #include <algorithm>
26
27 // Représente un fichier de configuration.
28 class ini_config
29 {
30 public:
31         using map = std::map<std::string, std::string>;
32
33         void read_file(const std::string& filename);
34
35         map get_keys(const std::string& section, bool wo_prefix=true);
36         std::string get_value(const std::string& section, const std::string& key);
37
38         typename map::size_type size() const { return config_.size(); }
39         typename map::iterator begin() { return config_.begin(); }
40         typename map::iterator end() { return config_.end(); }
41         typename map::const_iterator cbegin() const { return config_.cbegin(); }
42         typename map::const_iterator cend() const { return config_.cend(); }
43         typename map::reverse_iterator rbegin() { return config_.rbegin(); }
44         typename map::reverse_iterator rend() { return config_.rend(); }
45         typename map::const_reverse_iterator crbegin() const { return config_.crbegin(); }
46         typename map::const_reverse_iterator crend() const { return config_.crend(); }
47
48 private:
49         map config_;
50
51         enum class line_type
52         {
53                 ignore = 0,
54                 section = 1,
55                 key = 2
56         };
57
58         line_type qualify(std::string& line);
59 };
60
61 #endif // INI_CONFIG_HPP