1 |
< |
/* |
1 |
> |
/* |
2 |
|
* Copyright (c) 2005 The University of Notre Dame. All Rights Reserved. |
3 |
|
* |
4 |
|
* The University of Notre Dame grants you ("Licensee") a |
55 |
|
|
56 |
|
namespace oopse { |
57 |
|
|
58 |
– |
|
58 |
|
/** |
59 |
|
* Converts a string to UPPER CASE |
60 |
|
* @param S |
109 |
|
* @param v data to be converted |
110 |
|
* @return a string |
111 |
|
*/ |
112 |
< |
template<typename T> |
113 |
< |
std::string toString(const T& v) { |
114 |
< |
std::ostringstream oss; |
115 |
< |
if (!oss << v) { |
116 |
< |
std::cerr << "toString Error" << std::endl; |
118 |
< |
} |
119 |
< |
return oss.str(); |
112 |
> |
template<typename T> |
113 |
> |
std::string toString(const T& v) { |
114 |
> |
std::ostringstream oss; |
115 |
> |
if (!oss << v) { |
116 |
> |
std::cerr << "toString Error" << std::endl; |
117 |
|
} |
118 |
+ |
return oss.str(); |
119 |
+ |
} |
120 |
+ |
|
121 |
+ |
template<typename T> |
122 |
+ |
T lexi_cast(const std::string& str) { |
123 |
+ |
T result; |
124 |
+ |
std::istringstream iss(str); |
125 |
+ |
if (!(iss >> result)) { |
126 |
+ |
std::cerr << "lexi_cast Error" << std::endl; |
127 |
+ |
} |
128 |
+ |
return result; |
129 |
+ |
} |
130 |
|
|
131 |
< |
template<typename T> |
132 |
< |
T lexi_cast(const std::string& str) { |
133 |
< |
T result; |
134 |
< |
std::istringstream iss; |
135 |
< |
if (iss >> result) { |
136 |
< |
std::cerr << "lexi_cast Error" << std::endl; |
137 |
< |
} |
138 |
< |
return result; |
131 |
> |
|
132 |
> |
template<typename T> |
133 |
> |
bool isType(const std::string& str) { |
134 |
> |
T result; |
135 |
> |
std::istringstream iss(str); |
136 |
> |
bool ret = true; |
137 |
> |
if (!(iss >> result)) { |
138 |
> |
ret = false; |
139 |
|
} |
140 |
+ |
return ret; |
141 |
+ |
} |
142 |
|
|
143 |
< |
/**@todo need implementation */ |
144 |
< |
std::string getPrefix(const std::string& str); |
143 |
> |
bool isInteger(const std::string& str); |
144 |
> |
|
145 |
> |
std::string OOPSE_itoa(int value, unsigned int base = 10); |
146 |
> |
|
147 |
> |
/**@todo need implementation */ |
148 |
> |
std::string getPrefix(const std::string& str); |
149 |
> |
|
150 |
> |
/**@todo need implementation */ |
151 |
> |
std::string getSuffix(const std::string& str); |
152 |
> |
|
153 |
|
|
154 |
< |
/**@todo need implementation */ |
155 |
< |
std::string getSuffix(const std::string& str); |
156 |
< |
|
157 |
< |
} |
154 |
> |
template<class ContainerType> |
155 |
> |
std::string containerToString(const ContainerType& cont) { |
156 |
> |
std::ostringstream oss; |
157 |
> |
oss << "("; |
158 |
> |
typename ContainerType::const_iterator i = cont.begin(); |
159 |
> |
if (i != cont.end()) { |
160 |
> |
oss << *i; |
161 |
> |
++i; |
162 |
> |
} |
163 |
> |
for (; i != cont.end();++i) { |
164 |
> |
oss << ", "; |
165 |
> |
oss << *i; |
166 |
> |
} |
167 |
> |
oss << ")"; |
168 |
> |
return oss.str(); |
169 |
> |
} |
170 |
|
|
171 |
+ |
|
172 |
+ |
} |
173 |
|
#endif |