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

  1 a.dunfey 1.4.2.1 //%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 a.dunfey 1.4.2.1 // 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 a.dunfey 1.4.2.1 // 
 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                  struct StringRep
 44                  {
 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 mike     1.2     
 61                      static void ref(const StringRep* rep);
 62                  
 63                      static void unref(const StringRep* rep);
 64                  
 65                      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 mike     1.2     
 82                  inline void StringRep::free(StringRep* rep)
 83                  {
 84                      rep->refs.~AtomicInt();
 85                      ::operator delete(rep);
 86                  }
 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                      refs.~AtomicInt();
100                  }
101                  
102 mike     1.2     inline void StringRep::ref(const StringRep* rep)
103                  {
104                      if (rep != &StringRep::_emptyRep)
105                          ((StringRep*)rep)->refs++;
106                  }
107                  
108                  inline void StringRep::unref(const StringRep* rep)
109                  {
110                      if (rep != &StringRep::_emptyRep && 
111 mike     1.3     	((StringRep*)rep)->refs.decAndTestIfZero())
112 mike     1.2             StringRep::free((StringRep*)rep);
113                  }
114                  
115                  PEGASUS_COMMON_LINKAGE void StringThrowOutOfBounds();
116                  
117                  PEGASUS_COMMON_LINKAGE void StringAppendCharAux(StringRep*& _rep);
118                  
119                  PEGASUS_COMMON_LINKAGE Boolean StringEqualNoCase(
120                      const String& s1, const String& s2);
121                  
122                  PEGASUS_COMMON_LINKAGE Uint32 StringFindAux(
123                      const StringRep* _rep, const Char16* s, Uint32 n);
124                  
125                  inline void _checkBounds(size_t index, size_t size)
126                  {
127                  #ifndef PEGASUS_STRING_NO_THROW
128                      if (index > size)
129                          StringThrowOutOfBounds();
130                  #endif
131                  }
132                  
133 mike     1.2     PEGASUS_NAMESPACE_END
134                  
135                  #endif /* _Pegasus_StringRep_h */

No CVS admin address has been configured
Powered by
ViewCVS 0.9.2