COIN-OR::LEMON - Graph Library

Changeset 432:76287c8caa26 in lemon for lemon/bits/variant.h


Ignore:
Timestamp:
11/30/08 19:18:32 (15 years ago)
Author:
Balazs Dezso <deba@…>
Branch:
default
Phase:
public
Message:

Reorganication of graph adaptors and doc improvements (#67)

  • Moving to one file, lemon/adaptors.h
  • Renamings
  • Doc cleanings
File:
1 edited

Legend:

Unmodified
Added
Removed
  • lemon/bits/variant.h

    r430 r432  
    1 /* -*- C++ -*-
     1/* -*- mode: C++; indent-tabs-mode: nil; -*-
    22 *
    3  * This file is a part of LEMON, a generic C++ optimization library
     3 * This file is a part of LEMON, a generic C++ optimization library.
    44 *
    55 * Copyright (C) 2003-2008
     
    2828
    2929  namespace _variant_bits {
    30  
     30
    3131    template <int left, int right>
    3232    struct CTMax {
     
    8787      flag = bivariant.flag;
    8888      if (flag) {
    89         new(reinterpret_cast<First*>(data)) First(bivariant.first());     
     89        new(reinterpret_cast<First*>(data)) First(bivariant.first());
    9090      } else {
    91         new(reinterpret_cast<Second*>(data)) Second(bivariant.second());     
     91        new(reinterpret_cast<Second*>(data)) Second(bivariant.second());
    9292      }
    9393    }
     
    107107      destroy();
    108108      flag = true;
    109       new(reinterpret_cast<First*>(data)) First();   
     109      new(reinterpret_cast<First*>(data)) First();
    110110      return *this;
    111111    }
     
    118118      destroy();
    119119      flag = true;
    120       new(reinterpret_cast<First*>(data)) First(f);   
     120      new(reinterpret_cast<First*>(data)) First(f);
    121121      return *this;
    122122    }
     
    129129      destroy();
    130130      flag = false;
    131       new(reinterpret_cast<Second*>(data)) Second();   
     131      new(reinterpret_cast<Second*>(data)) Second();
    132132      return *this;
    133133    }
     
    140140      destroy();
    141141      flag = false;
    142       new(reinterpret_cast<Second*>(data)) Second(s);   
     142      new(reinterpret_cast<Second*>(data)) Second(s);
    143143      return *this;
    144144    }
     
    160160      flag = bivariant.flag;
    161161      if (flag) {
    162         new(reinterpret_cast<First*>(data)) First(bivariant.first());     
     162        new(reinterpret_cast<First*>(data)) First(bivariant.first());
    163163      } else {
    164         new(reinterpret_cast<Second*>(data)) Second(bivariant.second());     
     164        new(reinterpret_cast<Second*>(data)) Second(bivariant.second());
    165165      }
    166166      return *this;
     
    232232      }
    233233    }
    234    
     234
    235235    char data[_variant_bits::CTMax<sizeof(First), sizeof(Second)>::value];
    236236    bool flag;
     
    238238
    239239  namespace _variant_bits {
    240    
     240
    241241    template <int _idx, typename _TypeMap>
    242242    struct Memory {
     
    277277    template <int _idx, typename _TypeMap>
    278278    struct Size {
    279       static const int value = 
    280       CTMax<sizeof(typename _TypeMap::template Map<_idx>::Type), 
     279      static const int value =
     280      CTMax<sizeof(typename _TypeMap::template Map<_idx>::Type),
    281281            Size<_idx - 1, _TypeMap>::value>::value;
    282282    };
     
    284284    template <typename _TypeMap>
    285285    struct Size<0, _TypeMap> {
    286       static const int value = 
     286      static const int value =
    287287      sizeof(typename _TypeMap::template Map<0>::Type);
    288288    };
     
    302302  /// variant type.
    303303  /// \param _TypeMap This class describes the types of the Variant. The
    304   /// _TypeMap::Map<index>::Type should be a valid type for each index 
     304  /// _TypeMap::Map<index>::Type should be a valid type for each index
    305305  /// in the range {0, 1, ..., _num - 1}. The \c VariantTypeMap is helper
    306306  /// class to define such type mappings up to 10 types.
     
    338338    Variant() {
    339339      flag = 0;
    340       new(reinterpret_cast<typename TypeMap::template Map<0>::Type*>(data)) 
     340      new(reinterpret_cast<typename TypeMap::template Map<0>::Type*>(data))
    341341        typename TypeMap::template Map<0>::Type();
    342342    }
     
    379379      _variant_bits::Memory<num - 1, TypeMap>::destroy(flag, data);
    380380      flag = _idx;
    381       new(reinterpret_cast<typename TypeMap::template Map<_idx>::Type*>(data)) 
     381      new(reinterpret_cast<typename TypeMap::template Map<_idx>::Type*>(data))
    382382        typename TypeMap::template Map<_idx>::Type();
    383383      return *this;
     
    392392      _variant_bits::Memory<num - 1, TypeMap>::destroy(flag, data);
    393393      flag = _idx;
    394       new(reinterpret_cast<typename TypeMap::template Map<_idx>::Type*>(data)) 
     394      new(reinterpret_cast<typename TypeMap::template Map<_idx>::Type*>(data))
    395395        typename TypeMap::template Map<_idx>::Type(init);
    396396      return *this;
     
    404404      LEMON_DEBUG(_idx == flag, "Variant wrong index");
    405405      return *reinterpret_cast<const typename TypeMap::
    406         template Map<_idx>::Type*>(data); 
     406        template Map<_idx>::Type*>(data);
    407407    }
    408408
     
    414414      LEMON_DEBUG(_idx == flag, "Variant wrong index");
    415415      return *reinterpret_cast<typename TypeMap::template Map<_idx>::Type*>
    416         (data); 
     416        (data);
    417417    }
    418418
     
    425425
    426426  private:
    427    
     427
    428428    char data[_variant_bits::Size<num - 1, TypeMap>::value];
    429429    int flag;
     
    443443
    444444    struct List {};
    445    
     445
    446446    template <typename _Type, typename _List>
    447447    struct Insert {
     
    450450    };
    451451
    452     template <int _idx, typename _T0, typename _T1, typename _T2, 
     452    template <int _idx, typename _T0, typename _T1, typename _T2,
    453453              typename _T3, typename _T5, typename _T4, typename _T6,
    454454              typename _T7, typename _T8, typename _T9>
     
    467467      typedef typename Get<_idx, L0>::Type Type;
    468468    };
    469    
     469
    470470  }
    471471
     
    476476  /// \see Variant
    477477  template <
    478     typename _T0, 
     478    typename _T0,
    479479    typename _T1 = void, typename _T2 = void, typename _T3 = void,
    480480    typename _T5 = void, typename _T4 = void, typename _T6 = void,
     
    488488    };
    489489  };
    490  
     490
    491491}
    492492
Note: See TracChangeset for help on using the changeset viewer.