#include <emobject.h>

Public Types | |
| enum | ObjectType { UNKNOWN, BOOL, UNSIGNEDINT, INT, FLOAT, DOUBLE, STRING, EMDATA, XYDATA, INTARRAY, FLOATARRAY, STRINGARRAY, TRANSFORM, CTF, FLOAT_POINTER, INT_POINTER, VOID_POINTER } |
Public Member Functions | |
| EMObject () | |
| Constructors for each type More types could be added, but all of the accompanying functions would have to be altered to ensure correct functioning. | |
| EMObject (bool boolean) | |
| EMObject (int num) | |
| EMObject (unsigned int num) | |
| EMObject (float ff) | |
| EMObject (double dd) | |
| EMObject (const char *s) | |
| EMObject (const string &s) | |
| EMObject (float *fp) | |
| EMObject (int *ip) | |
| EMObject (void *vp) | |
| EMObject (EMData *em) | |
| EMObject (XYData *xy) | |
| EMObject (Transform *t) | |
| EMObject (Ctf *ctf) | |
| EMObject (const vector< int > &v) | |
| EMObject (const vector< float > &v) | |
| EMObject (const vector< string > &sarray) | |
| EMObject (const EMObject &that) | |
| Copy constructor. | |
| EMObject & | operator= (const EMObject &that) |
| Assigment operator copies pointer locations (emdata, xydata, transform3d) - does not take ownership deep copies all non pointer objects. | |
| ~EMObject () | |
| Desctructor Does not free pointers. | |
| operator bool () const | |
| Conversion operators. | |
| operator int () const | |
| operator unsigned int () const | |
| operator float () const | |
| operator double () const | |
| operator const char * () const | |
| operator float * () const | |
| operator int * () const | |
| operator void * () const | |
| operator EMData * () const | |
| operator XYData * () const | |
| operator Transform * () const | |
| operator Ctf * () const | |
| operator vector< int > () const | |
| operator vector< float > () const | |
| operator vector< string > () const | |
| bool | is_null () const |
| Checks to see if the EMObject is interpretable This basically equates to checking to see if the type is UNKNOWN. | |
| string | to_str () const |
| Calls to_str( this->type). | |
| ObjectType | get_type () const |
| Get the ObjectType This is an enumerated type first declared in the class EMObjectTypes. | |
| string | get_type_string () const |
| Get the ObjectType as a string This is an enumerated type first declared in the class EMObjectTypes. | |
| string | to_str (ObjectType type) const |
| Write the EMObject's value to a string Literally copies into a string, except for the case where the type is boolen where it writes true of false, as opposed to 1 or 0. | |
Static Public Member Functions | |
| static string | get_object_type_name (ObjectType t) |
| Get an ObjectType as a string statically Can be accessed without the instantiation of a class object. | |
Private Member Functions | |
| void | printInfo () const |
| A debug function that prints as much information as possibe to cout. | |
| void | init () |
Private Attributes | |
| union { | |
| bool b | |
| int n | |
| unsigned int ui | |
| float f | |
| double d | |
| float * fp | |
| int * ip | |
| void * vp | |
| EMData * emdata | |
| XYData * xydata | |
| }; | |
| string | str |
| vector< int > | iarray |
| vector< float > | farray |
| vector< string > | strarray |
| ObjectType | type |
Static Private Attributes | |
| static map< ObjectType, string > | type_registry |
Friends | |
| bool | operator== (const EMObject &e1, const EMObject &e2) |
| Friend declaration operator== namespace EMAN2 operator== accesses private variables. | |
| bool | operator!= (const EMObject &e1, const EMObject &e2) |
| Friend declaration operator!= namespace EMAN2 operator!= accesses private variables. | |
Each type is typically used as follows ('int' is the example):
int a = 12; EMObject o(a); EMObject o2 = a; // implicit converter from int to EMObject. int a1 = o; // implicit converter from EMObject to int.
EMObjects may store pointers but they currently do not assume ownership - that is, the memory associated with a pointer is never freed by an EMObject.
This type of class design is sometimes referred to as the Variant pattern.
See the testing code in rt/emdata/test_emobject.cpp for prewritten testing code
Definition at line 122 of file emobject.h.
| UNKNOWN | |
| BOOL | |
| UNSIGNEDINT | |
| INT | |
| FLOAT | |
| DOUBLE | |
| STRING | |
| EMDATA | |
| XYDATA | |
| INTARRAY | |
| FLOATARRAY | |
| STRINGARRAY | |
| TRANSFORM | |
| CTF | |
| FLOAT_POINTER | |
| INT_POINTER | |
| VOID_POINTER |
Definition at line 125 of file emobject.h.
00125 { 00126 UNKNOWN, 00127 BOOL, 00128 UNSIGNEDINT, 00129 INT, 00130 FLOAT, 00131 DOUBLE, 00132 STRING, 00133 EMDATA, 00134 XYDATA, 00135 INTARRAY, 00136 FLOATARRAY, 00137 STRINGARRAY, 00138 TRANSFORM, 00139 CTF, 00140 FLOAT_POINTER, 00141 INT_POINTER, 00142 VOID_POINTER 00143 };
| EMObject::EMObject | ( | ) |
| EMObject::EMObject | ( | bool | boolean | ) |
| EMObject::EMObject | ( | int | num | ) |
| EMObject::EMObject | ( | unsigned int | num | ) |
Definition at line 138 of file emobject.cpp.
References init().
00138 : 00139 ui(num), type(UNSIGNEDINT) 00140 { 00141 init(); 00142 }
| EMObject::EMObject | ( | float | ff | ) |
Definition at line 144 of file emobject.cpp.
References f, EMAN::Util::goodf(), and init().
00144 : 00145 type(FLOAT) 00146 { 00147 if(Util::goodf(&ff)) { 00148 f = ff; 00149 } 00150 else{ 00151 f = 0.0f; 00152 } 00153 init(); 00154 }
| EMObject::EMObject | ( | double | dd | ) |
Definition at line 156 of file emobject.cpp.
References d, EMAN::Util::goodf(), and init().
00156 : 00157 type(DOUBLE) 00158 { 00159 if(Util::goodf(&dd)) { 00160 d = dd; 00161 } 00162 else{ 00163 d = 0.0; 00164 } 00165 init(); 00166 }
| EMObject::EMObject | ( | const char * | s | ) |
| EMObject::EMObject | ( | const string & | s | ) |
| EMObject::EMObject | ( | float * | fp | ) |
Definition at line 180 of file emobject.cpp.
References init().
00180 : 00181 fp(f), type(FLOAT_POINTER) 00182 { 00183 init(); 00184 }
| EMObject::EMObject | ( | int * | ip | ) |
Definition at line 186 of file emobject.cpp.
References init().
00186 : 00187 ip(i), type(INT_POINTER) 00188 { 00189 init(); 00190 }
| EMObject::EMObject | ( | void * | vp | ) |
Definition at line 192 of file emobject.cpp.
References init().
00192 : 00193 vp(v), type(VOID_POINTER) 00194 { 00195 init(); 00196 }
| EMObject::EMObject | ( | EMData * | em | ) |
| EMObject::EMObject | ( | XYData * | xy | ) |
Definition at line 204 of file emobject.cpp.
References init().
00204 : 00205 xydata(xy), type(XYDATA) 00206 { 00207 init(); 00208 } EMObject::EMObject(Transform* t) :
| EMObject::EMObject | ( | Transform * | t | ) |
Definition at line 209 of file emobject.cpp.
References init().
00209 : 00210 farray(t->get_matrix()), type(TRANSFORM) 00211 { 00212 init(); 00213 }
| EMObject::EMObject | ( | Ctf * | ctf | ) |
| EMObject::EMObject | ( | const vector< int > & | v | ) |
| EMObject::EMObject | ( | const vector< float > & | v | ) |
Definition at line 227 of file emobject.cpp.
References init().
00227 : 00228 farray(v), type(FLOATARRAY) 00229 { 00230 init(); 00231 }
| EMObject::EMObject | ( | const vector< string > & | sarray | ) |
Definition at line 233 of file emobject.cpp.
References init().
00233 : 00234 strarray(sarray), type(STRINGARRAY) 00235 { 00236 init(); 00237 }
| EMObject::EMObject | ( | const EMObject & | that | ) |
Copy constructor.
copies pointer locations - does not take ownership deep copies all non pointer objects
Definition at line 795 of file emobject.cpp.
00796 { 00797 // init isn't necessary because that must have already called it! 00798 *this = that; 00799 }
| EMObject::~EMObject | ( | ) |
Assigment operator copies pointer locations (emdata, xydata, transform3d) - does not take ownership deep copies all non pointer objects.
Definition at line 805 of file emobject.cpp.
References b, BOOL, CTF, d, DOUBLE, emdata, EMDATA, f, farray, FLOAT, FLOAT_POINTER, FLOATARRAY, fp, iarray, INT, INT_POINTER, INTARRAY, ip, LOGERR, n, NotExistingObjectException, str, strarray, STRING, STRINGARRAY, TRANSFORM, type, ui, UNKNOWN, UNSIGNEDINT, VOID_POINTER, vp, xydata, and XYDATA.
00806 { 00807 00808 // This test breaks assignment when either the current or assigned values are (float)nan 00809 // it's also somewhat inherently stupid, since testing for equivalence may cost as much 00810 // as assignment. 00811 // if ( *this != that ) 00812 { 00813 // First store the type of the input, At first I forgot to do this and it was a very 00814 // difficult bug to track down 00815 type = that.type; 00816 00817 // if ( type != this_type ) throw 00818 00819 00820 switch (type) 00821 { 00822 case BOOL: 00823 b = that.b; 00824 break; 00825 case INT: 00826 n = that.n; 00827 break; 00828 case UNSIGNEDINT: 00829 ui = that.ui; 00830 break; 00831 case FLOAT: 00832 f = that.f; 00833 break; 00834 case DOUBLE: 00835 d = that.d; 00836 break; 00837 case CTF: 00838 case STRING: 00839 str = that.str; 00840 break; 00841 case FLOAT_POINTER: 00842 // Warning - Pointer address copy. 00843 fp = that.fp; 00844 break; 00845 case INT_POINTER: 00846 // Warning - Pointer address copy. 00847 ip = that.ip; 00848 break; 00849 case VOID_POINTER: 00850 // Warning - Pointer address copy. 00851 vp = that.vp; 00852 break; 00853 case EMDATA: 00854 // Warning - Pointer address copy. 00855 emdata = that.emdata; 00856 break; 00857 case XYDATA: 00858 // Warning - Pointer address copy. 00859 xydata = that.xydata; 00860 break; 00861 case TRANSFORM: 00862 case FLOATARRAY: 00863 farray = that.farray; 00864 break; 00865 case INTARRAY: 00866 iarray = that.iarray; 00867 break; 00868 case STRINGARRAY: 00869 strarray = that.strarray; 00870 break; 00871 case UNKNOWN: 00872 // This is possible, nothing should happen 00873 // The EMObject's default constructor has been called and 00874 // as yet has no type - doing nothing is exactly as the 00875 // the assignment operator should work. 00876 break; 00877 default: 00878 LOGERR("No such EMObject defined"); 00879 throw NotExistingObjectException("EMObject", "unknown type"); 00880 break; 00881 } 00882 } 00883 // else 00884 // { 00885 // cerr << "Warning - attempt to assign EMObject onto itself. No action taken" << endl; 00886 // cerr << "My type is " << get_object_type_name(type) << endl; 00887 // } 00888 00889 return *this; 00890 }
| EMObject::operator bool | ( | ) | const |
Conversion operators.
Definition at line 239 of file emobject.cpp.
References b, BOOL, d, DOUBLE, emdata, EMDATA, f, FLOAT, FLOAT_POINTER, fp, get_object_type_name(), INT, INT_POINTER, ip, n, type, TypeException, ui, UNKNOWN, UNSIGNEDINT, VOID_POINTER, xydata, and XYDATA.
00240 { 00241 if (type == BOOL) { 00242 return b; 00243 } 00244 else if (type == INT) { 00245 return n != 0; 00246 } 00247 else if (type == UNSIGNEDINT) { 00248 return ui != 0; 00249 } 00250 else if (type == FLOAT) { 00251 return f != 0; 00252 } 00253 else if (type == DOUBLE) { 00254 return d != 0; 00255 } 00256 else if (type == EMDATA) { 00257 return emdata != 0; 00258 } 00259 else if (type == XYDATA) { 00260 return xydata != 0; 00261 } 00262 else if (type == FLOAT_POINTER) { 00263 return fp != 0; 00264 } 00265 else if (type == INT_POINTER) { 00266 return ip != 0; 00267 } 00268 else if (type == VOID_POINTER) { 00269 return vp != 0; 00270 } 00271 // else if (type == TRANSFORM) { 00272 // return transform != 0; 00273 // } 00274 // It seemed unconventional to return a boolean for the stl objects 00275 else { 00276 if (type != UNKNOWN) { 00277 throw TypeException("Cannot convert to bool this data type ", 00278 get_object_type_name(type)); 00279 } 00280 } 00281 return 0; 00282 }
| EMObject::operator int | ( | ) | const |
Definition at line 284 of file emobject.cpp.
References b, BOOL, d, DOUBLE, f, FLOAT, get_object_type_name(), INT, n, type, TypeException, ui, UNKNOWN, and UNSIGNEDINT.
00285 { 00286 if (type == INT) { 00287 return n; 00288 } 00289 else if (type == UNSIGNEDINT) { 00290 return (int) ui; 00291 } 00292 else if (type == FLOAT) { 00293 return (int) f; 00294 } 00295 else if (type == DOUBLE) { 00296 return (int) d; 00297 } 00298 else if (type == BOOL) { 00299 return b?1:0; 00300 } 00301 else { 00302 if (type != UNKNOWN) { 00303 throw TypeException("Cannot convert to int this data type ", 00304 get_object_type_name(type)); 00305 } 00306 } 00307 return 0; 00308 }
| EMObject::operator unsigned int | ( | ) | const |
Definition at line 310 of file emobject.cpp.
References get_object_type_name(), type, TypeException, ui, UNKNOWN, and UNSIGNEDINT.
00311 { 00312 if (type == UNSIGNEDINT) { 00313 return (unsigned int) ui; 00314 } 00315 else { 00316 if (type != UNKNOWN) { 00317 throw TypeException("Cannot convert to int this data type ", 00318 get_object_type_name(type)); 00319 } 00320 } 00321 return 0; 00322 }
| EMObject::operator float | ( | ) | const |
Definition at line 324 of file emobject.cpp.
References b, BOOL, d, DOUBLE, f, FLOAT, get_object_type_name(), INT, n, type, TypeException, ui, UNKNOWN, and UNSIGNEDINT.
00325 { 00326 if (type == BOOL) { 00327 return b?1.0f:0.0f; 00328 } 00329 else if (type == FLOAT) { 00330 return f; 00331 } 00332 else if (type == INT) { 00333 return (float) n; 00334 } 00335 else if (type == UNSIGNEDINT) { 00336 return (float) ui; 00337 } 00338 else if (type == DOUBLE) { 00339 return (float) d; 00340 } 00341 else { 00342 if (type != UNKNOWN) { 00343 throw TypeException("Cannot convert to float from this data type", 00344 get_object_type_name(type)); 00345 } 00346 } 00347 00348 return 0; 00349 }
| EMObject::operator double | ( | ) | const |
Definition at line 351 of file emobject.cpp.
References b, BOOL, d, DOUBLE, f, FLOAT, get_object_type_name(), INT, n, type, TypeException, ui, UNKNOWN, and UNSIGNEDINT.
00352 { 00353 if (type == BOOL) { 00354 return b?1.0:0.0; 00355 } 00356 else if (type == DOUBLE) { 00357 return d; 00358 } 00359 else if (type == INT) { 00360 return (double) n; 00361 } 00362 else if (type == UNSIGNEDINT) { 00363 return (double) ui; 00364 } 00365 else if (type == FLOAT) { 00366 return (double) f; 00367 } 00368 else { 00369 if (type != UNKNOWN) { 00370 throw TypeException("Cannot convert to double from this data type", 00371 get_object_type_name(type)); 00372 } 00373 } 00374 return 0; 00375 }
| EMObject::operator const char * | ( | ) | const |
Definition at line 418 of file emobject.cpp.
References CTF, d, DOUBLE, f, FLOAT, get_object_type_name(), INT, n, str, STRING, type, TypeException, ui, UNKNOWN, and UNSIGNEDINT.
00419 { 00420 if (type != STRING && type != CTF) { 00421 stringstream ss; 00422 string return_string; 00423 if ( type == INT ) 00424 { 00425 ss << n; 00426 ss >> return_string; 00427 return return_string.c_str(); 00428 } 00429 if ( type == UNSIGNEDINT ) 00430 { 00431 ss << ui; 00432 ss >> return_string; 00433 return return_string.c_str(); 00434 } 00435 else 00436 if ( type == FLOAT ) 00437 { 00438 ss << f; 00439 ss >> return_string; 00440 return return_string.c_str(); 00441 } 00442 else 00443 if ( type == DOUBLE ) 00444 { 00445 ss << d; 00446 ss >> return_string; 00447 return return_string.c_str(); 00448 } 00449 else if (type != UNKNOWN) { 00450 throw TypeException("Cannot convert to string from this data type", 00451 get_object_type_name(type)); 00452 } 00453 00454 return ""; 00455 } 00456 return str.c_str(); 00457 }
| EMObject::operator float * | ( | ) | const |
Definition at line 392 of file emobject.cpp.
References FLOAT_POINTER, fp, get_object_type_name(), type, TypeException, and UNKNOWN.
00393 { 00394 if (type != FLOAT_POINTER) 00395 { 00396 if (type != UNKNOWN) 00397 throw TypeException("Cannot convert to float pointer from this data type", 00398 get_object_type_name(type)); 00399 00400 return 0; 00401 } 00402 00403 return fp; 00404 }
| EMObject::operator int * | ( | ) | const |
Definition at line 377 of file emobject.cpp.
References get_object_type_name(), INT_POINTER, ip, type, TypeException, and UNKNOWN.
00378 { 00379 if (type != INT_POINTER) 00380 { 00381 if (type != UNKNOWN) 00382 throw TypeException("Cannot convert to float pointer from this data type", 00383 get_object_type_name(type)); 00384 00385 return 0; 00386 } 00387 00388 return ip; 00389 }
| EMObject::operator void * | ( | ) | const |
Definition at line 407 of file emobject.cpp.
References emdata, EMDATA, FLOAT_POINTER, fp, get_object_type_name(), INT_POINTER, ip, type, TypeException, VOID_POINTER, xydata, and XYDATA.
00408 { 00409 if (type == VOID_POINTER) return vp; 00410 else if (type == FLOAT_POINTER) return (void *)fp; 00411 else if (type == INT_POINTER) return (void *)ip; 00412 else if (type == EMDATA) return (void *) emdata; 00413 else if (type == XYDATA) return (void *) xydata; 00414 // else if (type == TRANSFORM) return (void *) transform; 00415 else throw TypeException("Cannot convert to void pointer from this data type", get_object_type_name(type)); 00416 }
| EMObject::operator EMData * | ( | ) | const |
Definition at line 459 of file emobject.cpp.
References emdata, EMDATA, get_object_type_name(), type, TypeException, and UNKNOWN.
00460 { 00461 if (type != EMDATA) { 00462 if (type != UNKNOWN) { 00463 throw TypeException("Cannot convert to EMData* from this data type", 00464 get_object_type_name(type)); 00465 } 00466 return 0; 00467 } 00468 return emdata; 00469 }
| EMObject::operator XYData * | ( | ) | const |
Definition at line 471 of file emobject.cpp.
References get_object_type_name(), type, TypeException, UNKNOWN, xydata, and XYDATA.
00472 { 00473 if (type != XYDATA) { 00474 if (type != UNKNOWN) { 00475 throw TypeException("Cannot convert to XYData* from this data type", 00476 get_object_type_name(type)); 00477 } 00478 return 0; 00479 } 00480 return xydata; 00481 }
| EMObject::operator Transform * | ( | ) | const |
Definition at line 483 of file emobject.cpp.
References farray, get_object_type_name(), EMAN::Transform::set_matrix(), TRANSFORM, type, TypeException, and UNKNOWN.
00484 { 00485 if(type != TRANSFORM) { 00486 if(type != UNKNOWN) { 00487 throw TypeException("Cannot convert to TRANSFORM* from this data type", 00488 get_object_type_name(type)); 00489 } 00490 } 00491 Transform * transform = new Transform(); 00492 transform->set_matrix(farray); 00493 return transform; 00494 }
| EMObject::operator Ctf * | ( | ) | const |
Definition at line 496 of file emobject.cpp.
References EMAN::Ctf::from_string(), and str.
00497 { 00498 /* if(type != CTF) { 00499 if(type != CTF) { 00500 throw TypeException("Cannot convert to TRANSFORM* from this data type", 00501 get_object_type_name(type)); 00502 } 00503 }*/ 00504 Ctf * ctf = 0; 00505 if(str[0] == 'O') { 00506 ctf = new EMAN1Ctf(); 00507 ctf->from_string(str); 00508 } 00509 else if(str[0] == 'E') { 00510 ctf = new EMAN2Ctf(); 00511 ctf->from_string(str); 00512 } 00513 return ctf; 00514 }
| EMObject::operator vector< int > | ( | ) | const |
Definition at line 516 of file emobject.cpp.
References get_object_type_name(), iarray, INTARRAY, type, TypeException, and UNKNOWN.
00517 { 00518 if( type != INTARRAY ) 00519 { 00520 if( type != UNKNOWN ) { 00521 throw TypeException("Cannot convert to vector<int> from this data type", get_object_type_name(type) ); 00522 } 00523 return vector<int>(); 00524 } 00525 return iarray; 00526 }
| EMObject::operator vector< float > | ( | ) | const |
Definition at line 528 of file emobject.cpp.
References farray, FLOATARRAY, get_object_type_name(), type, TypeException, and UNKNOWN.
00529 { 00530 if (type != FLOATARRAY) { 00531 if (type != UNKNOWN) { 00532 throw TypeException("Cannot convert to vector<float> from this data type", 00533 get_object_type_name(type)); 00534 } 00535 return vector < float >(); 00536 } 00537 return farray; 00538 }
| EMObject::operator vector< string > | ( | ) | const |
Definition at line 540 of file emobject.cpp.
References get_object_type_name(), strarray, STRINGARRAY, type, TypeException, and UNKNOWN.
00541 { 00542 if (type != STRINGARRAY) { 00543 if (type != UNKNOWN) { 00544 throw TypeException("Cannot convert to vector<string> from this data type", 00545 get_object_type_name(type)); 00546 } 00547 return vector<string>(); 00548 } 00549 return strarray; 00550 }
| bool EMObject::is_null | ( | ) | const |
Checks to see if the EMObject is interpretable This basically equates to checking to see if the type is UNKNOWN.
Definition at line 552 of file emobject.cpp.
Referenced by EMAN::EMUtil::dump_dict().
| string EMObject::to_str | ( | ) | const |
Calls to_str( this->type).
Definition at line 557 of file emobject.cpp.
References type.
Referenced by EMAN::EMUtil::dump_dict(), and printInfo().
| ObjectType EMAN::EMObject::get_type | ( | ) | const [inline] |
Get the ObjectType This is an enumerated type first declared in the class EMObjectTypes.
Definition at line 218 of file emobject.h.
References type.
Referenced by EMAN::Transform::set_params(), and EMAN::Transform::set_params_inverse().
00218 { return type; }
| string EMAN::EMObject::get_type_string | ( | ) | const [inline] |
Get the ObjectType as a string This is an enumerated type first declared in the class EMObjectTypes.
Definition at line 224 of file emobject.h.
References get_object_type_name(), and type.
00224 { return get_object_type_name(type); }
| string EMObject::to_str | ( | ObjectType | type | ) | const |
Write the EMObject's value to a string Literally copies into a string, except for the case where the type is boolen where it writes true of false, as opposed to 1 or 0.
Definition at line 562 of file emobject.cpp.
References b, BOOL, CTF, d, DOUBLE, EMDATA, f, FLOAT, FLOAT_POINTER, FLOATARRAY, INT, INTARRAY, LOGERR, n, NotExistingObjectException, str, STRING, STRINGARRAY, TRANSFORM, ui, UNKNOWN, UNSIGNEDINT, VOID_POINTER, and XYDATA.
00563 { 00564 if (argtype == STRING) { 00565 return str; 00566 } 00567 else { 00568 char tmp_str[32]; 00569 if (argtype == BOOL) { 00570 if (b) 00571 sprintf(tmp_str, "true"); 00572 else 00573 sprintf(tmp_str, "false"); 00574 } 00575 else if (argtype == INT) { 00576 sprintf(tmp_str, "%d", n); 00577 } 00578 else if (argtype == UNSIGNEDINT) { 00579 sprintf(tmp_str, "%d", ui); 00580 } 00581 else if (argtype == FLOAT) { 00582 sprintf(tmp_str, "%f", f); 00583 } 00584 else if (argtype == DOUBLE) { 00585 sprintf(tmp_str, "%f", d); 00586 } 00587 else if (argtype == EMDATA) { 00588 sprintf(tmp_str, "EMDATA"); 00589 } 00590 else if (argtype == FLOAT_POINTER) { 00591 sprintf(tmp_str, "FLOAT_POINTER"); 00592 } 00593 else if (argtype == INT) { 00594 sprintf(tmp_str, "INT_POINTER"); 00595 } 00596 else if (argtype == VOID_POINTER) { 00597 sprintf(tmp_str, "VOID_POINTER"); 00598 } 00599 else if (argtype == XYDATA) { 00600 sprintf(tmp_str, "XYDATA"); 00601 } 00602 else if (argtype == INTARRAY) { 00603 sprintf(tmp_str, "INTARRAY"); 00604 } 00605 else if (argtype == FLOATARRAY) { 00606 sprintf(tmp_str, "FLOATARRAY"); 00607 } 00608 else if (argtype == STRINGARRAY) { 00609 sprintf(tmp_str, "STRINGARRAY"); 00610 } 00611 else if (argtype == TRANSFORM) { 00612 sprintf(tmp_str, "TRANSFORMD"); 00613 } 00614 else if (argtype == CTF) { 00615 sprintf(tmp_str, "CTF"); 00616 } 00617 else if (argtype == UNKNOWN) { 00618 sprintf(tmp_str, "UNKNOWN"); 00619 } 00620 else { 00621 LOGERR("No such EMObject defined"); 00622 throw NotExistingObjectException("EMObject", "unknown type"); 00623 } 00624 return string(tmp_str); 00625 } 00626 }
| string EMObject::get_object_type_name | ( | ObjectType | t | ) | [static] |
Get an ObjectType as a string statically Can be accessed without the instantiation of a class object.
Definition at line 628 of file emobject.cpp.
References BOOL, CTF, DOUBLE, EMDATA, FLOAT, FLOAT_POINTER, FLOATARRAY, INT, INT_POINTER, INTARRAY, LOGERR, NotExistingObjectException, STRING, STRINGARRAY, TRANSFORM, type_registry, UNKNOWN, UNSIGNEDINT, VOID_POINTER, and XYDATA.
Referenced by get_type_string(), operator bool(), operator const char *(), operator double(), operator EMData *(), operator float(), operator float *(), operator int(), operator int *(), operator Transform *(), operator unsigned int(), operator vector< float >(), operator vector< int >(), operator vector< string >(), operator void *(), operator XYData *(), and EMAN::TypeDict::put().
00629 { 00630 #ifdef _WIN32 00631 if (t == BOOL) { 00632 return "BOOL"; 00633 }else 00634 if ( t == INT){ 00635 return "INT"; 00636 }else 00637 if ( t == UNSIGNEDINT){ 00638 return "UNSIGNEDINT"; 00639 } else 00640 if ( t == FLOAT){ 00641 return "FLOAT"; 00642 } else 00643 if ( t == DOUBLE){ 00644 return "DOUBLE"; 00645 }else 00646 if ( t == STRING){ 00647 return "STRING"; 00648 }else 00649 if ( t == EMDATA){ 00650 return "EMDATA"; 00651 } 00652 else 00653 if ( t == XYDATA){ 00654 return "XYDATA"; 00655 }else 00656 if ( t == INTARRAY){ 00657 return "INTARRAY"; 00658 }else 00659 if ( t == FLOATARRAY){ 00660 return "FLOATARRAY"; 00661 } else 00662 if ( t == STRINGARRAY){ 00663 return "STRINGARRAY"; 00664 }else 00665 if ( t == TRANSFORM){ 00666 return "TRANSFORM"; 00667 }else 00668 if ( t == CTF){ 00669 return "CTF"; 00670 }else 00671 if ( t == FLOAT_POINTER){ 00672 return "FLOAT_POINTER"; 00673 }else 00674 if ( t == INT_POINTER){ 00675 return "INT_POINTER"; 00676 }else 00677 if ( t == UNKNOWN){ 00678 return "UNKNOWN"; 00679 } else 00680 if ( t == VOID_POINTER){ 00681 return "VOID_POINTER"; 00682 } 00683 else { 00684 LOGERR("No such EMObject defined"); 00685 throw NotExistingObjectException("EMObject", "unknown type"); 00686 } 00687 00688 #else 00689 00690 if ( type_registry.find(t) != type_registry.end() ) 00691 return type_registry[t]; 00692 else 00693 LOGERR("No such EMObject defined"); 00694 throw NotExistingObjectException("EMObject", "unknown type"); 00695 #endif //_WIN32 00696 }
| void EMObject::printInfo | ( | ) | const [private] |
A debug function that prints as much information as possibe to cout.
Definition at line 106 of file emobject.cpp.
References to_str(), type, and type_registry.
00107 { 00108 cout << "The address of my type is " << &type << endl; 00109 cout << " Now printing the enumerated values in type_registry " << endl; 00110 for( map< ObjectType, string>::const_iterator it = type_registry.begin(); it != type_registry.end(); ++it ) 00111 { 00112 cout << it->first << " " << it->second << endl; 00113 } 00114 cout << "My type is " << to_str(type) << " and its enumerated value is " << type << endl; 00115 cout << "The address of the static type registry is " << &type_registry <<", it should be same for all EMObjects" << endl; 00116 }
| void EMObject::init | ( | ) | [private] |
Definition at line 77 of file emobject.cpp.
References BOOL, CTF, DOUBLE, EMDATA, FLOAT, FLOAT_POINTER, FLOATARRAY, INT, INT_POINTER, INTARRAY, STRING, STRINGARRAY, TRANSFORM, type_registry, UNKNOWN, UNSIGNEDINT, VOID_POINTER, and XYDATA.
Referenced by EMObject().
00078 { 00079 static bool first_construction = true; 00080 if ( first_construction ) 00081 { 00082 // Initialize the the type registry once and for all 00083 type_registry[BOOL] = "BOOL"; 00084 type_registry[INT] = "INT"; 00085 type_registry[UNSIGNEDINT] = "UNSIGNEDINT"; 00086 type_registry[FLOAT] = "FLOAT"; 00087 type_registry[DOUBLE] = "DOUBLE"; 00088 type_registry[STRING] = "STRING"; 00089 type_registry[EMDATA] = "EMDATA"; 00090 type_registry[XYDATA] = "XYDATA"; 00091 type_registry[INTARRAY] = "INTARRAY"; 00092 type_registry[FLOATARRAY] = "FLOATARRAY"; 00093 type_registry[STRINGARRAY] = "STRINGARRAY"; 00094 type_registry[TRANSFORM] = "TRANFORM"; 00095 type_registry[CTF] = "CTF"; 00096 type_registry[FLOAT_POINTER] = "FLOAT_POINTER"; 00097 type_registry[INT_POINTER] = "INT_POINTER"; 00098 type_registry[UNKNOWN] = "UNKNOWN"; 00099 type_registry[VOID_POINTER] = "VOID_POINTER"; 00100 first_construction = false; 00101 } 00102 }
Friend declaration operator== namespace EMAN2 operator== accesses private variables.
Definition at line 698 of file emobject.cpp.
00699 { 00700 00701 if (e1.type != e2.type) { 00702 return false; 00703 } 00704 00705 switch (e1.type) { 00706 case EMObject::BOOL: 00707 return (e1.b == e2.b); 00708 break; 00709 case EMObject::INT: 00710 return (e1.n == e2.n); 00711 break; 00712 case EMObject::UNSIGNEDINT: 00713 return (e1.ui == e2.ui); 00714 break; 00715 case EMObject::FLOAT: 00716 return (e1.f == e2.f); 00717 break; 00718 case EMObject::DOUBLE: 00719 return (e1.d == e2.d); 00720 break; 00721 case EMObject::CTF: 00722 case EMObject::STRING: 00723 return (e1.str == e2.str); 00724 break; 00725 case EMObject::FLOAT_POINTER: 00726 return (e1.fp == e2.fp); 00727 break; 00728 case EMObject::INT_POINTER: 00729 return (e1.ip == e2.ip); 00730 break; 00731 case EMObject::VOID_POINTER: 00732 return (e1.vp == e2.vp); 00733 break; 00734 case EMObject::EMDATA: 00735 return (e1.emdata == e2.emdata); 00736 break; 00737 case EMObject::XYDATA: 00738 return (e1.xydata == e2.xydata); 00739 break; 00740 case EMObject::TRANSFORM: 00741 case EMObject::FLOATARRAY: 00742 if (e1.farray.size() == e2.farray.size()) { 00743 for (size_t i = 0; i < e1.farray.size(); i++) { 00744 if (e1.farray[i] != e2.farray[i]) { 00745 return false; 00746 } 00747 } 00748 return true; 00749 } 00750 else { 00751 return false; 00752 } 00753 break; 00754 case EMObject::INTARRAY: 00755 if (e1.iarray.size() == e2.iarray.size()) { 00756 for (size_t i = 0; i < e1.iarray.size(); i++) { 00757 if (e1.iarray[i] != e2.iarray[i]) { 00758 return false; 00759 } 00760 } 00761 return true; 00762 } 00763 break; 00764 case EMObject::STRINGARRAY: 00765 if (e1.strarray.size() == e2.strarray.size()) { 00766 for (size_t i = 0; i < e1.strarray.size(); i++) { 00767 if (e1.strarray[i] != e2.strarray[i]) { 00768 return false; 00769 } 00770 } 00771 return true; 00772 } 00773 else { 00774 return false; 00775 } 00776 break; 00777 case EMObject::UNKNOWN: 00778 // UNKNOWN really means "no type" and if two objects both have 00779 // type UNKNOWN they really are the same 00780 return (e1.type == e2.type); 00781 break; 00782 default: 00783 return false; 00784 break; 00785 } 00786 return false; 00787 }
Friend declaration operator!= namespace EMAN2 operator!= accesses private variables.
Definition at line 789 of file emobject.cpp.
| bool EMAN::EMObject::b |
Definition at line 252 of file emobject.h.
Referenced by operator bool(), operator double(), operator float(), operator int(), operator=(), EMAN::operator==(), and to_str().
Definition at line 253 of file emobject.h.
Referenced by operator bool(), operator const char *(), operator double(), operator float(), operator int(), operator=(), EMAN::operator==(), and to_str().
| unsigned int EMAN::EMObject::ui |
Definition at line 254 of file emobject.h.
Referenced by operator bool(), operator const char *(), operator double(), operator float(), operator int(), operator unsigned int(), operator=(), EMAN::operator==(), and to_str().
| float EMAN::EMObject::f |
Definition at line 255 of file emobject.h.
Referenced by EMAN::CtfAverager::add_image(), EMAN::FRCCmp::cmp(), EMObject(), EMAN::nn4Reconstructor::insert_slice(), EMAN::PointArray::match_points(), operator bool(), operator const char *(), operator double(), operator float(), operator int(), operator=(), EMAN::operator==(), EMAN::Util::pad(), EMAN::ToMassCenterProcessor::process_inplace(), EMAN::EMData::rotate_translate(), and to_str().
| double EMAN::EMObject::d |
Definition at line 256 of file emobject.h.
Referenced by EMObject(), operator bool(), operator const char *(), operator double(), operator float(), operator int(), operator=(), EMAN::operator==(), and to_str().
| float* EMAN::EMObject::fp |
Definition at line 257 of file emobject.h.
Referenced by operator bool(), operator float *(), operator void *(), operator=(), and EMAN::operator==().
| int* EMAN::EMObject::ip |
Definition at line 258 of file emobject.h.
Referenced by operator bool(), operator int *(), operator void *(), operator=(), and EMAN::operator==().
| void* EMAN::EMObject::vp |
Definition at line 260 of file emobject.h.
Referenced by operator bool(), operator EMData *(), operator void *(), operator=(), and EMAN::operator==().
Definition at line 261 of file emobject.h.
Referenced by operator bool(), operator void *(), operator XYData *(), operator=(), and EMAN::operator==().
union { ... } [private] |
string EMAN::EMObject::str [private] |
Definition at line 264 of file emobject.h.
Referenced by operator const char *(), operator Ctf *(), operator=(), EMAN::operator==(), and to_str().
vector< int > EMAN::EMObject::iarray [private] |
Definition at line 265 of file emobject.h.
Referenced by operator vector< int >(), operator=(), and EMAN::operator==().
vector< float > EMAN::EMObject::farray [private] |
Definition at line 266 of file emobject.h.
Referenced by operator Transform *(), operator vector< float >(), operator=(), and EMAN::operator==().
vector< string> EMAN::EMObject::strarray [private] |
Definition at line 267 of file emobject.h.
Referenced by operator vector< string >(), operator=(), and EMAN::operator==().
ObjectType EMAN::EMObject::type [private] |
Definition at line 268 of file emobject.h.
Referenced by get_type(), get_type_string(), is_null(), operator bool(), operator const char *(), operator double(), operator EMData *(), operator float(), operator float *(), operator int(), operator int *(), operator Transform *(), operator unsigned int(), operator vector< float >(), operator vector< int >(), operator vector< string >(), operator void *(), operator XYData *(), operator=(), EMAN::operator==(), printInfo(), and to_str().
map< EMObject::ObjectType, string > EMObject::type_registry [static, private] |
Definition at line 276 of file emobject.h.
Referenced by get_object_type_name(), init(), and printInfo().
1.5.6