webForumDet fria alternativet

pthread_string

2 svar · 340 visningar · startad av fnolis

fnolisMedlem sedan sep. 200162 inlägg
#1

Någon som har lite roliga kommentarer på denna classen? Har nog fått lite type cast förmycket här och där... men jag har blivit så förvirrad på koden att jag inte orkar kolla på den mer just nu...

<font size="1" face="Verdana, Arial, Helvetica, sans-serif">Kod:<font size="1" face="Verdana, Arial, Helvetica, sans-serif" color="#666600">
#ifndef _pthread_string_hpp_
#define _pthread_string_hpp_

#include <pthread.h>
#include <iostream>
#include <unistd.h>
#include <string>
#include <bits/stl_pthread_alloc.h>

namespace std
{

typedef std::\__allocator\<char, std::pthread_alloc\>                                  std_char_pthread_alloc;
typedef std::basic_string\< char, std::char_traits\<char\>, std_char_pthread_alloc \>   std_pthread_basic_string;

class pthread_string : public std_pthread_basic_string
{
    public:
        pthread_string() throw(): std_pthread_basic_string()
        {
        }

        pthread_string( const std_pthread_basic_string& pth_b_str ) throw(): std_pthread_basic_string( pth_b_str )
        {
        }

        pthread_string( const char\* x, int& y ) throw(): std_pthread_basic_string( x, y )
        {
        }

        pthread_string( const pthread_string& pth_str ) throw()
        {
            \*this = pth_str;
        }

        pthread_string( const string& str ) throw()
        {
            \*this = str.c_str();
        }

        pthread_string( const char\* str ) throw() : std_pthread_basic_string(str)
        {
        }

        pthread_string& operator=( const std_pthread_basic_string& str) throw()
        {
            return (pthread_string&) (\*(std_pthread_basic_string\*)this = str);
        }

        pthread_string& operator=( const string& str ) throw()
        {
            return (pthread_string&) (\*this = str.c_str());
        }
        pthread_string& operator=( const char\* str ) throw()
        {
            return (pthread_string&) (\*(std_pthread_basic_string\*)this = str);
        }
        pthread_string& operator+=( const std_pthread_basic_string& str) throw()
        {
            return (pthread_string&) (\*(std_pthread_basic_string\*)this += str);
        }

        pthread_string& operator+=( const string& str) throw()
        {
            return (pthread_string&) (\*(std_pthread_basic_string\*)this += str.c_str());
        }

        pthread_string& operator+=( const char\* str ) throw()
        {
            return (pthread_string&) (\*(std_pthread_basic_string\*)this += str);
        }

        pthread_string& operator+=( const char& str ) throw()
        {
            this-\>push_back( str );
            return \*this;
        }

        bool operator==( const string& str )
        {
            return !strcmp(this-\>c_str(), str.c_str());
        }

        bool operator==( const char\* str)
        {
            return !strcmp(this-\>c_str(), str );
        }

        string to_string( void ) const throw()
        {
            return this-\>c_str();
        }

        int to_int( void ) const throw()
        {
            return atoi( this-\>c_str());
        }

        string& convert( string& str) const throw()
        {
            str = this-\>c_str();
            return str ;
        }

        int& convert( int& x) const throw()
        {
            return x = atoi( this-\>c_str());
        }
};

}
#endif //_pthread_string_hpp_

fnolisMedlem sedan sep. 200162 inlägg
#2

använd _I N T E_ denna class! eftersom basic_string:s destuctor inte är virtuell så läcker denna class som ett soll! Håller på att skriva en ny class med samma namn och samma interface...

fnolisMedlem sedan sep. 200162 inlägg
#3

humm... om man tar bort #include <iostream> så läcker den inte mer... skumt.. i alla fall på gcc 3.0.x har inte provat på någon annan kompilator...

Genererad på 387 ms · cache AV · v20260730165559-full.f96bc7eb