[Cppunit-cvs] cppunit2/include/cpptl conststring.h,NONE,1.1 forwards.h,NONE,1.1
Brought to you by:
blep
From: Baptiste L. <bl...@us...> - 2005-02-26 13:44:25
|
Update of /cvsroot/cppunit/cppunit2/include/cpptl In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv8088/include/cpptl Added Files: conststring.h forwards.h Log Message: * added simple ConstString implementation --- NEW FILE: conststring.h --- #ifndef CPPTL_CONSTSTRING_H_INCLUDED # define CPPTL_CONSTSTRING_H_INCLUDED # include <cpptl/config.h> # include <string.h> namespace CppTL { class ConstStringIterator { public: typedef char value_type; typedef unsigned int size_type; ConstStringIterator() : current_( 0 ) { } ConstStringIterator( const value_type *current ) : current_( current ) { } char operator *() const { return *current_; } char operator[]( size_type index ) const { return current_[index]; } ConstStringIterator &operator ++() { ++current_; return *this; } ConstStringIterator operator ++(int) { ConstStringIterator it( *this ); ++current_; return it; } ConstStringIterator &operator --() { --current_; return *this; } ConstStringIterator operator --(int) { ConstStringIterator it( *this ); --current_; return it; } bool operator ==( const ConstStringIterator &other ) const { return current_ == other.current_; } bool operator !=( const ConstStringIterator &other ) const { return current_ != other.current_; } bool operator <( const ConstStringIterator &other ) const { return current_ < other.current_; } bool operator <=( const ConstStringIterator &other ) const { return current_ <= other.current_; } bool operator >( const ConstStringIterator &other ) const { return current_ > other.current_; } bool operator >=( const ConstStringIterator &other ) const { return current_ >= other.current_; } private: const value_type *current_; }; class ConstString { public: typedef unsigned int size_type; typedef char value_type; typedef ConstStringIterator const_iterator; ConstString(); ConstString( const value_type *begin, const value_type *end ); ConstString( const value_type *begin, size_type length ); ConstString( const ConstString &other ); ~ConstString(); ConstString &operator =( const ConstString &other ); void swap( ConstString &other ); const value_type *c_str() const; const value_type *end_c_str() const; size_type length() const; bool empty() const; value_type operator[]( size_type index ) const; private: size_type length_; char *buffer_; }; // ////////////////////////////////////////////////////////////////// // ////////////////////////////////////////////////////////////////// // class ConstString // ////////////////////////////////////////////////////////////////// // ////////////////////////////////////////////////////////////////// ConstString::ConstString() : length_( 0 ) , buffer_( 0 ) { } ConstString::ConstString( const value_type *begin, const value_type *end ) : length_( end - begin ) , buffer_( new value_type[end-begin+1] ) { memcpy( buffer_, begin, end-begin ); buffer_[ length_ ] = 0; } ConstString::ConstString( const ConstString &other ) : length_( other.length_ ) { buffer_ = new value_type[length_+1]; memcpy( buffer_, other.buffer_, length_+1 ); } ConstString::~ConstString() { delete [] buffer_; } ConstString & ConstString::operator =( const ConstString &other ) { ConstString temp( other ); swap( other ); return *this; } void ConstString::swap( ConstString &other ) { size_type tempLength = length_; value_type *tempBuffer = buffer_; length_ = other.length_; buffer_ = other.buffer_; other.length_ = tempLength; other.buffer_ = tempBuffer; } const ConstString::value_type * ConstString::c_str() const { return buffer_ ? buffer_ : ""; } const ConstString::value_type * ConstString::end_c_str() const { return buffer_ + length_; } ConstString::size_type ConstString::length() const { return length_; } bool ConstString::empty() const { return length_ == 0; } ConstString::value_type ConstString::operator[]( size_type index ) const { return buffer_[index]; } } // namespace CppTL #endif // CPPTL_CONSTSTRING_H_INCLUDED --- NEW FILE: forwards.h --- #ifndef CPPTL_FORWARDS_H_INCLUDED # define CPPTL_FORWARDS_H_INCLUDED # include <cpptl/config.h> namespace CppTL { // atomiccounter.h class AtomicCounter; // conststring.h class ConstString; // enumerator.h template<class ValueType> class AnyEnumerator; // sharedptr.h template<class PointeeType> class SharedPtr; // functor.h class Functor0; } // namespace CppTL #endif // CPPTL_FORWARDS_H_INCLUDED |