ALBA
albaString.h
Go to the documentation of this file.
1/*=========================================================================
2
3 Program: ALBA (Agile Library for Biomedical Applications)
4 Module: albaString
5 Authors: originally based on vtkString (www.vtk.org), rewritten Marco Petrone
6
7 Copyright (c) BIC
8 All rights reserved. See Copyright.txt or
9
10
11 This software is distributed WITHOUT ANY WARRANTY; without even
12 the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
13 PURPOSE. See the above copyright notice for more information.
14
15=========================================================================*/
16
17#ifndef __albaString_h
18#define __albaString_h
19
20#include "albaDefines.h"
21#include "albaBase.h"
22#include <string.h>
23#include "wx/string.h"
24
25//----------------------------------------------------------
26// forward references:
27//----------------------------------------------------------
28class albaMatrix;
29
42class ALBA_EXPORT albaString : public albaBase
43{
44public:
45
49 static albaID Length(const char* str);
50
52 const albaID Length() const;
53
55 static void Copy(char* dest, const char* src);
56
58 void Copy(const char* src);
59
61 void NCopy(const char* src,int n);
62
65 void Erase(int start,int end=-1);
66
72 static char* Duplicate(const char* str);
73
83 static void Duplicate(char * &store,const char *src,bool release=true);
84
88 char* Duplicate() const;
89
94 static int Compare(const char* str1, const char* str2);
95
100 int Compare(const char* str) const;
101
106 static bool Equals(const char* str1, const char* str2) { return Compare(str1, str2) == 0;}
107
113 bool Equals(const char* str) const;
114
116 static bool StartsWith(const char* str1, const char* str2);
118 bool StartsWith(const char* str) const;
119
121 static bool EndsWith(const char* str1, const char* str2);
123 bool EndsWith(const char* str) const;
124
129 static char* Append(const char* str1, const char* str2);
131 albaString &Append(const char* str);
132
134 int FindChr(const int c) const;
135
137 void Replace(char from, char to);
138
140 int FindLastChr(const int c) const;
141
143 int FindFirst(const char *str) const;
144
146 int FindLast(const char *str) const;
147
149 static const char *BaseName(const char *filename);
150 const char *BaseName() const;
151
154
158 void SetPathName(const char *str);
160
165 static char *ParsePathName(char *str);
167
170
172 const char * GetCStr() const;
173
178
180 int GetSize() const {return m_Size;};
181
192
194 static bool IsEmpty(const char *str) { return (str?str[0]=='\0':true);};
196 bool IsEmpty() const { return IsEmpty(GetCStr());};
197
201 albaString &Set(const char *a, bool release=false);
202
204 void SetCStr(char *a, bool release=false);
205
208 void Printf(const char *format, ...);
209
210 static wxString Format(const char *format, ...);
211
213 void NPrintf(unsigned long size, const char *format, ...);
214
216 operator const char*() const {return GetCStr();}
217
221 char & operator [] (const int i);
222
224 const char operator [] (const int i) const;
225
226 const bool operator==(const char *src) const;
227 const bool operator!=(const char *src) const;
228 const bool operator<(const char *a) const;
229 const bool operator>(const char *a) const;
230 const bool operator<=(const char *a) const;
231 const bool operator>=(const char *a) const;
232
233 //friend ALBA_EXPORT std::ostream& operator<<(std::ostream& os, const albaString& s);
234 //friend ALBA_EXPORT std::istream& operator>>(std::istream& is, albaString& s);
235
236 albaString &operator<<(const char *a) {return Append(a);};
237
238 void operator<<(std::ostream &os);
239 void operator>>(std::istream &os);
240
255 //void operator<<( std::string s);
256
257 albaString& operator+=(const char *s);
258
260 albaString(const char *src);
261 albaString(const double &num);
262#ifdef ALBA_USE_WX
263 albaString(const wxString &str);
264#endif
265
267 albaString &operator=(const char *src);
268 albaString &operator=(const double &num);
269#ifdef ALBA_USE_WX
270 albaString &operator=(const wxString &str);
271#endif
274protected:
275
277 int SetSize(albaID size);
278
279 void Initialize() {m_CStr=NULL;m_ConstCStr="";m_Size=0;};
280
281 char *m_CStr;
282 const char *m_ConstCStr;
284};
285
291{
292public:
294 albaCString(const char *str) {Set(str);}
295};
296
297#endif
298
long albaID
type for IDs inside ALBA
Definition: albaDefines.h:58
albaBase - the pourpose of this class is just to groups utilities classes
Definition: albaBase.h:27
Class Name : albaCString.
Definition: albaString.h:291
albaCString(const char *str)
constructor.
Definition: albaString.h:294
albaMatrix - Time stamped 4x4 Matrix.
Definition: albaMatrix.h:44
albaString - performs common string operations on c-strings.
Definition: albaString.h:43
const char * m_ConstCStr
Definition: albaString.h:282
const bool operator<(const char *a) const
void ExtractPathName()
Extract the pathname from a filename string.
albaID m_Size
Definition: albaString.h:283
static bool IsEmpty(const char *str)
return true if empty
Definition: albaString.h:194
albaString(const char *src)
albaString & Append(const char *str)
Append a new string to this string.
const bool operator==(const char *src) const
char * GetNonConstCStr()
Return the pointer to the internal c-string, but first force string the internal copy.
const bool operator>(const char *a) const
static char * Duplicate(const char *str)
This method makes a duplicate of a c-string similar to C function strdup but it uses new to create ne...
int FindChr(const int c) const
Scan the string for the first occurrence of the character.
static albaID Length(const char *str)
This static method returns the size of c-string.
static void Duplicate(char *&store, const char *src, bool release=true)
This method makes a duplicate of the string similar to C function strdup but it uses new to create ne...
albaString(const albaString &src)
albaString & operator<<(albaString *s)
static char * ParsePathName(char *str)
void operator>>(std::istream &os)
bool StartsWith(const char *str) const
Check if this string starts with the given one.
void SetCStr(char *a, bool release=false)
this can be used only with non constant c-string
albaString & operator+=(const char *s)
albaString & operator<<(albaMatrix d)
Put inside string a albaMatrix in row order example: 1 0 0 0 0 1 0 0 0 0 1 0 0 0 0 1 -> "1 0 0 0 0 1 ...
static void Copy(char *dest, const char *src)
static method to copy c-string to the another c-string.
void operator<<(std::ostream &os)
albaString & Set(const char *a, bool release=false)
Set the internal pointer to a give pointer.
albaString & operator=(const char *src)
albaString(const double &num)
void NCopy(const char *src, int n)
Copy N characters of another string to this string.
static bool StartsWith(const char *str1, const char *str2)
Static method to check if the first string starts with the second one.
const char * BaseName() const
char * m_CStr
Definition: albaString.h:281
char * Duplicate() const
Duplicate the string stored inside this object.
static bool EndsWith(const char *str1, const char *str2)
Static method to check if the first string ends with the second one.
char * ParsePathName()
parse the given string to substitute each (back)slash character with the right pathname separator.
int FindLast(const char *str) const
Find last occurrence of a substring.
albaString & operator<<(double d)
albaString & operator=(const albaString &mat)
bool IsEmpty() const
return true if empty
Definition: albaString.h:196
void Printf(const char *format,...)
Format given arguments according to format string.
void ForceDuplicate()
Force the string to create an internal duplication in place of reference to const char.
void SetPathName(albaString *str)
const char * GetCStr() const
Return the pointer to the internal c-string.
const bool operator!=(const char *src) const
void Erase(int start, int end=-1)
Erase characters from start position to end position.
int GetSize() const
return the real memory size allocated for the internal c-string
Definition: albaString.h:180
void Replace(char from, char to)
Replace each caracter from with to.
const bool operator>=(const char *a) const
void Copy(const char *src)
Copy a c-string to this string.
int SetMaxLength(albaID len)
Pre-Allocate space for the internal c-string.
bool EndsWith(const char *str) const
Check if this string ends with the given one.
albaString & operator=(const double &num)
int SetSize(albaID size)
Allocate space for the internal c-string.
const albaID Length() const
This method returns the size of this string.
char * ParsePathName(albaString *str)
static wxString Format(const char *format,...)
albaString & operator<<(int d)
static const char * BaseName(const char *filename)
Extract the base name of a filename string.
albaString & operator<<(float d)
void NPrintf(unsigned long size, const char *format,...)
like Printf but faster (you can specify output string size)
const bool operator<=(const char *a) const
int FindFirst(const char *str) const
Find first occurrence of a substring.
static bool Equals(const char *str1, const char *str2)
This static method compare two strings.
Definition: albaString.h:106
albaString & operator<<(const char *a)
Definition: albaString.h:236
bool Equals(const char *str) const
This method compare the given c-string with the one stored inside this object.
albaString & operator<<(long d)
static int Compare(const char *str1, const char *str2)
This static method compare two strings.
static char * Append(const char *str1, const char *str2)
Append two strings and produce a new one.
void Initialize()
Definition: albaString.h:279
int FindLastChr(const int c) const
Scan the string for the first occurrence of the character.
void SetPathName(const char *str)
parse the given string to substitute each (back)slash character with the right pathname separator.
int Compare(const char *str) const
This method compare the given c-string with the one stored inside this object.