![]() |
http://www.sim.no/ http://www.coin3d.org/ |
00001 #ifndef COIN_SBSTRING_H 00002 #define COIN_SBSTRING_H 00003 00004 /**************************************************************************\ 00005 * 00006 * This file is part of the Coin 3D visualization library. 00007 * Copyright (C) by Kongsberg Oil & Gas Technologies. 00008 * 00009 * This library is free software; you can redistribute it and/or 00010 * modify it under the terms of the GNU General Public License 00011 * ("GPL") version 2 as published by the Free Software Foundation. 00012 * See the file LICENSE.GPL at the root directory of this source 00013 * distribution for additional information about the GNU GPL. 00014 * 00015 * For using Coin with software that can not be combined with the GNU 00016 * GPL, and for taking advantage of the additional benefits of our 00017 * support services, please contact Kongsberg Oil & Gas Technologies 00018 * about acquiring a Coin Professional Edition License. 00019 * 00020 * See http://www.coin3d.org/ for more information. 00021 * 00022 * Kongsberg Oil & Gas Technologies, Bygdoy Alle 5, 0257 Oslo, NORWAY. 00023 * http://www.sim.no/ sales@sim.no coin-support@coin3d.org 00024 * 00025 \**************************************************************************/ 00026 00027 #include <stdarg.h> 00028 00029 #include <Inventor/system/inttypes.h> 00030 #include <Inventor/C/base/string.h> 00031 00032 #ifdef COIN_INTERNAL 00033 #define COIN_ALLOW_SBINTLIST 00034 #include <Inventor/lists/SbIntList.h> 00035 #undef COIN_ALLOW_SBINTLIST 00036 #else 00037 #include <Inventor/lists/SbIntList.h> 00038 #endif // COIN_INTERNAL 00039 00040 // ************************************************************************* 00041 00042 class COIN_DLL_API SbString { 00043 public: 00044 SbString(void) { cc_string_construct(&this->str); } 00045 00046 SbString(const char * s) 00047 { cc_string_construct(&this->str); cc_string_set_text(&this->str, s); } 00048 00049 SbString(const char * s, int start, int end) 00050 { cc_string_construct(&this->str); cc_string_set_subtext(&this->str, s, start, end); } 00051 00052 SbString(const SbString & s) 00053 { cc_string_construct(&this->str); cc_string_set_string(&this->str, &s.str); } 00054 00055 SbString(const int digits) 00056 { cc_string_construct(&this->str); cc_string_set_integer(&this->str, digits); } 00057 00058 ~SbString() { cc_string_clean(&this->str); } 00059 00060 uint32_t hash(void) const { return cc_string_hash(&this->str); } 00061 static uint32_t hash(const char * s) { return cc_string_hash_text(s); } 00062 00063 int getLength(void) const { return cc_string_length(&this->str); } 00064 00065 void makeEmpty(SbBool freeold = TRUE) 00066 { 00067 if ( freeold ) cc_string_clear(&this->str); 00068 else cc_string_clear_no_free(&this->str); 00069 } 00070 00071 const char * getString(void) const { return cc_string_get_text(&this->str); } 00072 00073 SbString getSubString(int startidx, int endidx = -1) const 00074 { 00075 SbString s; 00076 cc_string_set_subtext(&s.str, cc_string_get_text(&this->str), startidx, endidx); 00077 return s; 00078 } 00079 void deleteSubString(int startidx, int endidx = -1) 00080 { 00081 cc_string_remove_substring(&this->str, startidx, endidx); 00082 } 00083 00084 void addIntString(const int value) { cc_string_append_integer(&this->str, value); } 00085 00086 char operator[](int index) const { return this->str.pointer[index]; } 00087 00088 SbString & operator=(const char * s) 00089 { cc_string_set_text(&this->str, s); return *this; } 00090 SbString & operator=(const SbString & s) 00091 { cc_string_set_text(&this->str, s.str.pointer); return *this; } 00092 00093 SbString & operator+=(const char * s) 00094 { cc_string_append_text(&this->str, s); return *this; } 00095 SbString & operator+=(const SbString & s) 00096 { cc_string_append_string(&this->str, &s.str); return *this; } 00097 SbString & operator+=(const char c) 00098 { cc_string_append_char(&this->str, c); return *this; } 00099 00100 int operator!(void) const { return ! cc_string_is(&this->str); } 00101 00102 int compareSubString(const char * text, int offset = 0) const 00103 { return cc_string_compare_subtext(&this->str, text, offset); } 00104 00105 SbString & sprintf(const char * formatstr, ...) 00106 { 00107 va_list args; va_start(args, formatstr); 00108 cc_string_vsprintf(&this->str, formatstr, args); 00109 va_end(args); return *this; 00110 } 00111 SbString & vsprintf(const char * formatstr, va_list args) 00112 { cc_string_vsprintf(&this->str, formatstr, args); return *this; } 00113 00114 void apply(char (*func)(char input)) { 00115 cc_string_apply(&this->str, reinterpret_cast<cc_apply_f>(func)); 00116 } 00117 00118 int find(const SbString & s) const; 00119 SbBool findAll(const SbString & s, SbIntList & found) const; 00120 00121 SbString lower() const; 00122 SbString upper() const; 00123 00124 friend int operator==(const SbString & sbstr, const char * s); 00125 friend int operator==(const char * s, const SbString & sbstr); 00126 friend int operator==(const SbString & str1, const SbString & str2); 00127 friend int operator!=(const SbString & sbstr, const char * s); 00128 friend int operator!=(const char * s, const SbString & sbstr); 00129 friend int operator!=(const SbString & str1, const SbString & str2); 00130 friend const SbString operator+(const SbString & str1, const SbString & str2); 00131 friend const SbString operator+(const SbString & sbstr, const char * s); 00132 friend const SbString operator+(const char * s, const SbString & sbstr); 00133 00134 private: 00135 struct cc_string str; 00136 }; 00137 00138 inline int operator==(const SbString & sbstr, const char * s) 00139 { return (cc_string_compare_text(sbstr.str.pointer, s) == 0); } 00140 inline int operator==(const char * s, const SbString & sbstr) 00141 { return (cc_string_compare_text(s, sbstr.str.pointer) == 0); } 00142 inline int operator==(const SbString & str1, const SbString & str2) 00143 { return (cc_string_compare_text(str1.str.pointer, str2.str.pointer) == 0); } 00144 00145 inline int operator!=(const SbString & sbstr, const char * s) 00146 { return (cc_string_compare_text(sbstr.str.pointer, s) != 0); } 00147 inline int operator!=(const char * s, const SbString & sbstr) 00148 { return (cc_string_compare_text(s, sbstr.str.pointer) != 0); } 00149 inline int operator!=(const SbString & str1, const SbString & str2) 00150 { return (cc_string_compare_text(str1.str.pointer, str2.str.pointer) != 0); } 00151 00152 inline const SbString operator+(const SbString & str1, const SbString & str2) 00153 { 00154 SbString newstr(str1); 00155 newstr += str2; 00156 return newstr; 00157 } 00158 inline const SbString operator+(const SbString & sbstr, const char * s) 00159 { 00160 SbString newstr(sbstr); 00161 newstr += s; 00162 return newstr; 00163 } 00164 inline const SbString operator+(const char * s, const SbString & sbstr) 00165 { 00166 SbString newstr(s); 00167 newstr += sbstr; 00168 return newstr; 00169 } 00170 00171 #ifndef COIN_INTERNAL 00172 // For Open Inventor compatibility. 00173 #include <Inventor/SbName.h> 00174 #endif // !COIN_INTERNAL 00175 00176 #endif // !COIN_SBSTRING_H
Copyright © 1998-2010 by Kongsberg Oil & Gas Technologies. All rights reserved.
Generated for Coin by Doxygen 1.7.3.