Reaktoro  v2.11.0
A unified framework for modeling chemically reactive systems
StringList.hpp
1 // Reaktoro is a unified framework for modeling chemically reactive systems.
2 //
3 // Copyright © 2014-2024 Allan Leal
4 //
5 // This library is free software; you can redistribute it and/or
6 // modify it under the terms of the GNU Lesser General Public
7 // License as published by the Free Software Foundation; either
8 // version 2.1 of the License, or (at your option) any later version.
9 //
10 // This library is distributed in the hope that it will be useful,
11 // but WITHOUT ANY WARRANTY; without even the implied warranty of
12 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 // Lesser General Public License for more details.
14 //
15 // You should have received a copy of the GNU Lesser General Public License
16 // along with this library. If not, see <http://www.gnu.org/licenses/>.
17 
18 #pragma once
19 
20 // C++ includes
21 #include <string>
22 #include <vector>
23 
24 namespace Reaktoro {
25 
28 {
29 public:
32 
34  StringList(std::initializer_list<std::string> strings);
35 
37  StringList(std::vector<std::string> strings);
38 
44  StringList(const char* str);
45 
52  StringList(const char* str, char token);
53 
59  StringList(std::string str);
60 
67  StringList(std::string str, char token);
68 
70  auto empty() const -> bool;
71 
73  auto size() const -> std::size_t;
74 
76  auto data() const -> const std::vector<std::string>&;
77 
79  auto operator[](std::size_t index) -> std::string&;
80 
82  auto operator[](std::size_t index) const -> const std::string&;
83 
85  operator std::vector<std::string>() const;
86 
87 private:
89  std::vector<std::string> m_strings;
90 
91 public:
93  inline auto begin() const { return data().begin(); }
94 
96  inline auto begin() { return data().begin(); }
97 
99  inline auto end() const { return data().end(); }
100 
102  inline auto end() { return data().end(); }
103 
105  using value_type = std::string;
106 };
107 
108 } // namespace Reaktoro
A class for representing a list of strings with special constructors.
Definition: StringList.hpp:28
StringList(const char *str)
Construct a StringList instance by breaking the words within separated by space.
StringList(const char *str, char token)
Construct a StringList instance by breaking the words within separated by a token.
StringList(std::string str)
Construct a StringList instance by breaking the words within separated by space.
auto empty() const -> bool
Return true if the string list is empty.
auto end()
Return end iterator of this StringList instance (for STL compatibility reasons).
Definition: StringList.hpp:102
auto size() const -> std::size_t
Return the number of strings.
StringList()
Construct a default StringList instance.
StringList(std::initializer_list< std::string > strings)
Construct a StringList instance with a initializer list of strings.
auto begin() const
Return begin const iterator of this StringList instance (for STL compatibility reasons).
Definition: StringList.hpp:93
auto begin()
Return begin iterator of this StringList instance (for STL compatibility reasons).
Definition: StringList.hpp:96
auto end() const
Return end const iterator of this StringList instance (for STL compatibility reasons).
Definition: StringList.hpp:99
std::string value_type
The type of the value stored in a StringList instance (for STL compatibility reasons).
Definition: StringList.hpp:105
auto data() const -> const std::vector< std::string > &
Return the vector of strings.
StringList(std::vector< std::string > strings)
Construct a StringList instance with a vector of strings.
StringList(std::string str, char token)
Construct a StringList instance by breaking the words within separated by a token.
The namespace containing all components of the Reaktoro library.
Definition: Algorithms.hpp:29
auto index(const Container &c, const T &x) -> std::size_t
Return the index of item x in container c or the number of items if not found.
Definition: Algorithms.hpp:37
auto str(Args... items) -> std::string
Concatenate the arguments into a string without any separator string.
Definition: StringUtils.hpp:73