(file) Return to StringRep.h CVS log (file) (dir) Up to [Pegasus] / pegasus / src / Pegasus / Common

  1 karl  1.5 //%2006////////////////////////////////////////////////////////////////////////
  2 mike  1.2 //
  3           // Copyright (c) 2000, 2001, 2002 BMC Software; Hewlett-Packard Development
  4           // Company, L.P.; IBM Corp.; The Open Group; Tivoli Systems.
  5           // Copyright (c) 2003 BMC Software; Hewlett-Packard Development Company, L.P.;
  6           // IBM Corp.; EMC Corporation, The Open Group.
  7           // Copyright (c) 2004 BMC Software; Hewlett-Packard Development Company, L.P.;
  8           // IBM Corp.; EMC Corporation; VERITAS Software Corporation; The Open Group.
  9           // Copyright (c) 2005 Hewlett-Packard Development Company, L.P.; IBM Corp.;
 10           // EMC Corporation; VERITAS Software Corporation; The Open Group.
 11 karl  1.5 // Copyright (c) 2006 Hewlett-Packard Development Company, L.P.; IBM Corp.;
 12           // EMC Corporation; Symantec Corporation; The Open Group.
 13 mike  1.2 //
 14           // Permission is hereby granted, free of charge, to any person obtaining a copy
 15           // of this software and associated documentation files (the "Software"), to
 16           // deal in the Software without restriction, including without limitation the
 17           // rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
 18           // sell copies of the Software, and to permit persons to whom the Software is
 19           // furnished to do so, subject to the following conditions:
 20 karl  1.5 // 
 21 mike  1.2 // THE ABOVE COPYRIGHT NOTICE AND THIS PERMISSION NOTICE SHALL BE INCLUDED IN
 22           // ALL COPIES OR SUBSTANTIAL PORTIONS OF THE SOFTWARE. THE SOFTWARE IS PROVIDED
 23           // "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT
 24           // LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
 25           // PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
 26           // HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
 27           // ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
 28           // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
 29           //
 30           //==============================================================================
 31           //
 32           //%/////////////////////////////////////////////////////////////////////////////
 33           
 34           #ifndef _Pegasus_StringRep_h
 35           #define _Pegasus_StringRep_h
 36           
 37 mike  1.4 #include <Pegasus/Common/Config.h>
 38           #include <Pegasus/Common/AtomicInt.h>
 39 mike  1.2 #include <new>
 40           
 41           PEGASUS_NAMESPACE_BEGIN
 42           
 43 mike  1.7 struct PEGASUS_COMMON_LINKAGE StringRep
 44 mike  1.2 {
 45               StringRep();
 46           
 47               ~StringRep();
 48           
 49               static StringRep* alloc(size_t cap);
 50           
 51               static void free(StringRep* rep);
 52           
 53               static StringRep* create(const Uint16* data, size_t size);
 54           
 55               static StringRep* create(const char* data, size_t size);
 56           
 57               static StringRep* copyOnWrite(StringRep* rep);
 58           
 59               static Uint32 length(const Uint16* str);
 60           
 61               static void ref(const StringRep* rep);
 62           
 63               static void unref(const StringRep* rep);
 64           
 65 mike  1.2     static StringRep _emptyRep;
 66           
 67               // Number of characters in this string, excluding the null terminator.
 68               size_t size;
 69           
 70               // Number of characters this representation has room for. This is
 71               // greater or equal to size.
 72               size_t cap;
 73           
 74               // Number of string refering to this StringRep (1, 2, etc).
 75               AtomicInt refs;
 76           
 77               // The first character in the string. Extra space is allocated off the
 78               // end of this structure for additional characters.
 79               Uint16 data[1];
 80           };
 81           
 82           inline void StringRep::free(StringRep* rep)
 83           {
 84               rep->refs.~AtomicInt();
 85               ::operator delete(rep);
 86 mike  1.2 }
 87           
 88           inline StringRep::StringRep() : size(0), cap(0), refs(2)
 89           {
 90               // Only called on _emptyRep. We set the reference count to two to
 91               // keep a String from modifying it (if the reference count were one,
 92               // a string would think it was the sole owner of the StringRep object).
 93               data[0] = 0;
 94           }
 95           
 96           inline StringRep::~StringRep()
 97           {
 98               // Only called on _emptyRep.
 99           }
100           
101           inline void StringRep::ref(const StringRep* rep)
102           {
103               if (rep != &StringRep::_emptyRep)
104                   ((StringRep*)rep)->refs++;
105           }
106           
107 mike  1.2 inline void StringRep::unref(const StringRep* rep)
108           {
109 kumpf 1.9     if (rep != &StringRep::_emptyRep &&
110                   ((StringRep*)rep)->refs.decAndTestIfZero())
111 mike  1.2         StringRep::free((StringRep*)rep);
112           }
113           
114           PEGASUS_COMMON_LINKAGE void StringThrowOutOfBounds();
115           
116           PEGASUS_COMMON_LINKAGE void StringAppendCharAux(StringRep*& _rep);
117           
118           PEGASUS_COMMON_LINKAGE Boolean StringEqualNoCase(
119               const String& s1, const String& s2);
120           
121           PEGASUS_COMMON_LINKAGE Uint32 StringFindAux(
122               const StringRep* _rep, const Char16* s, Uint32 n);
123           
124           inline void _checkBounds(size_t index, size_t size)
125           {
126               if (index > size)
127                   StringThrowOutOfBounds();
128           }
129           
130           PEGASUS_NAMESPACE_END
131           
132 mike  1.2 #endif /* _Pegasus_StringRep_h */

No CVS admin address has been configured
Powered by
ViewCVS 0.9.2