Main Page | Class Hierarchy | Class List | File List | Class Members

Types.h

00001 // Types.h -- Definitions of some useful types.
00002 
00003 /*
00004  * Copyright (C) 1997, 1998 Tudor Hulubei <tudor@hulubei.net>.
00005  *
00006  * This library is free software; you can redistribute it and/or modify
00007  * it under the terms of the GNU Lesser General Public License as
00008  * published by the Free Software Foundation; either version 2, or (at
00009  * your option) any later version.
00010  *
00011  * This library is distributed in the hope that it will be useful,
00012  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00013  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00014  * GNU Lesser General Public License for more details.
00015  *
00016  * You should have received a copy of the GNU Lesser General Public
00017  * License along with this library; if not, write to the Free Software
00018  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA,
00019  * 02111-1307, USA.
00020  */
00021 
00022 /*
00023  * NOTE: This is an interal header file.
00024  * You should not attempt to use it directly.
00025  */
00026 
00027 // $Id: Types_8h-source.html,v 1.1 2005/05/25 12:37:18 tudor Exp $
00028 
00029 #ifndef _CSP_KERNEL_Types_H
00030 #define _CSP_KERNEL_Types_H
00031 
00032 
00033 
00034 CSP_NAMESPACE_BEGIN(csp);
00035 
00036 class CSP_API Value;
00037 class CSP_API Variable;
00038 class CSP_API Constraint;
00039 class CSP_API Solution;
00040 
00042 template<class T> struct hash_id :
00043     public unary_function<T, size_t>
00044 {
00045     size_t operator()(const T& key) const
00046     {
00047         return key->id();
00048     }
00049 };
00050 
00052 template<class T> struct equal_id :
00053     public binary_function<T, T, bool>
00054 {
00055     bool operator()(const T& x, const T& y) const
00056     {
00057         return x->id() == y->id();
00058     }
00059 };
00060 
00062 template<class T> struct less_id :
00063     public binary_function<T, T, bool>
00064 {
00065     bool operator()(const T& x, const T& y) const
00066     {
00067         return x->id() < y->id();
00068     }
00069 };
00070 
00071 CSP_NAMESPACE_END(csp);
00072 
00073 
00074 
00075 #if defined(__GNUG__)
00076 namespace __gnu_cxx
00077 {
00078     template<> struct hash<const csp::Value*> {
00079         size_t operator()(const csp::Value* value) const {
00080             return reinterpret_cast<size_t>(value); }
00081     };
00082 
00083     template<> struct hash<const csp::Variable*> {
00084         size_t operator()(const csp::Variable* variable) const {
00085             return reinterpret_cast<size_t>(variable); }
00086     };
00087 
00088     template<> struct hash<const csp::Constraint*> {
00089         size_t operator()(const csp::Constraint* constraint) const {
00090             return reinterpret_cast<size_t>(constraint); }
00091     };
00092 
00093     template<> struct hash<const csp::Solution*> {
00094         size_t operator()(const csp::Solution* solution) const {
00095             return reinterpret_cast<size_t>(solution); }
00096     };
00097 
00098     template<> struct hash<csp::Value*> {
00099         size_t operator()(const csp::Value* value) const {
00100             return reinterpret_cast<size_t>(value); }
00101     };
00102 
00103     template<> struct hash<csp::Variable*> {
00104         size_t operator()(const csp::Variable* variable) const {
00105             return reinterpret_cast<size_t>(variable); }
00106     };
00107 
00108     template<> struct hash<csp::Constraint*> {
00109         size_t operator()(const csp::Constraint* constraint) const {
00110             return reinterpret_cast<size_t>(constraint); }
00111     };
00112 
00113     template<> struct hash<csp::Solution*> {
00114         size_t operator()(const csp::Solution* solution) const {
00115             return reinterpret_cast<size_t>(solution); }
00116     };
00117 }
00118 #endif // __GNUG__
00119 
00120 
00121 CSP_NAMESPACE_BEGIN(csp);
00122 
00123 /*
00124  * FIXME: These ids should be longlong, but the GNU STDC++ library
00125  * doesn't support longlong as a hash key yet.  Change this into
00126  * longlong as soon as that support is added.
00127  */
00128 
00133 typedef int id_t;
00134 
00139 const id_t NoId = -1;
00140 
00141 #define ID_MAX INT_MAX
00142 #define ID_MIN INT_MIN
00143 
00144 
00145 class CSP_API Variable;
00146 class CSP_API Constraint;
00147 
00148 
00149 #if defined(__GNUG__)
00150 
00151     template<class T> struct hash_ptr :
00152         public unary_function<T, size_t> {
00153         size_t operator()(const T key) const {
00154             return reinterpret_cast<size_t>(key);
00155         }
00156     };
00157 
00159     template<class T> struct equal_ptr :
00160         public binary_function<T, T, bool> {
00161         bool operator()(const T x, const T y) const {
00162             return x == y;
00163         }
00164     };
00165 #endif // __GNUG__
00166 
00167 
00169 typedef list<Variable*> vlist_type;
00170 
00172 typedef vlist_type::iterator vlist_iterator;
00173 
00175 typedef vlist_type::const_iterator vlist_const_iterator;
00176 
00177 
00179 typedef list<Constraint*> clist_type;
00180 
00182 typedef clist_type::iterator clist_iterator;
00183 
00185 typedef clist_type::const_iterator clist_const_iterator;
00186 
00187 
00189 #if defined(__GNUG__)
00190 typedef hash_set<
00191     csp::Variable*,
00192     csp::hash_id<csp::Variable*>,
00193     csp::equal_id<csp::Variable*> > vhash_type;
00194 #elif defined(_MSC_VER)
00195 typedef hash_set<
00196     csp::Variable*,
00197     hash_compare<
00198         csp::Variable*,
00199         csp::less_id<csp::Variable*> > > vhash_type;
00200 #endif
00201 
00203 typedef vhash_type::iterator vhash_iterator;
00204 
00206 typedef vhash_type::const_iterator vhash_const_iterator;
00207 
00208 
00210 #if defined(__GNUG__)
00211 typedef hash_set<
00212     csp::Constraint*,
00213     csp::hash_id<csp::Constraint*>,
00214     csp::equal_id<csp::Constraint*> > chash_type;
00215 #elif defined(_MSC_VER)
00216 typedef hash_set<
00217     csp::Constraint*,
00218     hash_compare<
00219         csp::Constraint*,
00220         csp::less_id<csp::Constraint*> > > chash_type;
00221 #endif
00222 
00224 typedef chash_type::iterator chash_iterator;
00225 
00227 typedef chash_type::const_iterator chash_const_iterator;
00228 
00229 
00231 #if defined(__GNUG__)
00232 typedef hash_set<
00233     csp::Solution*,
00234     csp::hash_id<csp::Solution*>,
00235     csp::equal_id<csp::Solution*> > shash_type;
00236 #elif defined(_MSC_VER)
00237 typedef hash_set<
00238     csp::Solution*,
00239     hash_compare<
00240         csp::Solution*,
00241         csp::less_id<csp::Solution*> > > shash_type;
00242 #endif
00243 
00245 typedef shash_type::iterator shash_iterator;
00246 
00248 typedef shash_type::const_iterator shash_const_iterator;
00249 
00250 
00251 CSP_NAMESPACE_END(csp);
00252 
00253 
00254 #endif // _CSP_KERNEL_Types_H
00255 
00256 // Local Variables:
00257 // mode: C++
00258 // End:

Generated on Wed May 25 12:21:15 2005 for csp.kdevelop by  doxygen 1.3.9.1