libDAI
include/dai/var.h
Go to the documentation of this file.
00001 /*  This file is part of libDAI - http://www.libdai.org/
00002  *
00003  *  Copyright (c) 2006-2011, The libDAI authors. All rights reserved.
00004  *
00005  *  Use of this source code is governed by a BSD-style license that can be found in the LICENSE file.
00006  */
00007 
00008 
00011 
00012 
00013 #ifndef __defined_libdai_var_h
00014 #define __defined_libdai_var_h
00015 
00016 
00017 #include <iostream>
00018 #include <dai/exceptions.h>
00019 
00020 
00021 namespace dai {
00022 
00023 
00025 
00036 class Var {
00037     private:
00039         size_t  _label;
00040 
00042         size_t  _states;
00043 
00044     public:
00046         Var() : _label(0), _states(0) {}
00048         Var( size_t label, size_t states ) : _label(label), _states(states) {}
00049 
00051         size_t label() const { return _label; }
00053         size_t& label() { return _label; }
00054 
00056         size_t states() const { return _states; }
00058         size_t& states() { return _states; }
00059 
00061         bool operator< ( const Var& n ) const { 
00062 #ifdef DAI_DEBUG
00063             if( _label == n._label )
00064                 DAI_ASSERT( _states == n._states );
00065 #endif
00066             return( _label < n._label );
00067         }
00068 
00070         bool operator> ( const Var& n ) const { 
00071 #ifdef DAI_DEBUG
00072             if( _label == n._label )
00073                 DAI_ASSERT( _states == n._states );
00074 #endif
00075             return( _label > n._label ); 
00076         }
00077 
00079         bool operator<= ( const Var& n ) const {
00080 #ifdef DAI_DEBUG
00081             if( _label == n._label )
00082                 DAI_ASSERT( _states == n._states );
00083 #endif
00084             return( _label <= n._label );
00085         }
00086 
00088         bool operator>= ( const Var& n ) const {
00089 #ifdef DAI_DEBUG
00090             if( _label == n._label )
00091                 DAI_ASSERT( _states == n._states );
00092 #endif
00093             return( _label >= n._label );
00094         }
00095 
00097         bool operator!= ( const Var& n ) const {
00098 #ifdef DAI_DEBUG
00099             if( _label == n._label )
00100                 DAI_ASSERT( _states == n._states );
00101 #endif
00102             return( _label != n._label );
00103         }
00104 
00106         bool operator== ( const Var& n ) const {
00107 #ifdef DAI_DEBUG
00108             if( _label == n._label )
00109                 DAI_ASSERT( _states == n._states );
00110 #endif
00111             return( _label == n._label );
00112         }
00113 
00115         friend std::ostream& operator << ( std::ostream& os, const Var& n ) {
00116             return( os << "x" << n.label() );
00117         }
00118 };
00119 
00120 
00121 } // end of namespace dai
00122 
00123 
00124 #endif