lemon/bits/variant.h
changeset 416 76287c8caa26
parent 414 05357da973ce
child 430 09e416d35896
     1.1 --- a/lemon/bits/variant.h	Sun Nov 30 19:00:30 2008 +0100
     1.2 +++ b/lemon/bits/variant.h	Sun Nov 30 19:18:32 2008 +0100
     1.3 @@ -1,6 +1,6 @@
     1.4 -/* -*- C++ -*-
     1.5 +/* -*- mode: C++; indent-tabs-mode: nil; -*-
     1.6   *
     1.7 - * This file is a part of LEMON, a generic C++ optimization library
     1.8 + * This file is a part of LEMON, a generic C++ optimization library.
     1.9   *
    1.10   * Copyright (C) 2003-2008
    1.11   * Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport
    1.12 @@ -27,7 +27,7 @@
    1.13  namespace lemon {
    1.14  
    1.15    namespace _variant_bits {
    1.16 -  
    1.17 +
    1.18      template <int left, int right>
    1.19      struct CTMax {
    1.20        static const int value = left < right ? right : left;
    1.21 @@ -86,9 +86,9 @@
    1.22      BiVariant(const BiVariant& bivariant) {
    1.23        flag = bivariant.flag;
    1.24        if (flag) {
    1.25 -        new(reinterpret_cast<First*>(data)) First(bivariant.first());      
    1.26 +        new(reinterpret_cast<First*>(data)) First(bivariant.first());
    1.27        } else {
    1.28 -        new(reinterpret_cast<Second*>(data)) Second(bivariant.second());      
    1.29 +        new(reinterpret_cast<Second*>(data)) Second(bivariant.second());
    1.30        }
    1.31      }
    1.32  
    1.33 @@ -106,7 +106,7 @@
    1.34      BiVariant& setFirst() {
    1.35        destroy();
    1.36        flag = true;
    1.37 -      new(reinterpret_cast<First*>(data)) First();   
    1.38 +      new(reinterpret_cast<First*>(data)) First();
    1.39        return *this;
    1.40      }
    1.41  
    1.42 @@ -117,7 +117,7 @@
    1.43      BiVariant& setFirst(const First& f) {
    1.44        destroy();
    1.45        flag = true;
    1.46 -      new(reinterpret_cast<First*>(data)) First(f);   
    1.47 +      new(reinterpret_cast<First*>(data)) First(f);
    1.48        return *this;
    1.49      }
    1.50  
    1.51 @@ -128,7 +128,7 @@
    1.52      BiVariant& setSecond() {
    1.53        destroy();
    1.54        flag = false;
    1.55 -      new(reinterpret_cast<Second*>(data)) Second();   
    1.56 +      new(reinterpret_cast<Second*>(data)) Second();
    1.57        return *this;
    1.58      }
    1.59  
    1.60 @@ -139,7 +139,7 @@
    1.61      BiVariant& setSecond(const Second& s) {
    1.62        destroy();
    1.63        flag = false;
    1.64 -      new(reinterpret_cast<Second*>(data)) Second(s);   
    1.65 +      new(reinterpret_cast<Second*>(data)) Second(s);
    1.66        return *this;
    1.67      }
    1.68  
    1.69 @@ -159,9 +159,9 @@
    1.70        destroy();
    1.71        flag = bivariant.flag;
    1.72        if (flag) {
    1.73 -        new(reinterpret_cast<First*>(data)) First(bivariant.first());      
    1.74 +        new(reinterpret_cast<First*>(data)) First(bivariant.first());
    1.75        } else {
    1.76 -        new(reinterpret_cast<Second*>(data)) Second(bivariant.second());      
    1.77 +        new(reinterpret_cast<Second*>(data)) Second(bivariant.second());
    1.78        }
    1.79        return *this;
    1.80      }
    1.81 @@ -231,13 +231,13 @@
    1.82          reinterpret_cast<Second*>(data)->~Second();
    1.83        }
    1.84      }
    1.85 -    
    1.86 +
    1.87      char data[_variant_bits::CTMax<sizeof(First), sizeof(Second)>::value];
    1.88      bool flag;
    1.89    };
    1.90  
    1.91    namespace _variant_bits {
    1.92 -    
    1.93 +
    1.94      template <int _idx, typename _TypeMap>
    1.95      struct Memory {
    1.96  
    1.97 @@ -276,14 +276,14 @@
    1.98  
    1.99      template <int _idx, typename _TypeMap>
   1.100      struct Size {
   1.101 -      static const int value = 
   1.102 -      CTMax<sizeof(typename _TypeMap::template Map<_idx>::Type), 
   1.103 +      static const int value =
   1.104 +      CTMax<sizeof(typename _TypeMap::template Map<_idx>::Type),
   1.105              Size<_idx - 1, _TypeMap>::value>::value;
   1.106      };
   1.107  
   1.108      template <typename _TypeMap>
   1.109      struct Size<0, _TypeMap> {
   1.110 -      static const int value = 
   1.111 +      static const int value =
   1.112        sizeof(typename _TypeMap::template Map<0>::Type);
   1.113      };
   1.114  
   1.115 @@ -301,7 +301,7 @@
   1.116    /// \param _num The number of the types which can be stored in the
   1.117    /// variant type.
   1.118    /// \param _TypeMap This class describes the types of the Variant. The
   1.119 -  /// _TypeMap::Map<index>::Type should be a valid type for each index 
   1.120 +  /// _TypeMap::Map<index>::Type should be a valid type for each index
   1.121    /// in the range {0, 1, ..., _num - 1}. The \c VariantTypeMap is helper
   1.122    /// class to define such type mappings up to 10 types.
   1.123    ///
   1.124 @@ -337,7 +337,7 @@
   1.125      /// with 0 index.
   1.126      Variant() {
   1.127        flag = 0;
   1.128 -      new(reinterpret_cast<typename TypeMap::template Map<0>::Type*>(data)) 
   1.129 +      new(reinterpret_cast<typename TypeMap::template Map<0>::Type*>(data))
   1.130          typename TypeMap::template Map<0>::Type();
   1.131      }
   1.132  
   1.133 @@ -378,7 +378,7 @@
   1.134      Variant& set() {
   1.135        _variant_bits::Memory<num - 1, TypeMap>::destroy(flag, data);
   1.136        flag = _idx;
   1.137 -      new(reinterpret_cast<typename TypeMap::template Map<_idx>::Type*>(data)) 
   1.138 +      new(reinterpret_cast<typename TypeMap::template Map<_idx>::Type*>(data))
   1.139          typename TypeMap::template Map<_idx>::Type();
   1.140        return *this;
   1.141      }
   1.142 @@ -391,7 +391,7 @@
   1.143      Variant& set(const typename _TypeMap::template Map<_idx>::Type& init) {
   1.144        _variant_bits::Memory<num - 1, TypeMap>::destroy(flag, data);
   1.145        flag = _idx;
   1.146 -      new(reinterpret_cast<typename TypeMap::template Map<_idx>::Type*>(data)) 
   1.147 +      new(reinterpret_cast<typename TypeMap::template Map<_idx>::Type*>(data))
   1.148          typename TypeMap::template Map<_idx>::Type(init);
   1.149        return *this;
   1.150      }
   1.151 @@ -403,7 +403,7 @@
   1.152      const typename TypeMap::template Map<_idx>::Type& get() const {
   1.153        LEMON_DEBUG(_idx == flag, "Variant wrong index");
   1.154        return *reinterpret_cast<const typename TypeMap::
   1.155 -        template Map<_idx>::Type*>(data); 
   1.156 +        template Map<_idx>::Type*>(data);
   1.157      }
   1.158  
   1.159      /// \brief Gets the current value of the type with \c _idx index.
   1.160 @@ -413,7 +413,7 @@
   1.161      typename _TypeMap::template Map<_idx>::Type& get() {
   1.162        LEMON_DEBUG(_idx == flag, "Variant wrong index");
   1.163        return *reinterpret_cast<typename TypeMap::template Map<_idx>::Type*>
   1.164 -        (data); 
   1.165 +        (data);
   1.166      }
   1.167  
   1.168      /// \brief Returns the current state of the variant.
   1.169 @@ -424,7 +424,7 @@
   1.170      }
   1.171  
   1.172    private:
   1.173 -    
   1.174 +
   1.175      char data[_variant_bits::Size<num - 1, TypeMap>::value];
   1.176      int flag;
   1.177    };
   1.178 @@ -442,14 +442,14 @@
   1.179      };
   1.180  
   1.181      struct List {};
   1.182 -    
   1.183 +
   1.184      template <typename _Type, typename _List>
   1.185      struct Insert {
   1.186        typedef _List Next;
   1.187        typedef _Type Type;
   1.188      };
   1.189  
   1.190 -    template <int _idx, typename _T0, typename _T1, typename _T2, 
   1.191 +    template <int _idx, typename _T0, typename _T1, typename _T2,
   1.192                typename _T3, typename _T5, typename _T4, typename _T6,
   1.193                typename _T7, typename _T8, typename _T9>
   1.194      struct Mapper {
   1.195 @@ -466,7 +466,7 @@
   1.196        typedef Insert<_T0, L1> L0;
   1.197        typedef typename Get<_idx, L0>::Type Type;
   1.198      };
   1.199 -    
   1.200 +
   1.201    }
   1.202  
   1.203    /// \brief Helper class for Variant
   1.204 @@ -475,7 +475,7 @@
   1.205    /// converts the template parameters to be mappable by integer.
   1.206    /// \see Variant
   1.207    template <
   1.208 -    typename _T0, 
   1.209 +    typename _T0,
   1.210      typename _T1 = void, typename _T2 = void, typename _T3 = void,
   1.211      typename _T5 = void, typename _T4 = void, typename _T6 = void,
   1.212      typename _T7 = void, typename _T8 = void, typename _T9 = void>
   1.213 @@ -487,7 +487,7 @@
   1.214        Type;
   1.215      };
   1.216    };
   1.217 -  
   1.218 +
   1.219  }
   1.220  
   1.221