![]() |
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) 1998-2007 by Systems in Motion. All rights reserved. 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 Systems in Motion about acquiring 00018 * a Coin Professional Edition License. 00019 * 00020 * See http://www.coin3d.org/ for more information. 00021 * 00022 * Systems in Motion, Postboks 1283, Pirsenteret, 7462 Trondheim, 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)) { cc_string_apply(&this->str, (cc_apply_f)func); } 00115 00116 int find(const SbString & s) const; 00117 SbBool findAll(const SbString & s, SbIntList & found) const; 00118 00119 friend int operator==(const SbString & sbstr, const char * s); 00120 friend int operator==(const char * s, const SbString & sbstr); 00121 friend int operator==(const SbString & str1, const SbString & str2); 00122 friend int operator!=(const SbString & sbstr, const char * s); 00123 friend int operator!=(const char * s, const SbString & sbstr); 00124 friend int operator!=(const SbString & str1, const SbString & str2); 00125 00126 private: 00127 struct cc_string str; 00128 }; 00129 00130 inline int operator==(const SbString & sbstr, const char * s) 00131 { return (cc_string_compare_text(sbstr.str.pointer, s) == 0); } 00132 inline int operator==(const char * s, const SbString & sbstr) 00133 { return (cc_string_compare_text(s, sbstr.str.pointer) == 0); } 00134 inline int operator==(const SbString & str1, const SbString & str2) 00135 { return (cc_string_compare_text(str1.str.pointer, str2.str.pointer) == 0); } 00136 00137 inline int operator!=(const SbString & sbstr, const char * s) 00138 { return (cc_string_compare_text(sbstr.str.pointer, s) != 0); } 00139 inline int operator!=(const char * s, const SbString & sbstr) 00140 { return (cc_string_compare_text(s, sbstr.str.pointer) != 0); } 00141 inline int operator!=(const SbString & str1, const SbString & str2) 00142 { return (cc_string_compare_text(str1.str.pointer, str2.str.pointer) != 0); } 00143 00144 #ifndef COIN_INTERNAL 00145 // For Open Inventor compatibility. 00146 #include <Inventor/SbName.h> 00147 #endif // !COIN_INTERNAL 00148 00149 #endif // !COIN_SBSTRING_H
Copyright © 1998-2007 by Systems in Motion AS. All rights reserved.
Generated on Mon Feb 23 16:33:09 2009 for Coin by Doxygen. 1.5.8