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

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

No CVS admin address has been configured
Powered by
ViewCVS 0.9.2