Class documentation of Concepts

Loading...
Searching...
No Matches
stringFunc.hh
Go to the documentation of this file.
1
6#ifndef StringFuns_hh
7#define StringFuns_hh
8
9#include <string>
10#include <vector>
11#include <iomanip>
13#include "basics/typedefs.hh"
14#include "toolbox/sequence.hh"
15#include "toolbox/set.hh"
16
17namespace concepts {
18
19 // *************************************************************** tolower **
20
21 char tolower(const char ch);
22
23 // ********************************************************* stringtolower **
24
25 std::string stringtolower(const std::string s);
26
27 // ******************************************************** removeAllWhite **
28
30 std::string removeAllWhite(const std::string str);
31
32 // *********************************************************** getFilename **
33
35 std::string getFilename(const std::string str);
36
37 // ***************************************************** getFilenamePrefix **
38
42 std::string getFilenamePrefix(const std::string str);
43
44 // ********************************************************** getDirectory **
45
47 std::string getDirectory(const std::string str);
48
49 // *********************************************************** splitString **
50
54 std::vector<std::string> splitString(const std::string text,
55 const std::string separators);
56
57
58 // ************************************************* splitStringNameParams **
59
62 std::vector<std::string> splitStringNameParams(const std::string text);
63
64 // **************************************************** splitStringByComma **
65
72 std::vector<std::string> splitStringByComma(const std::string text);
73
74 // ************************************************************ stringSubs **
75
80 template<class F>
81 std::string stringSubs(const std::string str,
82 const std::string var, F value) {
83 std::stringstream s;
84 s << std::setprecision(16) << value;
85 std::string sNew = str;
86
87 std::string::size_type i;
88 while((i = sNew.find(var)) != std::string::npos)
89 sNew.replace(i, var.size(), s.str());
90 return sNew;
91 }
92
93
94 // ************************************************* ParseObjectFromString **
95
101 template<class F>
102 class ParseObjectFromString : public virtual OutputOperator {
103 public:
105 ParseObjectFromString(const char* name = "",
106 const Sequence<F> data = Sequence<F>())
107 : name_(name), data_ (data) {}
109 ParseObjectFromString(const char* name, const F data)
110 : name_(name), data_(1) { data_[0] = data; }
112 ParseObjectFromString(const char* name, const F data1, const F data2)
113 : name_(name), data_(2) { data_[0] = data1; data_[1] = data2; }
116 const F data1, const F data2, const F data3)
117 : name_(name), data_(3) {
118 data_[0] = data1;
119 data_[1] = data2;
120 data_[2] = data3;
121 }
122
124 std::string& name() { return name_; }
126 Sequence<F>& data() { return data_; }
127
129 bool parse(const std::string s);
130 protected:
131 std::ostream& info(std::ostream& os) const;
132 private:
134 std::string name_;
136 Sequence<F> data_;
137 };
138
139 template<class F>
140 bool ParseObjectFromString<F>::parse(const std::string s) {
142 if (seq.size() == 0) return false;
143
144 // remove white spaces
145 for(Sequence<std::string>::iterator i = seq.begin(); i != seq.end(); ++i) {
146 std::string t = removeAllWhite(*i); *i = t;
147 }
148 std::stringstream st; st << seq[0];
149 st >> name_;
150 data_.resize(seq.size()-1);
151 for(uint i = 0; i < data_.size(); ++i) {
152 std::stringstream st; st << seq[i+1];
153 st >> data_[i];
154 }
155
156 return true;
157 }
158
159 template<class F>
160 std::ostream& ParseObjectFromString<F>::info(std::ostream& os) const {
161 os << concepts::typeOf(*this)<< name_ << '(';
162 for(typename Sequence<F>::const_iterator i = data_.begin();
163 i != data_.end();) {
164 os << *i++;
165 if (i != data_.end())
166 os << ", ";
167 }
168 return os << ')';
169 }
170
171 // ******************************************** realSeqFromStringWithPower **
172
182
183 // ************************************************************ uintSeqSets **
184
196
197} // namespace concepts
198
199#endif // StringFuns_hh
ParseObjectFromString(const char *name, const F data1, const F data2)
Constructor with default name and default first two data entries.
bool parse(const std::string s)
Parser from a string.
ParseObjectFromString(const char *name="", const Sequence< F > data=Sequence< F >())
Constructor with default name and default data.
ParseObjectFromString(const char *name, const F data1, const F data2, const F data3)
Constructor with default name and default first three data entries.
Sequence< F > & data()
Returns the data.
std::string & name()
Returns the name of the object.
std::ostream & info(std::ostream &os) const
Returns information in an output stream.
ParseObjectFromString(const char *name, const F data)
Constructor with default name and default first data entry.
std::string removeAllWhite(const std::string str)
Removes all white space in the string str.
std::string typeOf(const T &t)
Definition output.hh:43
std::string getFilenamePrefix(const std::string str)
std::vector< std::string > splitStringByComma(const std::string text)
std::vector< std::string > splitStringNameParams(const std::string text)
std::string getFilename(const std::string str)
Returns the filename (with ending) of a given full filename.
std::string stringSubs(const std::string str, const std::string var, F value)
Definition stringFunc.hh:81
Sequence< concepts::Set< uint > > uintSeqSets(const std::string s)
Set< F > makeSet(uint n, const F &first,...)
Definition set.hh:320
std::string getDirectory(const std::string str)
Returns the directory of a given full filename.
Sequence< Real > realSeqFromStringWithPower(const std::string s)
std::vector< std::string > splitString(const std::string text, const std::string separators)