Core Library  1.7.0.0
Library containing core utilities and tools for threading, networking, logging, INI and CSV file management etc.
IniFileLines.h
Go to the documentation of this file.
1 // This file is part of CoreLibrary containing useful reusable utility
2 // classes.
3 //
4 // Copyright (C) 2014 to present, Duncan Crutchley
5 // Contact <dac1976github@outlook.com>
6 //
7 // This program is free software: you can redistribute it and/or modify
8 // it under the terms of the GNU Lesser General Public License as published
9 // by the Free Software Foundation, either version 3 of the License, or
10 // (at your option) any later version.
11 //
12 // This program is distributed in the hope that it will be useful,
13 // but WITHOUT ANY WARRANTY; without even the implied warranty of
14 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 // GNU General Public License and GNU Lesser General Public License
16 // for more details.
17 //
18 // You should have received a copy of the GNU General Public License
19 // and GNU Lesser General Public License along with this program. If
20 // not, see <http://www.gnu.org/licenses/>.
21 
27 #ifndef INIFILELINES
28 #define INIFILELINES
29 
30 #include <string>
31 #include <list>
32 #include <memory>
33 #include "CoreLibraryDllGlobal.h"
35 
37 namespace core_lib
38 {
40 namespace ini_file
41 {
42 
44 using keys_list = std::list<std::pair<std::string, std::string>>;
45 
47 namespace if_private
48 {
49 
51 class CORE_LIBRARY_DLL_SHARED_API Line
52 {
53 public:
54  Line() = default;
55  virtual ~Line() = default;
56  Line(Line const&) = default;
57  Line(Line&&) = default;
58  Line& operator=(Line const&) = default;
59  Line& operator=(Line&&) = default;
60 
66  virtual void Print(std::ostream& os, bool addLineFeed = true) const = 0;
67 };
68 
70 class CORE_LIBRARY_DLL_SHARED_API BlankLine : public Line
71 {
72 public:
74  BlankLine() = default;
76  BlankLine(const BlankLine&) = default;
78  ~BlankLine() override = default;
80  BlankLine& operator=(const BlankLine&) = default;
81 #ifdef USE_EXPLICIT_MOVE_
82 
83  BlankLine(BlankLine&& line);
85  BlankLine& operator=(BlankLine&& line);
86 #else
87 
88  BlankLine(BlankLine&&) = default;
90  BlankLine& operator=(BlankLine&&) = default;
91 #endif
92 
97  void Print(std::ostream& os, bool addLineFeed = true) const override;
98 };
99 
101 class CORE_LIBRARY_DLL_SHARED_API CommentLine : public Line
102 {
103 public:
105  CommentLine() = default;
107  CommentLine(const CommentLine&) = default;
109  explicit CommentLine(const std::string& comment);
111  ~CommentLine() override = default;
113  CommentLine& operator=(const CommentLine&) = default;
114 #ifdef USE_EXPLICIT_MOVE_
115 
116  CommentLine(CommentLine&& line);
118  CommentLine& operator=(CommentLine&& line);
119 #else
120 
121  CommentLine(CommentLine&&) = default;
123  CommentLine& operator=(CommentLine&&) = default;
124 #endif
125 
129  const std::string& Comment() const;
135  void Print(std::ostream& os, bool addLineFeed = true) const override;
136 
137 private:
139  std::string m_comment{};
140 };
141 
143 class CORE_LIBRARY_DLL_SHARED_API SectionLine : public Line
144 {
145 public:
147  SectionLine() = default;
149  SectionLine(const SectionLine&) = default;
151  explicit SectionLine(const std::string& section);
153  ~SectionLine() override = default;
155  SectionLine& operator=(const SectionLine&) = default;
156 #ifdef USE_EXPLICIT_MOVE_
157 
158  SectionLine(SectionLine&& line);
160  SectionLine& operator=(SectionLine&& line);
161 #else
162 
163  SectionLine(SectionLine&&) = default;
165  SectionLine& operator=(SectionLine&&) = default;
166 #endif
167 
171  const std::string& Section() const;
177  void Print(std::ostream& os, bool addLineFeed = true) const override;
178 
179 private:
181  std::string m_section{};
182 };
183 
185 class CORE_LIBRARY_DLL_SHARED_API KeyLine : public Line
186 {
187 public:
189  KeyLine() = default;
191  KeyLine(const KeyLine&) = default;
193  KeyLine(const std::string& key, const std::string& value);
195  ~KeyLine() override = default;
197  KeyLine& operator=(const KeyLine&) = default;
198 #ifdef USE_EXPLICIT_MOVE_
199 
200  KeyLine(KeyLine&& line);
202  KeyLine& operator=(KeyLine&& line);
203 #else
204 
205  KeyLine(KeyLine&&) = default;
207  KeyLine& operator=(KeyLine&&) = default;
208 #endif
209 
213  const std::string& Key() const;
218  const std::string& Value() const;
223  void Value(const std::string& value);
228  void Value(std::string&& value);
234  void Print(std::ostream& os, bool addLineFeed = true) const override;
235 
236 private:
238  std::string m_key{};
240  std::string m_value{};
241 };
242 
244 using line_list = std::list<std::shared_ptr<Line>>;
246 using line_iter = line_list::iterator;
248 using line_citer = line_list::const_iterator;
249 
250 } // namespace if_private
251 } // namespace ini_file
252 } // namespace core_lib
253 
254 #endif // INIFILELINES
std::list< std::pair< std::string, std::string > > keys_list
Typedef defining the key-value pair list for section entries.
Definition: IniFileLines.h:44
Class to manage a section key line in an INI file.
Definition: IniFileLines.h:185
Class to manage a comment line in an INI file.
Definition: IniFileLines.h:101
std::list< std::shared_ptr< Line > > line_list
Line list typedef.
Definition: IniFileLines.h:244
Class to manage a blank line in an INI file.
Definition: IniFileLines.h:70
The core_lib namespace.
Definition: AsioDefines.h:59
line_list::const_iterator line_citer
Line list const iterator typedef.
Definition: IniFileLines.h:248
Abstract base class to manage a line in an INI file.
Definition: IniFileLines.h:51
File containing declaration of DLL import/export control defines.
File containing platform specific definitions.
line_list::iterator line_iter
Line list iterator typedef.
Definition: IniFileLines.h:246
Class to manage a section header line in an INI file.
Definition: IniFileLines.h:143