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

  1 mike  1.1.2.1 //%2005////////////////////////////////////////////////////////////////////////
  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               //
 12               // Permission is hereby granted, free of charge, to any person obtaining a copy
 13               // of this software and associated documentation files (the "Software"), to
 14               // deal in the Software without restriction, including without limitation the
 15               // rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
 16               // sell copies of the Software, and to permit persons to whom the Software is
 17               // furnished to do so, subject to the following conditions:
 18               //
 19               // THE ABOVE COPYRIGHT NOTICE AND THIS PERMISSION NOTICE SHALL BE INCLUDED IN
 20               // ALL COPIES OR SUBSTANTIAL PORTIONS OF THE SOFTWARE. THE SOFTWARE IS PROVIDED
 21               // "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT
 22 mike  1.1.2.1 // LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
 23               // PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
 24               // HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
 25               // ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
 26               // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
 27               //
 28               //==============================================================================
 29               //
 30               //%/////////////////////////////////////////////////////////////////////////////
 31               
 32               #ifndef _Pegasus_StringRep_h
 33               #define _Pegasus_StringRep_h
 34               
 35               #include <Pegasus/Common/Atomic.h>
 36               
 37               PEGASUS_NAMESPACE_BEGIN
 38               
 39               struct StringRep
 40               {
 41                   StringRep();
 42               
 43 mike  1.1.2.1     ~StringRep();
 44               
 45                   static StringRep* alloc(size_t cap);
 46               
 47                   static void free(StringRep* rep);
 48               
 49                   static StringRep* create(const Uint16* data, size_t size);
 50               
 51                   static StringRep* create(const char* data, size_t size);
 52               
 53                   static StringRep* createASCII7(const char* data, size_t size);
 54               
 55                   static StringRep* copy_on_write(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                   static StringRep _empty_rep;
 64 mike  1.1.2.1 
 65                   size_t size;
 66                   size_t cap;
 67                   Atomic refs;
 68                   Uint16 data[1];
 69               };
 70               
 71               inline void StringRep::free(StringRep* rep)
 72               {
 73                   Atomic_destroy(&rep->refs);
 74                   ::operator delete(rep);
 75               }
 76               
 77               inline StringRep::StringRep() : size(0), cap(0)
 78               {
 79                   // Only called on _empty_rep.
 80                   Atomic_create(&refs, 99);
 81                   data[0] = 0;
 82               }
 83               
 84               inline StringRep::~StringRep()
 85 mike  1.1.2.1 {
 86                   // Only called on _empty_rep.
 87                   Atomic_destroy(&refs);
 88               }
 89               
 90               inline void StringRep::ref(const StringRep* rep)
 91               {
 92                   if (rep != &StringRep::_empty_rep)
 93               	Atomic_inc(&((StringRep*)rep)->refs);
 94               }
 95               
 96               inline void StringRep::unref(const StringRep* rep)
 97               {
 98                   if (rep != &StringRep::_empty_rep && 
 99               	Atomic_dec_and_test(&((StringRep*)rep)->refs))
100               	StringRep::free((StringRep*)rep);
101               }
102               
103               PEGASUS_COMMON_LINKAGE void String_throw_out_of_bounds();
104               
105               #ifdef PEGASUS_STRING_NO_THROW
106 mike  1.1.2.1 # define _check_bounds(ARG1, ARG2) /* empty */
107               #else
108               inline void _check_bounds(size_t index, size_t size)
109               {
110                   if (index > size)
111               	String_throw_out_of_bounds();
112               }
113               #endif
114               
115               PEGASUS_NAMESPACE_END
116               
117               #endif /* _Pegasus_StringRep_h */

No CVS admin address has been configured
Powered by
ViewCVS 0.9.2