#include <emobject.h>
Collaboration diagram for EMAN::EMObject:
Public Types | |
UNKNOWN | |
BOOL | |
UNSIGNEDINT | |
INT | |
FLOAT | |
DOUBLE | |
STRING | |
EMDATA | |
XYDATA | |
INTARRAY | |
FLOATARRAY | |
STRINGARRAY | |
TRANSFORM | |
CTF | |
FLOAT_POINTER | |
INT_POINTER | |
VOID_POINTER | |
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 () const | |
operator vector () const | |
operator vector () 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. | |
Static Private Member Functions | |
static map< ObjectType, string > | 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 = init() |
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 | ( | ) |
Constructors for each type More types could be added, but all of the accompanying functions would have to be altered to ensure correct functioning.
Definition at line 123 of file emobject.cpp.
EMObject::EMObject | ( | bool | boolean | ) |
EMObject::EMObject | ( | int | num | ) |
EMObject::EMObject | ( | unsigned int | num | ) |
EMObject::EMObject | ( | float | ff | ) |
Definition at line 139 of file emobject.cpp.
References f, and EMAN::Util::goodf().
00139 : 00140 type(FLOAT) 00141 { 00142 if(Util::goodf(&ff)) { 00143 f = ff; 00144 } 00145 else{ 00146 f = 0.0f; 00147 } 00148 }
EMObject::EMObject | ( | double | dd | ) |
Definition at line 150 of file emobject.cpp.
References d, and EMAN::Util::goodf().
00150 : 00151 type(DOUBLE) 00152 { 00153 if(Util::goodf(&dd)) { 00154 d = dd; 00155 } 00156 else{ 00157 d = 0.0; 00158 } 00159 }
EMObject::EMObject | ( | const char * | s | ) |
EMObject::EMObject | ( | const string & | s | ) |
EMObject::EMObject | ( | float * | fp | ) |
EMObject::EMObject | ( | int * | ip | ) |
EMObject::EMObject | ( | void * | vp | ) |
EMObject::EMObject | ( | EMData * | em | ) |
EMObject::EMObject | ( | XYData * | xy | ) |
EMObject::EMObject | ( | Transform * | t | ) |
EMObject::EMObject | ( | Ctf * | ctf | ) |
EMObject::EMObject | ( | const vector< int > & | v | ) |
EMObject::EMObject | ( | const vector< float > & | v | ) |
EMObject::EMObject | ( | const vector< string > & | sarray | ) |
Definition at line 205 of file emobject.cpp.
00205 : 00206 strarray(sarray), type(STRINGARRAY) 00207 {}
EMObject::EMObject | ( | const EMObject & | that | ) |
Copy constructor.
copies pointer locations - does not take ownership deep copies all non pointer objects
Definition at line 765 of file emobject.cpp.
00766 { 00767 // init isn't necessary because that must have already called it! 00768 *this = that; 00769 }
EMObject::~EMObject | ( | ) |
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 598 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(), operator void *(), operator XYData *(), and EMAN::TypeDict::put().
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 }
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.
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); }
map< EMObject::ObjectType, string > EMObject::init | ( | ) | [static, 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, UNKNOWN, UNSIGNEDINT, VOID_POINTER, and XYDATA.
00078 { 00079 map< EMObject::ObjectType, string> mymap; 00080 static bool first_construction = true; 00081 if ( first_construction ) 00082 { 00083 // Initialize the the type registry once and for all 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 }
bool EMObject::is_null | ( | ) | const |
EMObject::operator bool | ( | ) | const |
Conversion operators.
Definition at line 209 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.
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 // else if (type == TRANSFORM) { 00242 // return transform != 0; 00243 // } 00244 // It seemed unconventional to return a boolean for the stl objects 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 }
EMObject::operator const char * | ( | ) | const |
Definition at line 388 of file emobject.cpp.
References CTF, d, DOUBLE, f, FLOAT, get_object_type_name(), INT, n, str, STRING, type, TypeException, ui, UNKNOWN, and UNSIGNEDINT.
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 }
EMObject::operator Ctf * | ( | ) | const |
Definition at line 466 of file emobject.cpp.
References EMAN::Ctf::from_string(), and str.
00467 { 00468 /* if(type != CTF) { 00469 if(type != CTF) { 00470 throw TypeException("Cannot convert to TRANSFORM* from this data type", 00471 get_object_type_name(type)); 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 }
EMObject::operator double | ( | ) | const |
Definition at line 321 of file emobject.cpp.
References b, BOOL, d, DOUBLE, f, FLOAT, get_object_type_name(), INT, n, type, TypeException, ui, UNKNOWN, and UNSIGNEDINT.
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 }
EMObject::operator EMData * | ( | ) | const |
Definition at line 429 of file emobject.cpp.
References emdata, EMDATA, get_object_type_name(), type, TypeException, and UNKNOWN.
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 }
EMObject::operator float | ( | ) | const |
Definition at line 294 of file emobject.cpp.
References b, BOOL, d, DOUBLE, f, FLOAT, get_object_type_name(), INT, n, type, TypeException, ui, UNKNOWN, and UNSIGNEDINT.
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 }
EMObject::operator float * | ( | ) | const |
Definition at line 362 of file emobject.cpp.
References FLOAT_POINTER, fp, get_object_type_name(), type, TypeException, and UNKNOWN.
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 }
EMObject::operator int | ( | ) | const |
Definition at line 254 of file emobject.cpp.
References b, BOOL, d, DOUBLE, f, FLOAT, get_object_type_name(), INT, n, type, TypeException, ui, UNKNOWN, and UNSIGNEDINT.
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 }
EMObject::operator int * | ( | ) | const |
Definition at line 347 of file emobject.cpp.
References get_object_type_name(), INT_POINTER, ip, type, TypeException, and UNKNOWN.
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 }
EMObject::operator Transform * | ( | ) | const |
Definition at line 453 of file emobject.cpp.
References farray, get_object_type_name(), EMAN::Transform::set_matrix(), TRANSFORM, type, TypeException, and UNKNOWN.
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 }
EMObject::operator unsigned int | ( | ) | const |
Definition at line 280 of file emobject.cpp.
References get_object_type_name(), type, TypeException, ui, UNKNOWN, and UNSIGNEDINT.
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 }
EMAN::EMObject::operator vector | ( | ) | const |
EMAN::EMObject::operator vector | ( | ) | const |
EMObject::operator vector< string > | ( | ) | const |
Definition at line 486 of file emobject.cpp.
References get_object_type_name(), iarray, INTARRAY, type, TypeException, and UNKNOWN.
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 }
EMObject::operator void * | ( | ) | const |
Definition at line 377 of file emobject.cpp.
References emdata, EMDATA, FLOAT_POINTER, fp, get_object_type_name(), INT_POINTER, ip, type, TypeException, VOID_POINTER, xydata, and XYDATA.
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 // else if (type == TRANSFORM) return (void *) transform; 00385 else throw TypeException("Cannot convert to void pointer from this data type", get_object_type_name(type)); 00386 }
EMObject::operator XYData * | ( | ) | const |
Definition at line 441 of file emobject.cpp.
References get_object_type_name(), type, TypeException, UNKNOWN, xydata, and XYDATA.
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 }
Assigment operator copies pointer locations (emdata, xydata, transform3d) - does not take ownership deep copies all non pointer objects.
Definition at line 775 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.
00776 { 00777 00778 // This test breaks assignment when either the current or assigned values are (float)nan 00779 // it's also somewhat inherently stupid, since testing for equivalence may cost as much 00780 // as assignment. 00781 // if ( *this != that ) 00782 { 00783 // First store the type of the input, At first I forgot to do this and it was a very 00784 // difficult bug to track down 00785 type = that.type; 00786 00787 // if ( type != this_type ) throw 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 // Warning - Pointer address copy. 00813 fp = that.fp; 00814 break; 00815 case INT_POINTER: 00816 // Warning - Pointer address copy. 00817 ip = that.ip; 00818 break; 00819 case VOID_POINTER: 00820 // Warning - Pointer address copy. 00821 vp = that.vp; 00822 break; 00823 case EMDATA: 00824 // Warning - Pointer address copy. 00825 emdata = that.emdata; 00826 break; 00827 case XYDATA: 00828 // Warning - Pointer address copy. 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 // This is possible, nothing should happen 00843 // The EMObject's default constructor has been called and 00844 // as yet has no type - doing nothing is exactly as the 00845 // the assignment operator should work. 00846 break; 00847 default: 00848 LOGERR("No such EMObject defined"); 00849 throw NotExistingObjectException("EMObject", "unknown type"); 00850 break; 00851 } 00852 } 00853 // else 00854 // { 00855 // cerr << "Warning - attempt to assign EMObject onto itself. No action taken" << endl; 00856 // cerr << "My type is " << get_object_type_name(type) << endl; 00857 // } 00858 00859 return *this; 00860 }
void EMObject::printInfo | ( | ) | const [private] |
A debug function that prints as much information as possibe to cout.
Definition at line 109 of file emobject.cpp.
References to_str(), type, and type_registry.
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 }
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 532 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.
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 }
string EMObject::to_str | ( | ) | const |
Calls to_str( this->type).
Definition at line 527 of file emobject.cpp.
References type.
Referenced by printInfo().
Friend declaration operator!= namespace EMAN2 operator!= accesses private variables.
Definition at line 759 of file emobject.cpp.
Friend declaration operator== namespace EMAN2 operator== accesses private variables.
Definition at line 668 of file emobject.cpp.
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 // UNKNOWN really means "no type" and if two objects both have 00749 // type UNKNOWN they really are the same 00750 return (e1.type == e2.type); 00751 break; 00752 default: 00753 return false; 00754 break; 00755 } 00756 return false; 00757 }
union { ... } [private] |
bool EMAN::EMObject::b [private] |
Definition at line 252 of file emobject.h.
Referenced by operator bool(), operator double(), operator float(), operator int(), operator=(), EMAN::operator==(), and to_str().
double EMAN::EMObject::d [private] |
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().
EMData* EMAN::EMObject::emdata [private] |
Definition at line 260 of file emobject.h.
Referenced by operator bool(), operator EMData *(), operator void *(), operator=(), and EMAN::operator==().
float EMAN::EMObject::f [private] |
Definition at line 255 of file emobject.h.
Referenced by EMAN::FRCCmp::cmp(), EMAN::PhaseCmp::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().
vector< float > EMAN::EMObject::farray [private] |
Definition at line 266 of file emobject.h.
Referenced by operator Transform *(), operator=(), and EMAN::operator==().
float* EMAN::EMObject::fp [private] |
Definition at line 257 of file emobject.h.
Referenced by operator bool(), operator float *(), operator void *(), operator=(), and EMAN::operator==().
vector< int > EMAN::EMObject::iarray [private] |
Definition at line 265 of file emobject.h.
Referenced by operator vector(), operator=(), and EMAN::operator==().
int* EMAN::EMObject::ip [private] |
Definition at line 258 of file emobject.h.
Referenced by operator bool(), operator int *(), operator void *(), operator=(), and EMAN::operator==().
int EMAN::EMObject::n [private] |
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().
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< string> EMAN::EMObject::strarray [private] |
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(), operator void *(), operator XYData *(), operator=(), EMAN::operator==(), printInfo(), and to_str().
map< EMObject::ObjectType, string > EMObject::type_registry = init() [static, private] |
unsigned int EMAN::EMObject::ui [private] |
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().
void* EMAN::EMObject::vp [private] |
XYData* EMAN::EMObject::xydata [private] |
Definition at line 261 of file emobject.h.
Referenced by operator bool(), operator void *(), operator XYData *(), operator=(), and EMAN::operator==().