diff --git a/include/loki/flex/allocatorstringstorage.h b/include/loki/flex/allocatorstringstorage.h index 4fbfbda..5167e5b 100644 --- a/include/loki/flex/allocatorstringstorage.h +++ b/include/loki/flex/allocatorstringstorage.h @@ -26,7 +26,7 @@ class StoragePolicy typedef @ const_iterator; typedef A allocator_type; typedef @ size_type; - + StoragePolicy(const StoragePolicy& s); StoragePolicy(const A&); StoragePolicy(const E* s, size_type len, const A&); @@ -37,7 +37,7 @@ class StoragePolicy const_iterator begin() const; iterator end(); const_iterator end() const; - + size_type size() const; size_type max_size() const; size_type capacity() const; @@ -50,10 +50,10 @@ class StoragePolicy void resize(size_type newSize, E fill); void swap(StoragePolicy& rhs); - + const E* c_str() const; const E* data() const; - + A get_allocator() const; }; //////////////////////////////////////////////////////////////////////////////// @@ -82,7 +82,7 @@ class AllocatorStringStorage : public A void* Alloc(size_type sz, const void* p = 0) { - return A::allocate(1 + (sz - 1) / sizeof(E), + return A::allocate(1 + (sz - 1) / sizeof(E), static_cast(p)); } @@ -118,43 +118,43 @@ class AllocatorStringStorage : public A pData_->pEndOfMem_ = pData_->buffer_ + cap; } } - + public: typedef E value_type; typedef A allocator_type; typedef typename A::pointer iterator; typedef typename A::const_pointer const_iterator; - AllocatorStringStorage() + AllocatorStringStorage() : A(), pData_(0) { } - AllocatorStringStorage(const AllocatorStringStorage& rhs) + AllocatorStringStorage(const AllocatorStringStorage& rhs) : A(rhs.get_allocator()) { const size_type sz = rhs.size(); Init(sz, sz); if (sz) flex_string_details::pod_copy(rhs.begin(), rhs.end(), begin()); } - - AllocatorStringStorage(const AllocatorStringStorage& s, - flex_string_details::Shallow) + + AllocatorStringStorage(const AllocatorStringStorage& s, + flex_string_details::Shallow) : A(s.get_allocator()) { pData_ = s.pData_; } - + AllocatorStringStorage(const A& a) : A(a) - { + { pData_ = const_cast( &SimpleStringStorage::emptyString_); } - + AllocatorStringStorage(const E* s, size_type len, const A& a) : A(a) { - Init(len, len); + Init(len, len); flex_string_details::pod_copy(s, s + len, begin()); } @@ -164,7 +164,7 @@ public: Init(len, len); flex_string_details::pod_fill(&*begin(), &*end(), c); } - + AllocatorStringStorage& operator=(const AllocatorStringStorage& rhs) { const size_type sz = rhs.size(); @@ -173,28 +173,28 @@ public: pData_->pEnd_ = &*begin() + rhs.size(); return *this; } - + ~AllocatorStringStorage() { if (capacity()) { - Free(pData_, + Free(pData_, sizeof(Data) + capacity() * sizeof(E)); } } - + iterator begin() { return pData_->buffer_; } - + const_iterator begin() const { return pData_->buffer_; } - + iterator end() { return pData_->pEnd_; } - + const_iterator end() const { return pData_->pEnd_; } - + size_type size() const { return size_type(end() - begin()); } @@ -209,7 +209,7 @@ public: reserve(n); iterator newEnd = begin() + n; iterator oldEnd = end(); - if (newEnd > oldEnd) + if (newEnd > oldEnd) { // Copy the characters flex_string_details::pod_fill(oldEnd, newEnd, c); @@ -221,23 +221,23 @@ public: { if (res_arg <= capacity()) { - // @@@ shrink to fit here + // @@@ shrink to fit here return; } - + A& myAlloc = *this; AllocatorStringStorage newStr(myAlloc); newStr.Init(size(), res_arg); - + flex_string_details::pod_copy(begin(), end(), newStr.begin()); - + swap(newStr); } template void append(ForwardIterator b, ForwardIterator e) { - const size_type + const size_type sz = std::distance(b, e), neededCapacity = size() + sz; @@ -251,26 +251,26 @@ public: std::copy(b, e, end()); pData_->pEnd_ += sz; } - + void swap(AllocatorStringStorage& rhs) { // @@@ The following line is commented due to a bug in MSVC //std::swap(lhsAlloc, rhsAlloc); std::swap(pData_, rhs.pData_); } - + const E* c_str() const - { - if (pData_ != &SimpleStringStorage::emptyString_) + { + if (pData_ != &SimpleStringStorage::emptyString_) { *pData_->pEnd_ = E(); } - return &*begin(); + return &*begin(); } const E* data() const { return &*begin(); } - + A get_allocator() const { return *this; } }; diff --git a/include/loki/flex/cowstringopt.h b/include/loki/flex/cowstringopt.h index d662a95..326a6e7 100644 --- a/include/loki/flex/cowstringopt.h +++ b/include/loki/flex/cowstringopt.h @@ -32,7 +32,7 @@ class StoragePolicy typedef @ const_iterator; typedef A allocator_type; typedef @ size_type; - + StoragePolicy(const StoragePolicy& s); StoragePolicy(const A&); StoragePolicy(const E* s, size_type len, const A&); @@ -43,7 +43,7 @@ class StoragePolicy const_iterator begin() const; iterator end(); const_iterator end() const; - + size_type size() const; size_type max_size() const; size_type capacity() const; @@ -51,17 +51,17 @@ class StoragePolicy void reserve(size_type res_arg); void append(const E* s, size_type sz); - + template void append(InputIterator b, InputIterator e); void resize(size_type newSize, E fill); void swap(StoragePolicy& rhs); - + const E* c_str() const; const E* data() const; - + A get_allocator() const; }; //////////////////////////////////////////////////////////////////////////////// @@ -94,7 +94,7 @@ public: typedef typename Storage::allocator_type allocator_type; typedef typename allocator_type::size_type size_type; typedef typename Storage::reference reference; - + private: union { @@ -112,14 +112,14 @@ private: assert(*d.begin() > 0); return *d.begin(); } - + RefCountType& Refs() { Storage& d = Data(); assert(d.size() > 0); return reinterpret_cast(*d.begin()); } - + void MakeUnique() const { assert(GetRefs() >= 1); @@ -134,7 +134,7 @@ private: --(*Data().begin()); // Harmut Kaiser fix: // decrement the use count of the remaining object new(buf_) Storage( - *new(temp.buf_) Storage(Data()), + *new(temp.buf_) Storage(Data()), flex_string_details::Shallow()); *Data().begin() = 1; } @@ -155,12 +155,12 @@ public: } assert(Data().size() > 0); } - + CowStringOpt(const allocator_type& a) { new(buf_) Storage(1, 1, a); } - + CowStringOpt(const E* s, size_type len, const allocator_type& a) { // Warning - MSVC's debugger has trouble tracing through the code below. @@ -177,7 +177,7 @@ public: new(buf_) Storage(len + 1, c, a); Refs() = 1; } - + CowStringOpt& operator=(const CowStringOpt& rhs) { CowStringOpt(rhs).swap(*this); @@ -194,26 +194,26 @@ public: { assert(Data().size() > 0); MakeUnique(); - return Data().begin() + 1; + return Data().begin() + 1; } - + const_iterator begin() const { assert(Data().size() > 0); - return Data().begin() + 1; + return Data().begin() + 1; } - + iterator end() { MakeUnique(); - return Data().end(); + return Data().end(); } - + const_iterator end() const { - return Data().end(); + return Data().end(); } - + size_type size() const { assert(Data().size() > 0); @@ -221,13 +221,13 @@ public: } size_type max_size() const - { + { assert(Data().max_size() > 0); return Data().max_size() - 1; } size_type capacity() const - { + { assert(Data().capacity() > 0); return Data().capacity() - 1; } @@ -245,33 +245,33 @@ public: MakeUnique(); Data().append(b, e); } - + void reserve(size_type res_arg) { if (capacity() > res_arg) return; MakeUnique(); Data().reserve(res_arg + 1); } - + void swap(CowStringOpt& rhs) { Data().swap(rhs.Data()); } - + const E* c_str() const - { + { assert(Data().size() > 0); return Data().c_str() + 1; } const E* data() const - { + { assert(Data().size() > 0); return Data().data() + 1; } - + allocator_type get_allocator() const - { + { return Data().get_allocator(); } }; diff --git a/include/loki/flex/simplestringstorage.h b/include/loki/flex/simplestringstorage.h index 9b7e236..796a9c6 100644 --- a/include/loki/flex/simplestringstorage.h +++ b/include/loki/flex/simplestringstorage.h @@ -26,7 +26,7 @@ class StoragePolicy typedef @ const_iterator; typedef A allocator_type; typedef @ size_type; - + StoragePolicy(const StoragePolicy& s); StoragePolicy(const A&); StoragePolicy(const E* s, size_type len, const A&); @@ -37,7 +37,7 @@ class StoragePolicy const_iterator begin() const; iterator end(); const_iterator end() const; - + size_type size() const; size_type max_size() const; size_type capacity() const; @@ -50,10 +50,10 @@ class StoragePolicy void resize(size_type newSize, E fill); void swap(StoragePolicy& rhs); - + const E* c_str() const; const E* data() const; - + A get_allocator() const; }; //////////////////////////////////////////////////////////////////////////////// @@ -86,7 +86,7 @@ public: E buffer_[1]; }; static const Data emptyString_; - + typedef typename A::size_type size_type; private: @@ -95,14 +95,14 @@ private: void Init(size_type size, size_type capacity) { assert(size <= capacity); - if (capacity == 0) + if (capacity == 0) { pData_ = const_cast(&emptyString_); } else { - // 11-17-2000: comment added: - // No need to allocate (capacity + 1) to + // 11-17-2000: comment added: + // No need to allocate (capacity + 1) to // accommodate the terminating 0, because Data already // has one one character in there pData_ = static_cast( @@ -112,12 +112,12 @@ private: pData_->pEndOfMem_ = pData_->buffer_ + capacity; } } - + private: // Warning - this doesn't initialize pData_. Used in reserve() SimpleStringStorage() { } - + public: typedef E value_type; typedef E* iterator; @@ -125,23 +125,23 @@ public: typedef A allocator_type; typedef typename A::reference reference; - - SimpleStringStorage(const SimpleStringStorage& rhs) + + SimpleStringStorage(const SimpleStringStorage& rhs) { const size_type sz = rhs.size(); Init(sz, sz); if (sz) flex_string_details::pod_copy(rhs.begin(), rhs.end(), begin()); } - - SimpleStringStorage(const SimpleStringStorage& s, - flex_string_details::Shallow) + + SimpleStringStorage(const SimpleStringStorage& s, + flex_string_details::Shallow) : pData_(s.pData_) { } - + SimpleStringStorage(const A&) { pData_ = const_cast(&emptyString_); } - + SimpleStringStorage(const E* s, size_type len, const A&) { Init(len, len); @@ -153,7 +153,7 @@ public: Init(len, len); flex_string_details::pod_fill(begin(), end(), c); } - + SimpleStringStorage& operator=(const SimpleStringStorage& rhs) { const size_type sz = rhs.size(); @@ -171,16 +171,16 @@ public: iterator begin() { return pData_->buffer_; } - + const_iterator begin() const { return pData_->buffer_; } - + iterator end() { return pData_->pEnd_; } - + const_iterator end() const { return pData_->pEnd_; } - + size_type size() const { return pData_->pEnd_ - pData_->buffer_; } @@ -198,7 +198,7 @@ public: return; } - if (pData_ == &emptyString_) + if (pData_ == &emptyString_) { Init(0, res_arg); } @@ -206,10 +206,10 @@ public: { const size_type sz = size(); - void* p = realloc(pData_, + void* p = realloc(pData_, sizeof(Data) + res_arg * sizeof(E)); if (!p) throw std::bad_alloc(); - + if (p != pData_) { pData_ = static_cast(p); @@ -222,7 +222,7 @@ public: template void append(InputIterator b, InputIterator e) { - const size_type + const size_type sz = std::distance(b, e), neededCapacity = size() + sz; if (capacity() < neededCapacity) @@ -235,7 +235,7 @@ public: std::copy(b, e, end()); pData_->pEnd_ += sz; } - + void resize(size_type newSize, E fill) { const int delta = int(newSize - size()); @@ -243,7 +243,7 @@ public: if (delta > 0) { - if (newSize > capacity()) + if (newSize > capacity()) { reserve(newSize); } @@ -257,16 +257,16 @@ public: { std::swap(pData_, rhs.pData_); } - + const E* c_str() const { if (pData_ != &emptyString_) *pData_->pEnd_ = E(); - return pData_->buffer_; + return pData_->buffer_; } const E* data() const { return pData_->buffer_; } - + A get_allocator() const { return A(); } }; @@ -274,9 +274,9 @@ public: template const typename SimpleStringStorage::Data SimpleStringStorage::emptyString_; -//{ -// const_cast(SimpleStringStorage::emptyString_.buffer_), -// const_cast(SimpleStringStorage::emptyString_.buffer_), +//{ +// const_cast(SimpleStringStorage::emptyString_.buffer_), +// const_cast(SimpleStringStorage::emptyString_.buffer_), // { E() } //}; diff --git a/include/loki/flex/vectorstringstorage.h b/include/loki/flex/vectorstringstorage.h index 55a8081..b74e8e2 100644 --- a/include/loki/flex/vectorstringstorage.h +++ b/include/loki/flex/vectorstringstorage.h @@ -26,7 +26,7 @@ class StoragePolicy typedef @ const_iterator; typedef A allocator_type; typedef @ size_type; - + StoragePolicy(const StoragePolicy& s); StoragePolicy(const A&); StoragePolicy(const E* s, size_type len, const A&); @@ -37,7 +37,7 @@ class StoragePolicy const_iterator begin() const; iterator end(); const_iterator end() const; - + size_type size() const; size_type max_size() const; size_type capacity() const; @@ -45,17 +45,17 @@ class StoragePolicy void reserve(size_type res_arg); void append(const E* s, size_type sz); - + template void append(InputIterator b, InputIterator e); void resize(size_type newSize, E fill); void swap(StoragePolicy& rhs); - + const E* c_str() const; const E* data() const; - + A get_allocator() const; }; //////////////////////////////////////////////////////////////////////////////// @@ -87,13 +87,13 @@ public: // protected: typedef A allocator_type; typedef typename A::size_type size_type; typedef typename A::reference reference; - + VectorStringStorage(const VectorStringStorage& s) : base(s) { } - + VectorStringStorage(const A& a) : base(1, value_type(), a) { } - + VectorStringStorage(const value_type* s, size_type len, const A& a) : base(a) { @@ -109,26 +109,26 @@ public: // protected: // Terminating zero base::back() = value_type(); } - + VectorStringStorage& operator=(const VectorStringStorage& rhs) { base& v = *this; v = rhs; return *this; } - + iterator begin() { return base::begin(); } - + const_iterator begin() const { return base::begin(); } - + iterator end() { return base::end() - 1; } - + const_iterator end() const { return base::end() - 1; } - + size_type size() const { return base::size() - 1; } @@ -139,11 +139,11 @@ public: // protected: { return base::capacity() - 1; } void reserve(size_type res_arg) - { + { assert(res_arg < max_size()); - base::reserve(res_arg + 1); + base::reserve(res_arg + 1); } - + template void append(ForwardIterator b, ForwardIterator e) { @@ -178,13 +178,13 @@ public: // protected: void swap(VectorStringStorage& rhs) { base::swap(rhs); } - + const E* c_str() const { return &*begin(); } const E* data() const { return &*begin(); } - + A get_allocator() const { return base::get_allocator(); } };