Ignore:
Timestamp:
Feb 14, 2011, 12:58:25 AM (13 years ago)
Author:
イグトランス (egtra)
Message:

ムーブコンストラクタ・ムーブ代入演算子の導入

File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/egtra/ab5.0/abdev/ab_common/include/Lexical/Source.h

    r739 r810  
    2121    {
    2222    }
     23    IncludedFilesRelation(IncludedFilesRelation const& y)
     24        : filePaths(y.filePaths)
     25        , lineFileNumbers(y.lineFileNumbers)
     26    {
     27    }
     28    IncludedFilesRelation(IncludedFilesRelation&& y)
     29        : filePaths(std::move(y.filePaths))
     30        , lineFileNumbers(std::move(y.lineFileNumbers))
     31    {
     32    }
    2333    ~IncludedFilesRelation()
    2434    {
     35    }
     36    IncludedFilesRelation& operator =(IncludedFilesRelation&& y)
     37    {
     38        filePaths = std::move(y.filePaths);
     39        lineFileNumbers = std::move(y.lineFileNumbers);
     40        return *this;
     41    }
     42
     43    IncludedFilesRelation& operator =(IncludedFilesRelation const& y)
     44    {
     45        return *this = std::move(IncludedFilesRelation(y));
    2546    }
    2647
     
    7697        buffer[length] = 0;
    7798    }
     99    Text(Text&& text)
     100        : length( text.length )
     101    {
     102        buffer = text.buffer;
     103        text.buffer = static_cast<char*>(calloc(1, 1));
     104        text.length = 0;
     105    }
    78106    ~Text(){
    79107        free( buffer );
     
    100128    static void SlideString(char *buffer, int slide){
    101129        memmove(buffer+slide, buffer, strlen(buffer)+1);
     130    }
     131
     132protected:
     133    static void SwapImpl(Text& lhs, Text& rhs)
     134    {
     135        std::swap(lhs.buffer, rhs.buffer);
     136        std::swap(lhs.length, rhs.length);
    102137    }
    103138};
     
    192227    {
    193228    }
     229    BasicSource(BasicSource&& basicSource)
     230        : Text(std::move(basicSource))
     231        , includedFilesRelation(std::move(basicSource.includedFilesRelation))
     232    {
     233    }
    194234    BasicSource( const std::string &source )
    195235    {
     
    230270    bool GetLineInfo( int sourceCodePos, int &line, std::string &fileName ) const;
    231271
    232     void operator = ( const BasicSource &source ){
     272    BasicSource& operator =(const BasicSource &source)
     273    {
    233274        Realloc( source.length );
    234275        strcpy( buffer, source.buffer );
     276        return *this;
     277    }
     278    BasicSource& operator =(BasicSource&& source)
     279    {
     280        Text::SwapImpl(*this, source);
     281        return *this;
    235282    }
    236283
Note: See TracChangeset for help on using the changeset viewer.