]> git.xonotic.org Git - xonotic/netradiant.git/blobdiff - libs/string/string.h
Replace custom string classes with std::string - gone forever version
[xonotic/netradiant.git] / libs / string / string.h
index 7ab7e66b0643186c4f028f411e7bc8646a7705ed..835151dd21044c2d78b64bc972b5b2eea96cfc1e 100644 (file)
@@ -288,224 +288,17 @@ const char* getToken(){
 }
 };
 
-#if 0
-/// \brief A non-mutable c-style string.
-///
-/// \param Buffer The string storage implementation. Must be DefaultConstructible, CopyConstructible and Assignable. Must implement:
-/// \li Buffer(const char* string) - constructor which copies a c-style \p string.
-/// \li Buffer(const char* first, const char*) - constructor which copies a c-style string range [\p first, \p last).
-/// \li void swap(Buffer& other) - swaps contents with \p other.
-/// \li const char* c_str() - returns the stored non-mutable c-style string.
-template<typename Buffer>
-class String : public Buffer
-{
-public:
-
-String()
-       : Buffer(){
-}
-String( const char* string )
-       : Buffer( string ){
-}
-String( StringRange range )
-       : Buffer( range ){
-}
-
-String& operator=( const String& other ){
-       String temp( other );
-       temp.swap( *this );
-       return *this;
-}
-String& operator=( const char* string ){
-       String temp( string );
-       temp.swap( *this );
-       return *this;
-}
-String& operator=( StringRange range ){
-       String temp( range );
-       temp.swap( *this );
-       return *this;
-}
-
-void swap( String& other ){
-       Buffer::swap( other );
-}
-
-bool empty() const {
-       return string_empty( Buffer::c_str() );
-}
-};
-
-template<typename Buffer>
-inline bool operator<( const String<Buffer>& self, const String<Buffer>& other ){
-       return string_less( self.c_str(), other.c_str() );
-}
-
-template<typename Buffer>
-inline bool operator>( const String<Buffer>& self, const String<Buffer>& other ){
-       return string_greater( self.c_str(), other.c_str() );
-}
-
-template<typename Buffer>
-inline bool operator==( const String<Buffer>& self, const String<Buffer>& other ){
-       return string_equal( self.c_str(), other.c_str() );
-}
-
-template<typename Buffer>
-inline bool operator!=( const String<Buffer>& self, const String<Buffer>& other ){
-       return !string_equal( self.c_str(), other.c_str() );
-}
-
-template<typename Buffer>
-inline bool operator==( const String<Buffer>& self, const char* other ){
-       return string_equal( self.c_str(), other );
-}
-
-template<typename Buffer>
-inline bool operator!=( const String<Buffer>& self, const char* other ){
-       return !string_equal( self.c_str(), other );
-}
-
-namespace std
-{
-/// \brief Swaps the values of \p self and \p other.
-/// Overloads std::swap.
-template<typename Buffer>
-inline void swap( String<Buffer>& self, String<Buffer>& other ){
-       self.swap( other );
-}
-}
-
-
-/// \brief A non-mutable string buffer which manages memory allocation.
-template<typename Allocator>
-class CopiedBuffer : private Allocator
-{
-char* m_string;
-
-char* copy_range( StringRange range ){
-       return string_clone_range( range, static_cast<Allocator&>( *this ) );
-}
-char* copy( const char* other ){
-       return string_clone( other, static_cast<Allocator&>( *this ) );
-}
-void destroy( char* string ){
-       string_release( string, string_length( string ), static_cast<Allocator&>( *this ) );
-}
-
-protected:
-~CopiedBuffer(){
-       destroy( m_string );
-}
-public:
-CopiedBuffer()
-       : m_string( copy( "" ) ){
-}
-explicit CopiedBuffer( const Allocator& allocator )
-       : Allocator( allocator ), m_string( copy( "" ) ){
-}
-CopiedBuffer( const CopiedBuffer& other )
-       : Allocator( other ), m_string( copy( other.m_string ) ){
-}
-CopiedBuffer( const char* string, const Allocator& allocator = Allocator() )
-       : Allocator( allocator ), m_string( copy( string ) ){
-}
-CopiedBuffer( StringRange range, const Allocator& allocator = Allocator() )
-       : Allocator( allocator ), m_string( copy_range( range ) ){
-}
-const char* c_str() const {
-       return m_string;
-}
-void swap( CopiedBuffer& other ){
-       string_swap( m_string, other.m_string );
-}
-};
-
-/// \brief A non-mutable string which uses copy-by-value for assignment.
-typedef String< CopiedBuffer< DefaultAllocator<char> > > CopiedString;
-
-/// \brief A non-mutable string buffer which uses reference-counting to avoid unnecessary allocations.
-template<typename Allocator>
-class SmartBuffer : private Allocator
-{
-char* m_buffer;
-
-char* copy_range( StringRange range ){
-       char* buffer = Allocator::allocate( sizeof( std::size_t ) + ( range.last - range.first ) + 1 );
-       strncpy( buffer + sizeof( std::size_t ), range.first, range.last - range.first );
-       buffer[sizeof( std::size_t ) + ( range.last - range.first )] = '\0';
-       *reinterpret_cast<std::size_t*>( buffer ) = 0;
-       return buffer;
-}
-char* copy( const char* string ){
-       char* buffer = Allocator::allocate( sizeof( std::size_t ) + string_length( string ) + 1 );
-       strcpy( buffer + sizeof( std::size_t ), string );
-       *reinterpret_cast<std::size_t*>( buffer ) = 0;
-       return buffer;
-}
-void destroy( char* buffer ){
-       Allocator::deallocate( buffer, sizeof( std::size_t ) + string_length( c_str() ) + 1 );
-}
-
-void incref( char* buffer ){
-       ++( *reinterpret_cast<std::size_t*>( buffer ) );
-}
-void decref( char* buffer ){
-       if ( --( *reinterpret_cast<std::size_t*>( buffer ) ) == 0 ) {
-               destroy( buffer );
-       }
-}
-
-protected:
-~SmartBuffer(){
-       decref( m_buffer );
-}
-public:
-SmartBuffer()
-       : m_buffer( copy( "" ) ){
-       incref( m_buffer );
-}
-explicit SmartBuffer( const Allocator& allocator )
-       : Allocator( allocator ), m_buffer( copy( "" ) ){
-       incref( m_buffer );
-}
-SmartBuffer( const SmartBuffer& other )
-       : Allocator( other ), m_buffer( other.m_buffer ){
-       incref( m_buffer );
-}
-SmartBuffer( const char* string, const Allocator& allocator = Allocator() )
-       : Allocator( allocator ), m_buffer( copy( string ) ){
-       incref( m_buffer );
-}
-SmartBuffer( StringRange range, const Allocator& allocator = Allocator() )
-       : Allocator( allocator ), m_buffer( copy_range( range ) ){
-       incref( m_buffer );
-}
-const char* c_str() const {
-       return m_buffer + sizeof( std::size_t );
-}
-void swap( SmartBuffer& other ){
-       string_swap( m_buffer, other.m_buffer );
-}
-};
-
-/// \brief A non-mutable string which uses copy-by-reference for assignment of SmartString.
-typedef String< SmartBuffer< DefaultAllocator<char> > > SmartString;
-#endif
-
-typedef std::string CopiedString;
-
 class StringEqualNoCase
 {
 public:
-bool operator()( const CopiedString& key, const CopiedString& other ) const {
+bool operator()( const std::string& key, const std::string& other ) const {
        return string_equal_nocase( key.c_str(), other.c_str() );
 }
 };
 
 struct StringLessNoCase
 {
-       bool operator()( const CopiedString& x, const CopiedString& y ) const {
+       bool operator()( const std::string& x, const std::string& y ) const {
                return string_less_nocase( x.c_str(), y.c_str() );
        }
 };