Coin Logo http://www.sim.no/
http://www.coin3d.org/

SbString.h
1#ifndef COIN_SBSTRING_H
2#define COIN_SBSTRING_H
3
4/**************************************************************************\
5 *
6 * This file is part of the Coin 3D visualization library.
7 * Copyright (C) by Kongsberg Oil & Gas Technologies.
8 *
9 * This library is free software; you can redistribute it and/or
10 * modify it under the terms of the GNU General Public License
11 * ("GPL") version 2 as published by the Free Software Foundation.
12 * See the file LICENSE.GPL at the root directory of this source
13 * distribution for additional information about the GNU GPL.
14 *
15 * For using Coin with software that can not be combined with the GNU
16 * GPL, and for taking advantage of the additional benefits of our
17 * support services, please contact Kongsberg Oil & Gas Technologies
18 * about acquiring a Coin Professional Edition License.
19 *
20 * See http://www.coin3d.org/ for more information.
21 *
22 * Kongsberg Oil & Gas Technologies, Bygdoy Alle 5, 0257 Oslo, NORWAY.
23 * http://www.sim.no/ sales@sim.no coin-support@coin3d.org
24 *
25\**************************************************************************/
26
27#include <stdarg.h>
28
29#include <Inventor/system/inttypes.h>
30#include <Inventor/C/base/string.h>
31
32#ifdef COIN_INTERNAL
33 #define COIN_ALLOW_SBINTLIST
34 #include <Inventor/lists/SbIntList.h>
35 #undef COIN_ALLOW_SBINTLIST
36#else
37 #include <Inventor/lists/SbIntList.h>
38#endif // COIN_INTERNAL
39
40// *************************************************************************
41
42class COIN_DLL_API SbString {
43public:
44 SbString(void) { cc_string_construct(&this->str); }
45
46 SbString(const char * s)
47 { cc_string_construct(&this->str); cc_string_set_text(&this->str, s); }
48
49 SbString(const char * s, int start, int end)
50 { cc_string_construct(&this->str); cc_string_set_subtext(&this->str, s, start, end); }
51
52 SbString(const SbString & s)
53 { cc_string_construct(&this->str); cc_string_set_string(&this->str, &s.str); }
54
55 SbString(const int digits)
56 { cc_string_construct(&this->str); cc_string_set_integer(&this->str, digits); }
57
58 ~SbString() { cc_string_clean(&this->str); }
59
60 uint32_t hash(void) const { return cc_string_hash(&this->str); }
61 static uint32_t hash(const char * s) { return cc_string_hash_text(s); }
62
63 int getLength(void) const { return cc_string_length(&this->str); }
64
65 void makeEmpty(SbBool freeold = TRUE)
66 {
67 if ( freeold ) cc_string_clear(&this->str);
68 else cc_string_clear_no_free(&this->str);
69 }
70
71 const char * getString(void) const { return cc_string_get_text(&this->str); }
72
73 SbString getSubString(int startidx, int endidx = -1) const
74 {
75 SbString s;
76 cc_string_set_subtext(&s.str, cc_string_get_text(&this->str), startidx, endidx);
77 return s;
78 }
79 void deleteSubString(int startidx, int endidx = -1)
80 {
81 cc_string_remove_substring(&this->str, startidx, endidx);
82 }
83
84 void addIntString(const int value) { cc_string_append_integer(&this->str, value); }
85
86 char operator[](int index) const { return this->str.pointer[index]; }
87
88 SbString & operator=(const char * s)
89 { cc_string_set_text(&this->str, s); return *this; }
91 { cc_string_set_text(&this->str, s.str.pointer); return *this; }
92
93 SbString & operator+=(const char * s)
94 { cc_string_append_text(&this->str, s); return *this; }
96 { cc_string_append_string(&this->str, &s.str); return *this; }
97 SbString & operator+=(const char c)
98 { cc_string_append_char(&this->str, c); return *this; }
99
100 int operator!(void) const { return ! cc_string_is(&this->str); }
101
102 int compareSubString(const char * text, int offset = 0) const
103 { return cc_string_compare_subtext(&this->str, text, offset); }
104
105 SbString & sprintf(const char * formatstr, ...)
106 {
107 va_list args; va_start(args, formatstr);
108 cc_string_vsprintf(&this->str, formatstr, args);
109 va_end(args); return *this;
110 }
111 SbString & vsprintf(const char * formatstr, va_list args)
112 { cc_string_vsprintf(&this->str, formatstr, args); return *this; }
113
114 void apply(char (*func)(char input)) {
115 cc_string_apply(&this->str, reinterpret_cast<cc_apply_f>(func));
116 }
117
118 int find(const SbString & s) const;
119 SbBool findAll(const SbString & s, SbIntList & found) const;
120
121 SbString lower() const;
122 SbString upper() const;
123
124 friend int operator==(const SbString & sbstr, const char * s);
125 friend int operator==(const char * s, const SbString & sbstr);
126 friend int operator==(const SbString & str1, const SbString & str2);
127 friend int operator!=(const SbString & sbstr, const char * s);
128 friend int operator!=(const char * s, const SbString & sbstr);
129 friend int operator!=(const SbString & str1, const SbString & str2);
130 friend const SbString operator+(const SbString & str1, const SbString & str2);
131 friend const SbString operator+(const SbString & sbstr, const char * s);
132 friend const SbString operator+(const char * s, const SbString & sbstr);
133
134private:
135 struct cc_string str;
136};
137
138inline int operator==(const SbString & sbstr, const char * s)
139{ return (cc_string_compare_text(sbstr.str.pointer, s) == 0); }
140inline int operator==(const char * s, const SbString & sbstr)
141{ return (cc_string_compare_text(s, sbstr.str.pointer) == 0); }
142inline int operator==(const SbString & str1, const SbString & str2)
143{ return (cc_string_compare_text(str1.str.pointer, str2.str.pointer) == 0); }
144
145inline int operator!=(const SbString & sbstr, const char * s)
146{ return (cc_string_compare_text(sbstr.str.pointer, s) != 0); }
147inline int operator!=(const char * s, const SbString & sbstr)
148{ return (cc_string_compare_text(s, sbstr.str.pointer) != 0); }
149inline int operator!=(const SbString & str1, const SbString & str2)
150{ return (cc_string_compare_text(str1.str.pointer, str2.str.pointer) != 0); }
151
152inline const SbString operator+(const SbString & str1, const SbString & str2)
153{
154 SbString newstr(str1);
155 newstr += str2;
156 return newstr;
157}
158inline const SbString operator+(const SbString & sbstr, const char * s)
159{
160 SbString newstr(sbstr);
161 newstr += s;
162 return newstr;
163}
164inline const SbString operator+(const char * s, const SbString & sbstr)
165{
166 SbString newstr(s);
167 newstr += sbstr;
168 return newstr;
169}
170
171#ifndef COIN_INTERNAL
172// For Open Inventor compatibility.
173#include <Inventor/SbName.h>
174#endif // !COIN_INTERNAL
175
176#endif // !COIN_SBSTRING_H
The SbIntList class is a container for integer list arrays.
Definition SbIntList.h:31
The SbString class is a string class with convenience functions for string operations.
Definition SbString.h:42
int operator!(void) const
Definition SbString.h:100
int getLength(void) const
Definition SbString.h:63
SbString getSubString(int startidx, int endidx=-1) const
Definition SbString.h:73
char operator[](int index) const
Definition SbString.h:86
SbString(const char *s)
Definition SbString.h:46
~SbString()
Definition SbString.h:58
SbString(const int digits)
Definition SbString.h:55
SbString & operator+=(const char c)
Definition SbString.h:97
SbString & operator=(const SbString &s)
Definition SbString.h:90
SbString(const SbString &s)
Definition SbString.h:52
SbString(const char *s, int start, int end)
Definition SbString.h:49
uint32_t hash(void) const
Definition SbString.h:60
SbString & sprintf(const char *formatstr,...)
Definition SbString.h:105
const char * getString(void) const
Definition SbString.h:71
SbString & operator+=(const char *s)
Definition SbString.h:93
static uint32_t hash(const char *s)
Definition SbString.h:61
void deleteSubString(int startidx, int endidx=-1)
Definition SbString.h:79
SbString & operator+=(const SbString &s)
Definition SbString.h:95
void addIntString(const int value)
Definition SbString.h:84
int compareSubString(const char *text, int offset=0) const
Definition SbString.h:102
SbString(void)
Definition SbString.h:44
void makeEmpty(SbBool freeold=TRUE)
Definition SbString.h:65
SbString & vsprintf(const char *formatstr, va_list args)
Definition SbString.h:111
SbString & operator=(const char *s)
Definition SbString.h:88
The cc_string type is a C ADT for ASCII string management.
Definition string.h:41

Copyright © 1998-2010 by Kongsberg Oil & Gas Technologies. All rights reserved.

Generated on Wed Jul 17 2024 for Coin by Doxygen 1.12.0.