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

Diff for /pegasus/src/Pegasus/Common/Buffer.cpp between version 1.8 and 1.12

version 1.8, 2006/08/21 17:49:10 version 1.12, 2007/02/13 19:21:44
Line 29 
Line 29 
 // //
 //============================================================================== //==============================================================================
 // //
 // Author: Michael E. Brasher (mike-brasher@austin.rr.com -- Inova Europe)  
 //  
 //%///////////////////////////////////////////////////////////////////////////// //%/////////////////////////////////////////////////////////////////////////////
  
 #include <cstring> #include <cstring>
Line 52 
Line 50 
     {0} /* data[0] */     {0} /* data[0] */
 }; };
  
 static const size_t MIN_CAPACITY = 2048;  static const Uint32 MIN_CAPACITY = 2048;
  
 static Uint32 _next_pow_2(Uint32 x) static Uint32 _next_pow_2(Uint32 x)
 { {
Line 73 
Line 71 
     return x;     return x;
 } }
  
 static inline BufferRep* _allocate(size_t cap)  static inline BufferRep* _allocate(Uint32 cap)
 { {
     if (cap < MIN_CAPACITY)     if (cap < MIN_CAPACITY)
         cap = MIN_CAPACITY;         cap = MIN_CAPACITY;
Line 89 
Line 87 
     return rep;     return rep;
 } }
  
 static inline BufferRep* _reallocate(BufferRep* rep, size_t cap)  static inline BufferRep* _reallocate(BufferRep* rep, Uint32 cap)
 { {
     // Allocate an extra byte for null-termination performed by getData().     // Allocate an extra byte for null-termination performed by getData().
     rep = (BufferRep*)realloc(rep, sizeof(BufferRep) + cap + 1);     rep = (BufferRep*)realloc(rep, sizeof(BufferRep) + cap + 1);
Line 109 
Line 107 
     _rep->size = x._rep->size;     _rep->size = x._rep->size;
 } }
  
 Buffer::Buffer(const char* data, size_t size)  Buffer::Buffer(const char* data, Uint32 size)
 { {
     _rep = _allocate(size);     _rep = _allocate(size);
     _rep->size = size;     _rep->size = size;
Line 134 
Line 132 
     return *this;     return *this;
 } }
  
 void Buffer::_reserve_aux(size_t cap)  void Buffer::_reserve_aux(Uint32 cap)
 { {
     if (_rep->cap == 0)     if (_rep->cap == 0)
     {     {
Line 160 
Line 158 
     }     }
 } }
  
 void Buffer::insert(size_t pos, const char* data, size_t size)  void Buffer::insert(Uint32 pos, const char* data, Uint32 size)
 { {
     if (pos > _rep->size)     if (pos > _rep->size)
         return;         return;
  
     size_t cap = _rep->size + size;      Uint32 cap = _rep->size + size;
     size_t rem = _rep->size - pos;      Uint32 rem = _rep->size - pos;
  
     if (cap > _rep->cap)     if (cap > _rep->cap)
     {     {
Line 190 
Line 188 
     }     }
 } }
  
 void Buffer::remove(size_t pos, size_t size)  void Buffer::remove(Uint32 pos, Uint32 size)
 { {
     if (pos + size > _rep->size)     if (pos + size > _rep->size)
         return;         return;
  
     size_t rem = _rep->size - (pos + size);      Uint32 rem = _rep->size - (pos + size);
  
     if (rem)     if (rem)
         memmove(_rep->data + pos, _rep->data + pos + size, rem);         memmove(_rep->data + pos, _rep->data + pos + size, rem);
Line 203 
Line 201 
     _rep->size -= size;     _rep->size -= size;
 } }
  
 size_t Buffer::appendf(const char* format, ...)  
 {  
     size_t size = 128;  
     va_list ap;  
   
     for (;;)  
     {  
         reserveCapacity(_rep->size + size);  
         char* str = _rep->data + _rep->size;  
   
         va_start(ap, format);  
   
 #if defined(PEGASUS_OS_TYPE_WINDOWS)  
         int n = _vsnprintf(str, size, format, ap);  
 #else  
         int n = vsnprintf(str, size, format, ap);  
 #endif  
   
         va_end(ap);  
   
         if (n > -1 && n < int(size))  
         {  
             _rep->size += n;  
             return size_t(n);  
         }  
   
         if (n > -1)  
             size = n + 1;  
         else  
             size *= 2;  
     }  
   
     // Unreachable:  
     return 0;  
 }  
   
 PEGASUS_NAMESPACE_END PEGASUS_NAMESPACE_END


Legend:
Removed from v.1.8  
changed lines
  Added in v.1.12

No CVS admin address has been configured
Powered by
ViewCVS 0.9.2