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) 1998-2007 by Systems in Motion. All rights reserved.
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 Systems in Motion about acquiring
18 * a Coin Professional Edition License.
19 *
20 * See http://www.coin3d.org/ for more information.
21 *
22 * Systems in Motion, Postboks 1283, Pirsenteret, 7462 Trondheim, 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)) { cc_string_apply(&this->str, (cc_apply_f)func); }
115
116 int find(const SbString & s) const;
117 SbBool findAll(const SbString & s, SbIntList & found) const;
118
119 friend int operator==(const SbString & sbstr, const char * s);
120 friend int operator==(const char * s, const SbString & sbstr);
121 friend int operator==(const SbString & str1, const SbString & str2);
122 friend int operator!=(const SbString & sbstr, const char * s);
123 friend int operator!=(const char * s, const SbString & sbstr);
124 friend int operator!=(const SbString & str1, const SbString & str2);
125
126private:
127 struct cc_string str;
128};
129
130inline int operator==(const SbString & sbstr, const char * s)
131{ return (cc_string_compare_text(sbstr.str.pointer, s) == 0); }
132inline int operator==(const char * s, const SbString & sbstr)
133{ return (cc_string_compare_text(s, sbstr.str.pointer) == 0); }
134inline int operator==(const SbString & str1, const SbString & str2)
135{ return (cc_string_compare_text(str1.str.pointer, str2.str.pointer) == 0); }
136
137inline int operator!=(const SbString & sbstr, const char * s)
138{ return (cc_string_compare_text(sbstr.str.pointer, s) != 0); }
139inline int operator!=(const char * s, const SbString & sbstr)
140{ return (cc_string_compare_text(s, sbstr.str.pointer) != 0); }
141inline int operator!=(const SbString & str1, const SbString & str2)
142{ return (cc_string_compare_text(str1.str.pointer, str2.str.pointer) != 0); }
143
144#ifndef COIN_INTERNAL
145// For Open Inventor compatibility.
146#include <Inventor/SbName.h>
147#endif // !COIN_INTERNAL
148
149#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
void makeEmpty(SbBool freeold=1)
Definition: SbString.h:65
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
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
static uint32_t hash(const char *s)
Definition: SbString.h:61
SbString & vsprintf(const char *formatstr, va_list args)
Definition: SbString.h:111
SbString & operator=(const char *s)
Definition: SbString.h:88

Copyright © 1998-2007 by Systems in Motion AS. All rights reserved.

Generated on Wed Jan 18 2023 for Coin by Doxygen. 1.9.6