libDAI
var.h
Go to the documentation of this file.
1 /* This file is part of libDAI - http://www.libdai.org/
2  *
3  * Copyright (c) 2006-2011, The libDAI authors. All rights reserved.
4  *
5  * Use of this source code is governed by a BSD-style license that can be found in the LICENSE file.
6  */
7 
8 
11 
12 
13 #ifndef __defined_libdai_var_h
14 #define __defined_libdai_var_h
15 
16 
17 #include <iostream>
18 #include <dai/exceptions.h>
19 
20 
21 namespace dai {
22 
23 
25 
36 class Var {
37  private:
39  size_t _label;
40 
42  size_t _states;
43 
44  public:
46  Var() : _label(0), _states(0) {}
48  Var( size_t label, size_t states ) : _label(label), _states(states) {}
49 
51  size_t label() const { return _label; }
53  size_t& label() { return _label; }
54 
56  size_t states() const { return _states; }
58  size_t& states() { return _states; }
59 
61  bool operator< ( const Var& n ) const {
62 #ifdef DAI_DEBUG
63  if( _label == n._label )
64  DAI_ASSERT( _states == n._states );
65 #endif
66  return( _label < n._label );
67  }
68 
70  bool operator> ( const Var& n ) const {
71 #ifdef DAI_DEBUG
72  if( _label == n._label )
73  DAI_ASSERT( _states == n._states );
74 #endif
75  return( _label > n._label );
76  }
77 
79  bool operator<= ( const Var& n ) const {
80 #ifdef DAI_DEBUG
81  if( _label == n._label )
82  DAI_ASSERT( _states == n._states );
83 #endif
84  return( _label <= n._label );
85  }
86 
88  bool operator>= ( const Var& n ) const {
89 #ifdef DAI_DEBUG
90  if( _label == n._label )
91  DAI_ASSERT( _states == n._states );
92 #endif
93  return( _label >= n._label );
94  }
95 
97  bool operator!= ( const Var& n ) const {
98 #ifdef DAI_DEBUG
99  if( _label == n._label )
100  DAI_ASSERT( _states == n._states );
101 #endif
102  return( _label != n._label );
103  }
104 
106  bool operator== ( const Var& n ) const {
107 #ifdef DAI_DEBUG
108  if( _label == n._label )
109  DAI_ASSERT( _states == n._states );
110 #endif
111  return( _label == n._label );
112  }
113 
115  friend std::ostream& operator << ( std::ostream& os, const Var& n ) {
116  return( os << "x" << n.label() );
117  }
118 };
119 
120 
121 } // end of namespace dai
122 
123 
124 #endif