ITK  4.9.0
Insight Segmentation and Registration Toolkit
itkFancyString.h
Go to the documentation of this file.
1 /*=========================================================================
2  *
3  * Copyright Insight Software Consortium
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.txt
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 
19 #ifndef itkFancyString_h
20 #define itkFancyString_h
21 
22 #include <string>
23 #include <vector>
24 #include <map>
25 #include "itkArray.h"
26 #include "ITKIOXMLExport.h"
27 
28 namespace itk
29 {
30 
45 class ITKIOXML_EXPORT FancyString
46 {
47 public:
48  FancyString();
49  FancyString( const std::string& str );
50  FancyString( const char* s );
52 
53  FancyString& operator=( const std::string& str );
54  FancyString& operator=( const char* s );
55 
57  operator const char * () const;
58 
60  // helper functions for converting a string to/from a std::vector
62 
72  template < typename T >
73  FancyString& ToData( std::vector<T>& outputData, int count = -1 );
75 
80  template < typename T >
81  FancyString& FromData( const std::vector<T>& inputData );
82 
84  // helper functions for converting a string to/from a itk::Array
86 
96  template < typename T >
97  FancyString& ToData( Array<T>& outputData, int count = -1 );
99 
104  template < typename T >
105  FancyString& FromData( const Array<T>& inputData );
106 
108  // helper functions for converting a string to/from a basic data type
110 
114  operator const std::string& () const;
115 
119  const std::string& ToString() const;
120 
125  template < typename T >
126  FancyString& ToData( T& outputData );
127 
132  template < typename T >
133  FancyString& FromData( const T& inputData );
134 
136  // helper functions for string manipulations
138 
140  void ClearContent();
141 
143  void Append(const FancyString& str);
144 
146  FancyString& Trim( const std::string& dislike = " \t\n\r" );
147 
149  FancyString& TrimLeft( const std::string& dislike = " \t\n\r" );
150 
152  FancyString& TrimRight( const std::string& dislike = " \t\n\r" );
153 
155  FancyString& ToUpperCase();
156 
158  FancyString& ToLowerCase();
159 
161  void Split( std::string& lpart, std::string& rpart, const std::string& delims = "=:" ) const;
162 
164  void Split( std::vector<std::string>& result, const std::string& delims = ";|" ) const;
165 
170  void Split( std::map<std::string,std::string>& result, const std::string& delims = ";|" );
171 
173  bool MatchWith( const std::string& s2, bool ignoreCase = true );
174 
176  bool StartWith( const std::string& s2, bool ignoreCase = true );
177 
179  bool EndWith( const std::string& s2, bool ignoreCase = true );
180 
182  bool ContainSub( const std::string& s2, bool ignoreCase = true );
183 
184 private:
185 
186  std::string m_Value;
187 
188 }; // class FancyString
189 
190 } // namespace itk
191 
193 // helper function to compare FancyString with std::string and char*
195 
196 bool ITKIOXML_EXPORT operator!=( itk::FancyString& s, const std::string& );
197 bool ITKIOXML_EXPORT operator!=( itk::FancyString& s, const char* );
198 bool ITKIOXML_EXPORT operator!=( itk::FancyString& s, const itk::FancyString&);
199 
200 bool ITKIOXML_EXPORT operator==( itk::FancyString& s, const std::string& );
201 bool ITKIOXML_EXPORT operator==( itk::FancyString& s, const char* );
202 bool ITKIOXML_EXPORT operator==( itk::FancyString& s, const itk::FancyString&);
203 
204 namespace itk
205 {
207 // manipulators for FancyString (currently only one is defined)
209 
213 FancyString& operator<<( FancyString& s, void (*mf)(FancyString&) );
214 
218 void ClearContent( FancyString& input );
219 
221 // helper functions for converting a string to/from a std::vector
223 
229 template < typename T >
230 FancyString& operator>>( FancyString& s, std::vector<T>& data );
231 
236 template < typename T >
237 FancyString& operator<<( FancyString& s, const std::vector<T>& data );
238 
240 // helper functions for converting a string to/from a itk::Array
242 
248 template < typename T >
249 FancyString& operator>>( FancyString& s, Array<T>& data );
250 
255 template < typename T >
256 FancyString& operator<<( FancyString& s, const Array<T>& data );
257 
259 // helper functions for converting a string to/from a basic data type
261 
266 template < typename T >
267 FancyString& operator>>( FancyString& s, T& data );
268 
273 template < typename T >
274 FancyString& operator<<( FancyString& s, const T& data );
275 
276 } // namespace itk
277 
278 #ifndef ITK_MANUAL_INSTANTIATION
279 #include "itkFancyString.hxx"
280 #endif
281 
282 #endif // itkFancyString_h
bool operator!=(const ImageRegionCopier< D1, D2 > &c1, const ImageRegionCopier< D1, D2 > &c2)
Array class with size defined at construction time.
Definition: itkArray.h:50
std::istream & operator>>(std::istream &is, Point< T, NPointDimension > &v)
std::ostream & operator<<(std::ostream &os, const Array< TValue > &arr)
Definition: itkArray.h:191
std::string m_Value
void ClearContent(FancyString &input)
A special string type that is used to aid I/O operations in DOM-based object readers/writers.
bool ITKIOXML_EXPORT operator==(itk::FancyString &s, const std::string &)