gravatar
kpeter (Peter Kovacs)
kpeter@inf.elte.hu
Hide all docs in variant.h (#196)
0 1 0
default
1 file changed with 151 insertions and 151 deletions:
↑ Collapse diff ↑
Show white space 6 line context
... ...
@@ -23,4 +23,4 @@
23 23

	
24
/// \file
25
/// \brief Variant types
24
// \file
25
// \brief Variant types
26 26

	
... ...
@@ -38,10 +38,10 @@
38 38

	
39
  /// \brief Simple Variant type for two types
40
  ///
41
  /// Simple Variant type for two types. The Variant type is a type
42
  /// safe union. The C++ has strong limitations for using unions, by
43
  /// example we can not store type with non default constructor or
44
  /// destructor in an union. This class always knowns the current
45
  /// state of the variant and it cares for the proper construction
46
  /// and destruction.
39
  // \brief Simple Variant type for two types
40
  //
41
  // Simple Variant type for two types. The Variant type is a type-safe
42
  // union. C++ has strong limitations for using unions, for
43
  // example you cannot store a type with non-default constructor or
44
  // destructor in a union. This class always knowns the current
45
  // state of the variant and it cares for the proper construction
46
  // and destruction.
47 47
  template <typename _First, typename _Second>
... ...
@@ -50,11 +50,11 @@
50 50

	
51
    /// \brief The \c First type.
51
    // \brief The \c First type.
52 52
    typedef _First First;
53
    /// \brief The \c Second type.
53
    // \brief The \c Second type.
54 54
    typedef _Second Second;
55 55

	
56
    /// \brief Constructor
57
    ///
58
    /// This constructor initalizes to the default value of the \c First
59
    /// type.
56
    // \brief Constructor
57
    //
58
    // This constructor initalizes to the default value of the \c First
59
    // type.
60 60
    BiVariant() {
... ...
@@ -64,6 +64,6 @@
64 64

	
65
    /// \brief Constructor
66
    ///
67
    /// This constructor initalizes to the given value of the \c First
68
    /// type.
65
    // \brief Constructor
66
    //
67
    // This constructor initalizes to the given value of the \c First
68
    // type.
69 69
    BiVariant(const First& f) {
... ...
@@ -73,6 +73,6 @@
73 73

	
74
    /// \brief Constructor
75
    ///
76
    /// This constructor initalizes to the given value of the \c
77
    /// Second type.
74
    // \brief Constructor
75
    //
76
    // This constructor initalizes to the given value of the \c
77
    // Second type.
78 78
    BiVariant(const Second& s) {
... ...
@@ -82,5 +82,5 @@
82 82

	
83
    /// \brief Copy constructor
84
    ///
85
    /// Copy constructor
83
    // \brief Copy constructor
84
    //
85
    // Copy constructor
86 86
    BiVariant(const BiVariant& bivariant) {
... ...
@@ -94,5 +94,5 @@
94 94

	
95
    /// \brief Destrcutor
96
    ///
97
    /// Destructor
95
    // \brief Destrcutor
96
    //
97
    // Destructor
98 98
    ~BiVariant() {
... ...
@@ -101,6 +101,6 @@
101 101

	
102
    /// \brief Set to the default value of the \c First type.
103
    ///
104
    /// This function sets the variant to the default value of the \c
105
    /// First type.
102
    // \brief Set to the default value of the \c First type.
103
    //
104
    // This function sets the variant to the default value of the \c
105
    // First type.
106 106
    BiVariant& setFirst() {
... ...
@@ -112,6 +112,6 @@
112 112

	
113
    /// \brief Set to the given value of the \c First type.
114
    ///
115
    /// This function sets the variant to the given value of the \c
116
    /// First type.
113
    // \brief Set to the given value of the \c First type.
114
    //
115
    // This function sets the variant to the given value of the \c
116
    // First type.
117 117
    BiVariant& setFirst(const First& f) {
... ...
@@ -123,6 +123,6 @@
123 123

	
124
    /// \brief Set to the default value of the \c Second type.
125
    ///
126
    /// This function sets the variant to the default value of the \c
127
    /// Second type.
124
    // \brief Set to the default value of the \c Second type.
125
    //
126
    // This function sets the variant to the default value of the \c
127
    // Second type.
128 128
    BiVariant& setSecond() {
... ...
@@ -134,6 +134,6 @@
134 134

	
135
    /// \brief Set to the given value of the \c Second type.
136
    ///
137
    /// This function sets the variant to the given value of the \c
138
    /// Second type.
135
    // \brief Set to the given value of the \c Second type.
136
    //
137
    // This function sets the variant to the given value of the \c
138
    // Second type.
139 139
    BiVariant& setSecond(const Second& s) {
... ...
@@ -145,3 +145,3 @@
145 145

	
146
    /// \brief Operator form of the \c setFirst()
146
    // \brief Operator form of the \c setFirst()
147 147
    BiVariant& operator=(const First& f) {
... ...
@@ -150,3 +150,3 @@
150 150

	
151
    /// \brief Operator form of the \c setSecond()
151
    // \brief Operator form of the \c setSecond()
152 152
    BiVariant& operator=(const Second& s) {
... ...
@@ -155,3 +155,3 @@
155 155

	
156
    /// \brief Assign operator
156
    // \brief Assign operator
157 157
    BiVariant& operator=(const BiVariant& bivariant) {
... ...
@@ -168,56 +168,56 @@
168 168

	
169
    /// \brief Reference to the value
170
    ///
171
    /// Reference to the value of the \c First type.
172
    /// \pre The BiVariant should store value of \c First type.
169
    // \brief Reference to the value
170
    //
171
    // Reference to the value of the \c First type.
172
    // \pre The BiVariant should store value of \c First type.
173 173
    First& first() {
174 174
      LEMON_DEBUG(flag, "Variant wrong state");
175
      return *reinterpret_cast<First*>(data); 
175
      return *reinterpret_cast<First*>(data);
176 176
    }
177 177

	
178
    /// \brief Const reference to the value
179
    ///
180
    /// Const reference to the value of the \c First type.
181
    /// \pre The BiVariant should store value of \c First type.
182
    const First& first() const { 
178
    // \brief Const reference to the value
179
    //
180
    // Const reference to the value of the \c First type.
181
    // \pre The BiVariant should store value of \c First type.
182
    const First& first() const {
183 183
      LEMON_DEBUG(flag, "Variant wrong state");
184
      return *reinterpret_cast<const First*>(data); 
184
      return *reinterpret_cast<const First*>(data);
185 185
    }
186 186

	
187
    /// \brief Operator form of the \c first()
187
    // \brief Operator form of the \c first()
188 188
    operator First&() { return first(); }
189
    /// \brief Operator form of the const \c first()
189
    // \brief Operator form of the const \c first()
190 190
    operator const First&() const { return first(); }
191 191

	
192
    /// \brief Reference to the value
193
    ///
194
    /// Reference to the value of the \c Second type.
195
    /// \pre The BiVariant should store value of \c Second type.
196
    Second& second() { 
192
    // \brief Reference to the value
193
    //
194
    // Reference to the value of the \c Second type.
195
    // \pre The BiVariant should store value of \c Second type.
196
    Second& second() {
197 197
      LEMON_DEBUG(!flag, "Variant wrong state");
198
      return *reinterpret_cast<Second*>(data); 
198
      return *reinterpret_cast<Second*>(data);
199 199
    }
200 200

	
201
    /// \brief Const reference to the value
202
    ///
203
    /// Const reference to the value of the \c Second type.
204
    /// \pre The BiVariant should store value of \c Second type.
205
    const Second& second() const { 
201
    // \brief Const reference to the value
202
    //
203
    // Const reference to the value of the \c Second type.
204
    // \pre The BiVariant should store value of \c Second type.
205
    const Second& second() const {
206 206
      LEMON_DEBUG(!flag, "Variant wrong state");
207
      return *reinterpret_cast<const Second*>(data); 
207
      return *reinterpret_cast<const Second*>(data);
208 208
    }
209 209

	
210
    /// \brief Operator form of the \c second()
210
    // \brief Operator form of the \c second()
211 211
    operator Second&() { return second(); }
212
    /// \brief Operator form of the const \c second()
212
    // \brief Operator form of the const \c second()
213 213
    operator const Second&() const { return second(); }
214 214

	
215
    /// \brief %True when the variant is in the first state
216
    ///
217
    /// %True when the variant stores value of the \c First type.
215
    // \brief %True when the variant is in the first state
216
    //
217
    // %True when the variant stores value of the \c First type.
218 218
    bool firstState() const { return flag; }
219 219

	
220
    /// \brief %True when the variant is in the second state
221
    ///
222
    /// %True when the variant stores value of the \c Second type.
220
    // \brief %True when the variant is in the second state
221
    //
222
    // %True when the variant stores value of the \c Second type.
223 223
    bool secondState() const { return !flag; }
... ...
@@ -291,36 +291,36 @@
291 291

	
292
  /// \brief Variant type
293
  ///
294
  /// Simple Variant type. The Variant type is a type safe union. The
295
  /// C++ has strong limitations for using unions, for example we
296
  /// cannot store type with non default constructor or destructor in
297
  /// a union. This class always knowns the current state of the
298
  /// variant and it cares for the proper construction and
299
  /// destruction.
300
  ///
301
  /// \param _num The number of the types which can be stored in the
302
  /// variant type.
303
  /// \param _TypeMap This class describes the types of the Variant. The
304
  /// _TypeMap::Map<index>::Type should be a valid type for each index
305
  /// in the range {0, 1, ..., _num - 1}. The \c VariantTypeMap is helper
306
  /// class to define such type mappings up to 10 types.
307
  ///
308
  /// And the usage of the class:
309
  ///\code
310
  /// typedef Variant<3, VariantTypeMap<int, std::string, double> > MyVariant;
311
  /// MyVariant var;
312
  /// var.set<0>(12);
313
  /// std::cout << var.get<0>() << std::endl;
314
  /// var.set<1>("alpha");
315
  /// std::cout << var.get<1>() << std::endl;
316
  /// var.set<2>(0.75);
317
  /// std::cout << var.get<2>() << std::endl;
318
  ///\endcode
319
  ///
320
  /// The result of course:
321
  ///\code
322
  /// 12
323
  /// alpha
324
  /// 0.75
325
  ///\endcode
292
  // \brief Variant type
293
  //
294
  // Simple Variant type. The Variant type is a type-safe union.
295
  // C++ has strong limitations for using unions, for example you
296
  // cannot store type with non-default constructor or destructor in
297
  // a union. This class always knowns the current state of the
298
  // variant and it cares for the proper construction and
299
  // destruction.
300
  //
301
  // \param _num The number of the types which can be stored in the
302
  // variant type.
303
  // \param _TypeMap This class describes the types of the Variant. The
304
  // _TypeMap::Map<index>::Type should be a valid type for each index
305
  // in the range {0, 1, ..., _num - 1}. The \c VariantTypeMap is helper
306
  // class to define such type mappings up to 10 types.
307
  //
308
  // And the usage of the class:
309
  //\code
310
  // typedef Variant<3, VariantTypeMap<int, std::string, double> > MyVariant;
311
  // MyVariant var;
312
  // var.set<0>(12);
313
  // std::cout << var.get<0>() << std::endl;
314
  // var.set<1>("alpha");
315
  // std::cout << var.get<1>() << std::endl;
316
  // var.set<2>(0.75);
317
  // std::cout << var.get<2>() << std::endl;
318
  //\endcode
319
  //
320
  // The result of course:
321
  //\code
322
  // 12
323
  // alpha
324
  // 0.75
325
  //\endcode
326 326
  template <int _num, typename _TypeMap>
... ...
@@ -333,6 +333,6 @@
333 333

	
334
    /// \brief Constructor
335
    ///
336
    /// This constructor initalizes to the default value of the \c type
337
    /// with 0 index.
334
    // \brief Constructor
335
    //
336
    // This constructor initalizes to the default value of the \c type
337
    // with 0 index.
338 338
    Variant() {
... ...
@@ -344,5 +344,5 @@
344 344

	
345
    /// \brief Copy constructor
346
    ///
347
    /// Copy constructor
345
    // \brief Copy constructor
346
    //
347
    // Copy constructor
348 348
    Variant(const Variant& variant) {
... ...
@@ -352,5 +352,5 @@
352 352

	
353
    /// \brief Assign operator
354
    ///
355
    /// Assign operator
353
    // \brief Assign operator
354
    //
355
    // Assign operator
356 356
    Variant& operator=(const Variant& variant) {
... ...
@@ -365,5 +365,5 @@
365 365

	
366
    /// \brief Destrcutor
367
    ///
368
    /// Destructor
366
    // \brief Destrcutor
367
    //
368
    // Destructor
369 369
    ~Variant() {
... ...
@@ -372,6 +372,6 @@
372 372

	
373
    /// \brief Set to the default value of the type with \c _idx index.
374
    ///
375
    /// This function sets the variant to the default value of the
376
    /// type with \c _idx index.
373
    // \brief Set to the default value of the type with \c _idx index.
374
    //
375
    // This function sets the variant to the default value of the
376
    // type with \c _idx index.
377 377
    template <int _idx>
... ...
@@ -385,6 +385,6 @@
385 385

	
386
    /// \brief Set to the given value of the type with \c _idx index.
387
    ///
388
    /// This function sets the variant to the given value of the type
389
    /// with \c _idx index.
386
    // \brief Set to the given value of the type with \c _idx index.
387
    //
388
    // This function sets the variant to the given value of the type
389
    // with \c _idx index.
390 390
    template <int _idx>
... ...
@@ -398,5 +398,5 @@
398 398

	
399
    /// \brief Gets the current value of the type with \c _idx index.
400
    ///
401
    /// Gets the current value of the type with \c _idx index.
399
    // \brief Gets the current value of the type with \c _idx index.
400
    //
401
    // Gets the current value of the type with \c _idx index.
402 402
    template <int _idx>
... ...
@@ -408,5 +408,5 @@
408 408

	
409
    /// \brief Gets the current value of the type with \c _idx index.
410
    ///
411
    /// Gets the current value of the type with \c _idx index.
409
    // \brief Gets the current value of the type with \c _idx index.
410
    //
411
    // Gets the current value of the type with \c _idx index.
412 412
    template <int _idx>
... ...
@@ -418,5 +418,5 @@
418 418

	
419
    /// \brief Returns the current state of the variant.
420
    ///
421
    /// Returns the current state of the variant.
419
    // \brief Returns the current state of the variant.
420
    //
421
    // Returns the current state of the variant.
422 422
    int state() const {
... ...
@@ -471,7 +471,7 @@
471 471

	
472
  /// \brief Helper class for Variant
473
  ///
474
  /// Helper class to define type mappings for Variant. This class
475
  /// converts the template parameters to be mappable by integer.
476
  /// \see Variant
472
  // \brief Helper class for Variant
473
  //
474
  // Helper class to define type mappings for Variant. This class
475
  // converts the template parameters to be mappable by integer.
476
  // \see Variant
477 477
  template <
0 comments (0 inline)