Changeset 810 in dev


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

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

Location:
branches/egtra/ab5.0/abdev/ab_common
Files:
4 edited

Legend:

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

    r750 r810  
    77class NamespaceScopes : public std::vector<std::string>
    88{
     9    typedef std::vector<std::string> Base;
    910    // XMLシリアライズ用
    1011private:
     
    1718
    1819public:
    19     NamespaceScopes(){}
     20    NamespaceScopes() {}
     21    NamespaceScopes(NamespaceScopes const& y)
     22        : Base(y)
     23    {
     24    }
     25    NamespaceScopes(NamespaceScopes&& y)
     26        : Base(std::move(y))
     27    {
     28    }
    2029    NamespaceScopes( const std::string &namespaceStr );
    2130    NamespaceScopes( NamespaceScopes::const_iterator first, NamespaceScopes::const_iterator last )
    22         : std::vector<std::string>( first, last )
     31        : Base(first, last)
    2332    {
    2433    }
    2534    ~NamespaceScopes(){}
    2635
    27     NamespaceScopes operator+ ( const NamespaceScopes &namespaceScopes ) const;
    28 
    2936    void append( const NamespaceScopes &namespaceScopes )
    3037    {
    3138        insert( end(), namespaceScopes.begin(), namespaceScopes.end() );
     39    }
     40
     41    NamespaceScopes& operator +=(const NamespaceScopes &namespaceScopes)
     42    {
     43        append(namespaceScopes);
     44        return *this;
    3245    }
    3346
     
    7790};
    7891
     92NamespaceScopes operator +(const NamespaceScopes &lhs, const NamespaceScopes &rhs);
     93
    7994inline bool operator ==( const NamespaceScopes &lhs, const NamespaceScopes &rhs )
    8095{
     
    8499class NamespaceScopesCollection : public std::vector<NamespaceScopes>
    85100{
     101    typedef std::vector<NamespaceScopes> Base;
    86102    // XMLシリアライズ用
    87103private:
     
    93109
    94110public:
     111    NamespaceScopesCollection() : Base() {}
     112    NamespaceScopesCollection(NamespaceScopesCollection&& y) : Base(std::move(y)) {}
     113    NamespaceScopesCollection(NamespaceScopesCollection const& y) : Base(y) {}
     114    NamespaceScopesCollection& operator =(NamespaceScopesCollection&& y)
     115    {
     116        Base::operator =(std::move(y));
     117        return *this;
     118    }
     119    NamespaceScopesCollection& operator =(NamespaceScopesCollection const& y)
     120    {
     121        return operator =(NamespaceScopesCollection(y));
     122    }
    95123    bool IsExist( const NamespaceScopes &namespaceScopes ) const
    96124    {
  • 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
  • branches/egtra/ab5.0/abdev/ab_common/include/Lexical/Symbol.h

    r637 r810  
    4848    {
    4949    }
     50    Symbol(Symbol&& symbol)
     51        : namespaceScopes(std::move(symbol.namespaceScopes))
     52        , name(std::move(symbol.name))
     53    {
     54    }
    5055    Symbol()
    5156    {
     57    }
     58    Symbol& operator =(Symbol&& symbol)
     59    {
     60        namespaceScopes = std::move(symbol.namespaceScopes);
     61        name = std::move(symbol.name);
     62        return *this;
     63    }
     64    Symbol& operator =(Symbol const& symbol)
     65    {
     66        return *this = Symbol(symbol);
    5267    }
    5368
  • branches/egtra/ab5.0/abdev/ab_common/src/Lexical/Namespace.cpp

    r736 r810  
    1616        std::string tempName = namespaceStr.substr( i, i2-i );
    1717
    18         push_back( tempName );
     18        push_back(std::move(tempName));
    1919
    2020        if( i2 == std::string::npos ){
     
    2626}
    2727
    28 NamespaceScopes NamespaceScopes::operator+ ( const NamespaceScopes &namespaceScopes ) const
     28NamespaceScopes ActiveBasic::Common::Lexical::operator +(const NamespaceScopes &lhs, const NamespaceScopes &rhs)
    2929{
    30     NamespaceScopes result;
    31     result.reserve( this->size() + namespaceScopes.size() );
    32     result = *this;
    33     result.append( namespaceScopes );
    34     return result;
     30    return NamespaceScopes(lhs) += rhs;
    3531}
    3632
Note: See TracChangeset for help on using the changeset viewer.