00001 // Basic Alltype implementation -*- C++ -*- 00002 00003 // $Id: basic_alltype.cc 681 2008-07-14 14:29:16Z mihaly $ 00004 // Copyright (C) 2001-2003 Hermann Schichl 00005 // 00006 // This file is part of the COCONUT API. This library 00007 // is free software; you can redistribute it and/or modify it under the 00008 // terms of the Library GNU General Public License as published by the 00009 // Free Software Foundation; either version 2, or (at your option) 00010 // any later version. 00011 00012 // This library is distributed in the hope that it will be useful, 00013 // but WITHOUT ANY WARRANTY; without even the implied warranty of 00014 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00015 // Library GNU General Public License for more details. 00016 00017 // As a special exception, you may use this file as part of a free software 00018 // library without restriction. Specifically, if other files instantiate 00019 // templates or use macros or inline functions from this file, or you compile 00020 // this file and link it with other files to produce an executable, this 00021 // file does not by itself cause the resulting executable to be covered by 00022 // the Library GNU General Public License. This exception does not however 00023 // invalidate any other reasons why the executable file might be covered by 00024 // the Library GNU General Public License. 00025 00028 #include <coconut_config.h> 00029 #include <basic_alltype.h> 00030 #include <print_seq.h> 00031 #include <print_matrix.h> 00032 00033 namespace coco { 00034 00036 00041 const char *basic_alltype::__basic_alltype_name[] = BASIC_ALLTYPE_NAMES; 00042 00043 const basic_alltype& basic_alltype_empty() 00044 { 00045 static basic_alltype __empty; 00046 return __empty; 00047 } 00048 00049 std::ostream& operator<<(std::ostream& os, const basic_alltype& b) 00050 { 00051 os << '{' << b.type_name(); 00052 if(b.contents_type() != ALLTYPE_EMPTY) 00053 os << " : "; 00054 switch(b.contents_type()) 00055 { 00056 case ALLTYPE_EMPTY: 00057 break; 00058 case ALLTYPE_INTERVAL: 00059 os << b.ni(); 00060 break; 00061 case ALLTYPE_DOUBLE: 00062 os << b.nd(); 00063 break; 00064 case ALLTYPE_UINT: 00065 os << b.nu(); 00066 break; 00067 case ALLTYPE_INT: 00068 os << b.nn(); 00069 break; 00070 case ALLTYPE_BOOL: 00071 os << b.nb(); 00072 break; 00073 case ALLTYPE_ALLOCED_S: 00074 os << b.s(); 00075 break; 00076 case ALLTYPE_ALLOCED_B: 00077 os << b.b(); 00078 break; 00079 case ALLTYPE_ALLOCED_N: 00080 os << b.n(); 00081 break; 00082 case ALLTYPE_ALLOCED_U: 00083 os << b.u(); 00084 break; 00085 case ALLTYPE_ALLOCED_D: 00086 os << b.d(); 00087 break; 00088 case ALLTYPE_ALLOCED_I: 00089 os << b.i(); 00090 break; 00091 case ALLTYPE_ALLOCED_C: 00092 os << b.sv(); 00093 break; 00094 case ALLTYPE_ALLOCED_M: 00095 os << b.m(); 00096 break; 00097 case ALLTYPE_ALLOCED_NM: 00098 os << b.nm(); 00099 break; 00100 case ALLTYPE_ALLOCED_IM: 00101 os << b.im(); 00102 break; 00103 case ALLTYPE_ALLOCED_SM: 00104 os << b.sm(); 00105 break; 00106 } 00107 os << '}'; 00108 return os; 00109 } 00110 00111 bool basic_alltype::operator==(const basic_alltype& __a) const 00112 { 00113 bool ret(false); 00114 if(contents_type() == __a.contents_type()) 00115 { 00116 switch(__cont_type) 00117 { 00118 case ALLTYPE_EMPTY: 00119 break; 00120 case ALLTYPE_INTERVAL: 00121 if(__c.ni == __a.__c.ni) ret = true; 00122 break; 00123 case ALLTYPE_DOUBLE: 00124 if(__c.nd == __a.__c.nd) ret = true; 00125 break; 00126 case ALLTYPE_UINT: 00127 if(__c.nu == __a.__c.nu) ret = true; 00128 break; 00129 case ALLTYPE_INT: 00130 if(__c.nn == __a.__c.nn) ret = true; 00131 break; 00132 case ALLTYPE_BOOL: 00133 if(__c.nb == __a.__c.nb) ret = true; 00134 break; 00135 case ALLTYPE_ALLOCED_S: 00136 if(__c.s == __a.__c.s) ret = true; 00137 break; 00138 case ALLTYPE_ALLOCED_B: 00139 if(__c.b == __a.__c.b) ret = true; 00140 break; 00141 case ALLTYPE_ALLOCED_N: 00142 if(__c.n == __a.__c.n) ret = true; 00143 break; 00144 case ALLTYPE_ALLOCED_U: 00145 if(__c.u == __a.__c.u) ret = true; 00146 break; 00147 case ALLTYPE_ALLOCED_D: 00148 if(__c.d == __a.__c.d) ret = true; 00149 break; 00150 case ALLTYPE_ALLOCED_I: 00151 if(__c.i == __a.__c.i) ret = true; 00152 break; 00153 case ALLTYPE_ALLOCED_C: 00154 if(__c.sv == __a.__c.sv) ret = true; 00155 break; 00156 case ALLTYPE_ALLOCED_M: 00157 if(__c.m == __a.__c.m) ret = true; 00158 break; 00159 case ALLTYPE_ALLOCED_NM: 00160 if(__c.nm == __a.__c.nm) ret = true; 00161 break; 00162 case ALLTYPE_ALLOCED_IM: 00163 if(__c.im == __a.__c.im) ret = true; 00164 break; 00165 case ALLTYPE_ALLOCED_SM: 00166 if(__c.sm == __a.__c.sm) ret = true; 00167 break; 00168 } 00169 } 00170 return ret; 00171 } 00172 00173 bool basic_alltype::operator!=(const basic_alltype& b) const 00174 { 00175 return !(*this == b); 00176 } 00177 00178 } // namespace coco