00001
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039 #include "emobject.h"
00040 #include <cmath>
00041 #ifdef WIN32
00042 #define M_PI 3.14159265358979323846f
00043 #endif
00044
00045 #include <algorithm>
00046
00047
00048 #include "util.h"
00049
00050 using namespace EMAN;
00051
00052 #include <iostream>
00053 using std::cout;
00054 using std::cerr;
00055 using std::endl;
00056
00057 const float EMConsts::I2G = (float) (4.0 / (M_PI*M_PI));
00058 const float EMConsts::I3G = (float) (6.4 / (M_PI*M_PI));
00059 const float EMConsts::I4G = (float) (8.8 / (M_PI*M_PI));
00060 const float EMConsts::I5G = (float) (10.4 / (M_PI*M_PI));
00061
00062 const double EMConsts::pi = 3.141592653589793238462643383279502884197169399;
00063 const double EMConsts::deg2rad = pi/180.0;
00064 const double EMConsts::rad2deg = 180.0/pi;
00065
00066
00067 #include <sstream>
00068 using std::stringstream;
00069
00070 #include "transform.h"
00071 #include "ctf.h"
00072
00073
00074 map< EMObject::ObjectType, string> EMObject::type_registry = init();;
00075
00076
00077 map< EMObject::ObjectType, string> EMObject::init()
00078 {
00079 map< EMObject::ObjectType, string> mymap;
00080 static bool first_construction = true;
00081 if ( first_construction )
00082 {
00083
00084 mymap[BOOL] = "BOOL";
00085 mymap[INT] = "INT";
00086 mymap[UNSIGNEDINT] = "UNSIGNEDINT";
00087 mymap[FLOAT] = "FLOAT";
00088 mymap[DOUBLE] = "DOUBLE";
00089 mymap[STRING] = "STRING";
00090 mymap[EMDATA] = "EMDATA";
00091 mymap[XYDATA] = "XYDATA";
00092 mymap[INTARRAY] = "INTARRAY";
00093 mymap[FLOATARRAY] = "FLOATARRAY";
00094 mymap[STRINGARRAY] = "STRINGARRAY";
00095 mymap[TRANSFORM] = "TRANFORM";
00096 mymap[CTF] = "CTF";
00097 mymap[FLOAT_POINTER] = "FLOAT_POINTER";
00098 mymap[INT_POINTER] = "INT_POINTER";
00099 mymap[UNKNOWN] = "UNKNOWN";
00100 mymap[VOID_POINTER] = "VOID_POINTER";
00101 first_construction = false;
00102 }
00103
00104 return mymap;
00105 }
00106
00107
00108
00109 void EMObject::printInfo() const
00110 {
00111 cout << "The address of my type is " << &type << endl;
00112 cout << " Now printing the enumerated values in type_registry " << endl;
00113 for( map< ObjectType, string>::const_iterator it = type_registry.begin(); it != type_registry.end(); ++it )
00114 {
00115 cout << it->first << " " << it->second << endl;
00116 }
00117 cout << "My type is " << to_str(type) << " and its enumerated value is " << type << endl;
00118 cout << "The address of the static type registry is " << &type_registry <<", it should be same for all EMObjects" << endl;
00119 }
00120
00121 EMObject::~EMObject() {}
00122
00123 EMObject::EMObject() :
00124 d(0), type(UNKNOWN)
00125 {}
00126
00127 EMObject::EMObject(bool boolean) :
00128 b(boolean), type(BOOL)
00129 {}
00130
00131 EMObject::EMObject(int num) :
00132 n(num), type(INT)
00133 {}
00134
00135 EMObject::EMObject(unsigned int num) :
00136 ui(num), type(UNSIGNEDINT)
00137 {}
00138
00139 EMObject::EMObject(float ff) :
00140 type(FLOAT)
00141 {
00142 if(Util::goodf(&ff)) {
00143 f = ff;
00144 }
00145 else{
00146 f = 0.0f;
00147 }
00148 }
00149
00150 EMObject::EMObject(double dd) :
00151 type(DOUBLE)
00152 {
00153 if(Util::goodf(&dd)) {
00154 d = dd;
00155 }
00156 else{
00157 d = 0.0;
00158 }
00159 }
00160
00161 EMObject::EMObject(const char *s) :
00162 str(s), type(STRING)
00163 {}
00164
00165 EMObject::EMObject(const string & s) :
00166 str(s), type(STRING)
00167 {}
00168
00169 EMObject::EMObject(float *f) :
00170 fp(f), type(FLOAT_POINTER)
00171 {}
00172
00173 EMObject::EMObject(int *i) :
00174 ip(i), type(INT_POINTER)
00175 {}
00176
00177 EMObject::EMObject(void *v) :
00178 vp(v), type(VOID_POINTER)
00179 {}
00180
00181 EMObject::EMObject(EMData * em) :
00182 emdata(em), type(EMDATA)
00183 {}
00184
00185 EMObject::EMObject(XYData * xy) :
00186 xydata(xy), type(XYDATA)
00187 {}
00188
00189 EMObject::EMObject(Transform* t) :
00190 farray(t->get_matrix()), type(TRANSFORM)
00191 {}
00192
00193 EMObject::EMObject(Ctf * ctf) :
00194 str(ctf->to_string()), type(CTF)
00195 {}
00196
00197 EMObject::EMObject(const vector< int >& v ) :
00198 iarray(v), type(INTARRAY)
00199 {}
00200
00201 EMObject::EMObject(const vector < float >&v) :
00202 farray(v), type(FLOATARRAY)
00203 {}
00204
00205 EMObject:: EMObject(const vector <string>& sarray) :
00206 strarray(sarray), type(STRINGARRAY)
00207 {}
00208
00209 EMObject::operator bool () const
00210 {
00211 if (type == BOOL) {
00212 return b;
00213 }
00214 else if (type == INT) {
00215 return n != 0;
00216 }
00217 else if (type == UNSIGNEDINT) {
00218 return ui != 0;
00219 }
00220 else if (type == FLOAT) {
00221 return f != 0;
00222 }
00223 else if (type == DOUBLE) {
00224 return d != 0;
00225 }
00226 else if (type == EMDATA) {
00227 return emdata != 0;
00228 }
00229 else if (type == XYDATA) {
00230 return xydata != 0;
00231 }
00232 else if (type == FLOAT_POINTER) {
00233 return fp != 0;
00234 }
00235 else if (type == INT_POINTER) {
00236 return ip != 0;
00237 }
00238 else if (type == VOID_POINTER) {
00239 return vp != 0;
00240 }
00241
00242
00243
00244
00245 else {
00246 if (type != UNKNOWN) {
00247 throw TypeException("Cannot convert to bool this data type ",
00248 get_object_type_name(type));
00249 }
00250 }
00251 return 0;
00252 }
00253
00254 EMObject::operator int () const
00255 {
00256 if (type == INT) {
00257 return n;
00258 }
00259 else if (type == UNSIGNEDINT) {
00260 return (int) ui;
00261 }
00262 else if (type == FLOAT) {
00263 return (int) f;
00264 }
00265 else if (type == DOUBLE) {
00266 return (int) d;
00267 }
00268 else if (type == BOOL) {
00269 return b?1:0;
00270 }
00271 else {
00272 if (type != UNKNOWN) {
00273 throw TypeException("Cannot convert to int this data type ",
00274 get_object_type_name(type));
00275 }
00276 }
00277 return 0;
00278 }
00279
00280 EMObject::operator unsigned int () const
00281 {
00282 if (type == UNSIGNEDINT) {
00283 return (unsigned int) ui;
00284 }
00285 else {
00286 if (type != UNKNOWN) {
00287 throw TypeException("Cannot convert to int this data type ",
00288 get_object_type_name(type));
00289 }
00290 }
00291 return 0;
00292 }
00293
00294 EMObject::operator float () const
00295 {
00296 if (type == BOOL) {
00297 return b?1.0f:0.0f;
00298 }
00299 else if (type == FLOAT) {
00300 return f;
00301 }
00302 else if (type == INT) {
00303 return (float) n;
00304 }
00305 else if (type == UNSIGNEDINT) {
00306 return (float) ui;
00307 }
00308 else if (type == DOUBLE) {
00309 return (float) d;
00310 }
00311 else {
00312 if (type != UNKNOWN) {
00313 throw TypeException("Cannot convert to float from this data type",
00314 get_object_type_name(type));
00315 }
00316 }
00317
00318 return 0;
00319 }
00320
00321 EMObject::operator double () const
00322 {
00323 if (type == BOOL) {
00324 return b?1.0:0.0;
00325 }
00326 else if (type == DOUBLE) {
00327 return d;
00328 }
00329 else if (type == INT) {
00330 return (double) n;
00331 }
00332 else if (type == UNSIGNEDINT) {
00333 return (double) ui;
00334 }
00335 else if (type == FLOAT) {
00336 return (double) f;
00337 }
00338 else {
00339 if (type != UNKNOWN) {
00340 throw TypeException("Cannot convert to double from this data type",
00341 get_object_type_name(type));
00342 }
00343 }
00344 return 0;
00345 }
00346
00347 EMObject::operator int * () const
00348 {
00349 if (type != INT_POINTER)
00350 {
00351 if (type != UNKNOWN)
00352 throw TypeException("Cannot convert to float pointer from this data type",
00353 get_object_type_name(type));
00354
00355 return 0;
00356 }
00357
00358 return ip;
00359 }
00360
00361
00362 EMObject::operator float * () const
00363 {
00364 if (type != FLOAT_POINTER)
00365 {
00366 if (type != UNKNOWN)
00367 throw TypeException("Cannot convert to float pointer from this data type",
00368 get_object_type_name(type));
00369
00370 return 0;
00371 }
00372
00373 return fp;
00374 }
00375
00376
00377 EMObject::operator void * () const
00378 {
00379 if (type == VOID_POINTER) return vp;
00380 else if (type == FLOAT_POINTER) return (void *)fp;
00381 else if (type == INT_POINTER) return (void *)ip;
00382 else if (type == EMDATA) return (void *) emdata;
00383 else if (type == XYDATA) return (void *) xydata;
00384
00385 else throw TypeException("Cannot convert to void pointer from this data type", get_object_type_name(type));
00386 }
00387
00388 EMObject::operator const char * () const
00389 {
00390 if (type != STRING && type != CTF) {
00391 stringstream ss;
00392 string return_string;
00393 if ( type == INT )
00394 {
00395 ss << n;
00396 ss >> return_string;
00397 return return_string.c_str();
00398 }
00399 if ( type == UNSIGNEDINT )
00400 {
00401 ss << ui;
00402 ss >> return_string;
00403 return return_string.c_str();
00404 }
00405 else
00406 if ( type == FLOAT )
00407 {
00408 ss << f;
00409 ss >> return_string;
00410 return return_string.c_str();
00411 }
00412 else
00413 if ( type == DOUBLE )
00414 {
00415 ss << d;
00416 ss >> return_string;
00417 return return_string.c_str();
00418 }
00419 else if (type != UNKNOWN) {
00420 throw TypeException("Cannot convert to string from this data type",
00421 get_object_type_name(type));
00422 }
00423
00424 return "";
00425 }
00426 return str.c_str();
00427 }
00428
00429 EMObject::operator EMData * () const
00430 {
00431 if (type != EMDATA) {
00432 if (type != UNKNOWN) {
00433 throw TypeException("Cannot convert to EMData* from this data type",
00434 get_object_type_name(type));
00435 }
00436 return 0;
00437 }
00438 return emdata;
00439 }
00440
00441 EMObject::operator XYData * () const
00442 {
00443 if (type != XYDATA) {
00444 if (type != UNKNOWN) {
00445 throw TypeException("Cannot convert to XYData* from this data type",
00446 get_object_type_name(type));
00447 }
00448 return 0;
00449 }
00450 return xydata;
00451 }
00452
00453 EMObject::operator Transform* () const
00454 {
00455 if(type != TRANSFORM) {
00456 if(type != UNKNOWN) {
00457 throw TypeException("Cannot convert to TRANSFORM* from this data type",
00458 get_object_type_name(type));
00459 }
00460 }
00461 Transform * transform = new Transform();
00462 transform->set_matrix(farray);
00463 return transform;
00464 }
00465
00466 EMObject::operator Ctf* () const
00467 {
00468
00469
00470
00471
00472
00473
00474 Ctf * ctf = 0;
00475 if(str[0] == 'O') {
00476 ctf = new EMAN1Ctf();
00477 ctf->from_string(str);
00478 }
00479 else if(str[0] == 'E') {
00480 ctf = new EMAN2Ctf();
00481 ctf->from_string(str);
00482 }
00483 return ctf;
00484 }
00485
00486 EMObject::operator vector<int>() const
00487 {
00488 if( type != INTARRAY )
00489 {
00490 if( type != UNKNOWN ) {
00491 throw TypeException("Cannot convert to vector<int> from this data type", get_object_type_name(type) );
00492 }
00493 return vector<int>();
00494 }
00495 return iarray;
00496 }
00497
00498 EMObject::operator vector < float > () const
00499 {
00500 if (type != FLOATARRAY) {
00501 if (type != UNKNOWN) {
00502 throw TypeException("Cannot convert to vector<float> from this data type",
00503 get_object_type_name(type));
00504 }
00505 return vector < float >();
00506 }
00507 return farray;
00508 }
00509
00510 EMObject::operator vector<string> () const
00511 {
00512 if (type != STRINGARRAY) {
00513 if (type != UNKNOWN) {
00514 throw TypeException("Cannot convert to vector<string> from this data type",
00515 get_object_type_name(type));
00516 }
00517 return vector<string>();
00518 }
00519 return strarray;
00520 }
00521
00522 bool EMObject::is_null() const
00523 {
00524 return (type == UNKNOWN);
00525 }
00526
00527 string EMObject::to_str() const
00528 {
00529 return to_str(type);
00530 }
00531
00532 string EMObject::to_str(ObjectType argtype) const
00533 {
00534 if (argtype == STRING) {
00535 return str;
00536 }
00537 else {
00538 char tmp_str[32];
00539 if (argtype == BOOL) {
00540 if (b)
00541 sprintf(tmp_str, "true");
00542 else
00543 sprintf(tmp_str, "false");
00544 }
00545 else if (argtype == INT) {
00546 sprintf(tmp_str, "%d", n);
00547 }
00548 else if (argtype == UNSIGNEDINT) {
00549 sprintf(tmp_str, "%d", ui);
00550 }
00551 else if (argtype == FLOAT) {
00552 sprintf(tmp_str, "%f", f);
00553 }
00554 else if (argtype == DOUBLE) {
00555 sprintf(tmp_str, "%f", d);
00556 }
00557 else if (argtype == EMDATA) {
00558 sprintf(tmp_str, "EMDATA");
00559 }
00560 else if (argtype == FLOAT_POINTER) {
00561 sprintf(tmp_str, "FLOAT_POINTER");
00562 }
00563 else if (argtype == INT) {
00564 sprintf(tmp_str, "INT_POINTER");
00565 }
00566 else if (argtype == VOID_POINTER) {
00567 sprintf(tmp_str, "VOID_POINTER");
00568 }
00569 else if (argtype == XYDATA) {
00570 sprintf(tmp_str, "XYDATA");
00571 }
00572 else if (argtype == INTARRAY) {
00573 sprintf(tmp_str, "INTARRAY");
00574 }
00575 else if (argtype == FLOATARRAY) {
00576 sprintf(tmp_str, "FLOATARRAY");
00577 }
00578 else if (argtype == STRINGARRAY) {
00579 sprintf(tmp_str, "STRINGARRAY");
00580 }
00581 else if (argtype == TRANSFORM) {
00582 sprintf(tmp_str, "TRANSFORMD");
00583 }
00584 else if (argtype == CTF) {
00585 sprintf(tmp_str, "CTF");
00586 }
00587 else if (argtype == UNKNOWN) {
00588 sprintf(tmp_str, "UNKNOWN");
00589 }
00590 else {
00591 LOGERR("No such EMObject defined");
00592 throw NotExistingObjectException("EMObject", "unknown type");
00593 }
00594 return string(tmp_str);
00595 }
00596 }
00597
00598 string EMObject::get_object_type_name(ObjectType t)
00599 {
00600 #ifdef _WIN32
00601 if (t == BOOL) {
00602 return "BOOL";
00603 }else
00604 if ( t == INT){
00605 return "INT";
00606 }else
00607 if ( t == UNSIGNEDINT){
00608 return "UNSIGNEDINT";
00609 } else
00610 if ( t == FLOAT){
00611 return "FLOAT";
00612 } else
00613 if ( t == DOUBLE){
00614 return "DOUBLE";
00615 }else
00616 if ( t == STRING){
00617 return "STRING";
00618 }else
00619 if ( t == EMDATA){
00620 return "EMDATA";
00621 }
00622 else
00623 if ( t == XYDATA){
00624 return "XYDATA";
00625 }else
00626 if ( t == INTARRAY){
00627 return "INTARRAY";
00628 }else
00629 if ( t == FLOATARRAY){
00630 return "FLOATARRAY";
00631 } else
00632 if ( t == STRINGARRAY){
00633 return "STRINGARRAY";
00634 }else
00635 if ( t == TRANSFORM){
00636 return "TRANSFORM";
00637 }else
00638 if ( t == CTF){
00639 return "CTF";
00640 }else
00641 if ( t == FLOAT_POINTER){
00642 return "FLOAT_POINTER";
00643 }else
00644 if ( t == INT_POINTER){
00645 return "INT_POINTER";
00646 }else
00647 if ( t == UNKNOWN){
00648 return "UNKNOWN";
00649 } else
00650 if ( t == VOID_POINTER){
00651 return "VOID_POINTER";
00652 }
00653 else {
00654 LOGERR("No such EMObject defined");
00655 throw NotExistingObjectException("EMObject", "unknown type");
00656 }
00657
00658 #else
00659
00660 if ( type_registry.find(t) != type_registry.end() )
00661 return type_registry[t];
00662 else
00663 LOGERR("No such EMObject defined");
00664 throw NotExistingObjectException("EMObject", "unknown type");
00665 #endif //_WIN32
00666 }
00667
00668 bool EMAN::operator==(const EMObject &e1, const EMObject & e2)
00669 {
00670
00671 if (e1.type != e2.type) {
00672 return false;
00673 }
00674
00675 switch (e1.type) {
00676 case EMObject::BOOL:
00677 return (e1.b == e2.b);
00678 break;
00679 case EMObject::INT:
00680 return (e1.n == e2.n);
00681 break;
00682 case EMObject::UNSIGNEDINT:
00683 return (e1.ui == e2.ui);
00684 break;
00685 case EMObject::FLOAT:
00686 return (e1.f == e2.f);
00687 break;
00688 case EMObject::DOUBLE:
00689 return (e1.d == e2.d);
00690 break;
00691 case EMObject::CTF:
00692 case EMObject::STRING:
00693 return (e1.str == e2.str);
00694 break;
00695 case EMObject::FLOAT_POINTER:
00696 return (e1.fp == e2.fp);
00697 break;
00698 case EMObject::INT_POINTER:
00699 return (e1.ip == e2.ip);
00700 break;
00701 case EMObject::VOID_POINTER:
00702 return (e1.vp == e2.vp);
00703 break;
00704 case EMObject::EMDATA:
00705 return (e1.emdata == e2.emdata);
00706 break;
00707 case EMObject::XYDATA:
00708 return (e1.xydata == e2.xydata);
00709 break;
00710 case EMObject::TRANSFORM:
00711 case EMObject::FLOATARRAY:
00712 if (e1.farray.size() == e2.farray.size()) {
00713 for (size_t i = 0; i < e1.farray.size(); i++) {
00714 if (e1.farray[i] != e2.farray[i]) {
00715 return false;
00716 }
00717 }
00718 return true;
00719 }
00720 else {
00721 return false;
00722 }
00723 break;
00724 case EMObject::INTARRAY:
00725 if (e1.iarray.size() == e2.iarray.size()) {
00726 for (size_t i = 0; i < e1.iarray.size(); i++) {
00727 if (e1.iarray[i] != e2.iarray[i]) {
00728 return false;
00729 }
00730 }
00731 return true;
00732 }
00733 break;
00734 case EMObject::STRINGARRAY:
00735 if (e1.strarray.size() == e2.strarray.size()) {
00736 for (size_t i = 0; i < e1.strarray.size(); i++) {
00737 if (e1.strarray[i] != e2.strarray[i]) {
00738 return false;
00739 }
00740 }
00741 return true;
00742 }
00743 else {
00744 return false;
00745 }
00746 break;
00747 case EMObject::UNKNOWN:
00748
00749
00750 return (e1.type == e2.type);
00751 break;
00752 default:
00753 return false;
00754 break;
00755 }
00756 return false;
00757 }
00758
00759 bool EMAN::operator!=(const EMObject &e1, const EMObject & e2)
00760 {
00761 return !(e1 == e2);
00762 }
00763
00764
00765 EMObject::EMObject(const EMObject& that)
00766 {
00767
00768 *this = that;
00769 }
00770
00771
00772
00773
00774
00775 EMObject& EMObject::operator=( const EMObject& that )
00776 {
00777
00778
00779
00780
00781
00782 {
00783
00784
00785 type = that.type;
00786
00787
00788
00789
00790 switch (type)
00791 {
00792 case BOOL:
00793 b = that.b;
00794 break;
00795 case INT:
00796 n = that.n;
00797 break;
00798 case UNSIGNEDINT:
00799 ui = that.ui;
00800 break;
00801 case FLOAT:
00802 f = that.f;
00803 break;
00804 case DOUBLE:
00805 d = that.d;
00806 break;
00807 case CTF:
00808 case STRING:
00809 str = that.str;
00810 break;
00811 case FLOAT_POINTER:
00812
00813 fp = that.fp;
00814 break;
00815 case INT_POINTER:
00816
00817 ip = that.ip;
00818 break;
00819 case VOID_POINTER:
00820
00821 vp = that.vp;
00822 break;
00823 case EMDATA:
00824
00825 emdata = that.emdata;
00826 break;
00827 case XYDATA:
00828
00829 xydata = that.xydata;
00830 break;
00831 case TRANSFORM:
00832 case FLOATARRAY:
00833 farray = that.farray;
00834 break;
00835 case INTARRAY:
00836 iarray = that.iarray;
00837 break;
00838 case STRINGARRAY:
00839 strarray = that.strarray;
00840 break;
00841 case UNKNOWN:
00842
00843
00844
00845
00846 break;
00847 default:
00848 LOGERR("No such EMObject defined");
00849 throw NotExistingObjectException("EMObject", "unknown type");
00850 break;
00851 }
00852 }
00853
00854
00855
00856
00857
00858
00859 return *this;
00860 }
00861
00862
00863
00864 void TypeDict::dump()
00865 {
00866 map < string, string >::iterator p;
00867 for (p = type_dict.begin(); p != type_dict.end(); p++) {
00868 printf("\t%s %s %s\n",
00869 p->first.c_str(), p->second.c_str(), desc_dict[p->first].c_str());
00870 }
00871 }
00872
00873
00874
00875 Dict::Dict(const Dict& that)
00876 {
00877 *this = that;
00878 }
00879
00880 Dict& Dict::operator=(const Dict& that)
00881 {
00882 if ( this != &that )
00883 {
00884 dict.clear();
00885 copy(that.begin(), that.end(), inserter(dict, dict.begin()));
00886
00887
00888 }
00889 else
00890 {
00891 cerr << "Warning - attempted to assign a Dict object to itself. No action taken" << endl;
00892 }
00893
00894 return *this;
00895 }
00896
00897 bool EMAN::operator==(const Dict& d1, const Dict& d2)
00898 {
00899
00900 return (d1.dict == d2.dict);
00901 }
00902
00903 bool EMAN::operator!=(const Dict& d1, const Dict& d2)
00904 {
00905 return !(d1 == d2);
00906 }
00907
00908
00909
00910
00911
00912
00913
00914 Dict::iterator Dict::begin( void )
00915 {
00916 return iterator( dict.begin() );
00917 }
00918
00919 Dict::const_iterator Dict::begin( void ) const
00920 {
00921 return const_iterator( (map < string, EMObject >::const_iterator) dict.begin() );
00922 }
00923
00924
00925 Dict::iterator Dict::find( const string& key )
00926 {
00927 return iterator( dict.find(key) );
00928 }
00929
00930 Dict::iterator Dict::end( void )
00931 {
00932 return iterator( dict.end() );
00933 }
00934
00935 Dict::const_iterator Dict::end( void ) const
00936 {
00937 return const_iterator( (map < string, EMObject >::const_iterator)dict.end() );
00938 }
00939
00940 Dict::const_iterator Dict::find( const string& key ) const
00941 {
00942 return const_iterator( (map < string, EMObject >::const_iterator)dict.find(key) );
00943 }
00944
00945
00946
00947
00948 Dict::iterator::iterator( map< string, EMObject >::iterator parent_it ) :
00949 map< string, EMObject >::iterator( parent_it )
00950 {
00951 }
00952
00953
00954 Dict::iterator::iterator( const iterator& that ) :
00955 map < string, EMObject >::iterator( that )
00956 {
00957 }
00958
00959
00960 Dict::iterator& Dict::iterator::operator=( const iterator& that )
00961 {
00962 if( this != &that )
00963 {
00964 map < string, EMObject >::iterator::operator=( that );
00965 }
00966 return *this;
00967 }
00968
00969
00970
00971
00972
00973 Dict::const_iterator::const_iterator( const map < string, EMObject >::const_iterator parent_it ) :
00974 map< string, EMObject >::const_iterator( parent_it )
00975 {
00976 }
00977
00978 Dict::const_iterator::const_iterator( const Dict::iterator& it ) :
00979 map< string, EMObject >::const_iterator(it)
00980 {
00981 }
00982
00983 Dict::const_iterator::const_iterator( const const_iterator& it ) :
00984 map< string, EMObject >::const_iterator(it)
00985 {
00986 }
00987
00988 Dict::const_iterator& Dict::const_iterator::operator=( const const_iterator& that )
00989 {
00990 if( this != &that )
00991 {
00992 map < string, EMObject >::const_iterator::operator=( that );
00993 }
00994 return *this;
00995 }
00996
00997 EMObject Dict::get_ci(const string & key) const
00998 {
00999 string lower_key = Util::str_to_lower(key);
01000
01001 for (map < string, EMObject >::const_iterator it = dict.begin(); it != dict.end(); ++it ) {
01002 string lower = Util::str_to_lower(it->first);
01003 if (lower == lower_key) return it->second;
01004 }
01005
01006 throw NotExistingObjectException("EMObject", "Nonexisting key (" + key + ") in Dict");
01007 }
01008
01009 bool Dict::has_key_ci(const string & key) const
01010 {
01011 string lower_key = Util::str_to_lower(key);
01012
01013 for (map < string, EMObject >::const_iterator it = dict.begin(); it != dict.end(); ++it ) {
01014 string lower = Util::str_to_lower(it->first);
01015 if (lower == lower_key) return true;
01016 }
01017 return false;
01018 }