Main Page | Modules | Namespace List | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Namespace Members | Class Members | File Members

EMAN::EMObject Class Reference

EMObject is a wrapper class for types including int, float, double, etc as defined in ObjectType. More...

#include <emobject.h>

Collaboration diagram for EMAN::EMObject:

Collaboration graph
[legend]
List of all members.

Public Types

enum  ObjectType {
  UNKNOWN, BOOL, SHORT, UNSIGNEDINT,
  INT, FLOAT, DOUBLE, STRING,
  EMDATA, XYDATA, INTARRAY, FLOATARRAY,
  STRINGARRAY, TRANSFORM, CTF, FLOAT_POINTER,
  INT_POINTER, VOID_POINTER, TRANSFORMARRAY
}

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 (short)
 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 vector< Transform > &tarray)
 EMObject (const EMObject &that)
 Copy constructor.
EMObjectoperator= (const EMObject &that)
 Assigment operator copies pointer locations (emdata, xydata, transform) - does not take ownership deep copies all non pointer objects.
 ~EMObject ()
 Desctructor Does not free pointers.
 operator bool () const
 Conversion operators.
 operator short () const
 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
 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

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

map< ObjectType, string > init ()

Private Attributes

string str
vector< int > iarray
vector< float > farray
vector< string > strarray
vector< Transformtransformarray
ObjectType type
bool b
short si
int n
unsigned int ui
float f
double d
float * fp
int * ip
void * vp
EMDataemdata
XYDataxydata

Static Private Attributes

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.

Detailed Description

EMObject is a wrapper class for types including int, float, double, etc as defined in ObjectType.

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 126 of file emobject.h.


Member Enumeration Documentation

enum EMAN::EMObject::ObjectType
 

Enumeration values:
UNKNOWN 
BOOL 
SHORT 
UNSIGNEDINT 
INT 
FLOAT 
DOUBLE 
STRING 
EMDATA 
XYDATA 
INTARRAY 
FLOATARRAY 
STRINGARRAY 
TRANSFORM 
CTF 
FLOAT_POINTER 
INT_POINTER 
VOID_POINTER 
TRANSFORMARRAY 

Definition at line 129 of file emobject.h.

00129                                 {
00130                         UNKNOWN,
00131                         BOOL,
00132                         SHORT,
00133                         UNSIGNEDINT,
00134                         INT,
00135                         FLOAT,
00136                         DOUBLE,
00137                         STRING,
00138                         EMDATA,
00139                         XYDATA,
00140                         INTARRAY,
00141                         FLOATARRAY,
00142                         STRINGARRAY,
00143                         TRANSFORM,
00144                         CTF,
00145                         FLOAT_POINTER,
00146                         INT_POINTER,
00147                         VOID_POINTER,
00148                         TRANSFORMARRAY
00149                 };


Constructor & Destructor Documentation

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 135 of file emobject.cpp.

00135                    :
00136         d(0), type(UNKNOWN)
00137 {
00138 #ifdef MEMDEBUG
00139         allemobjlist.insert(this);
00140         printf("  +(%6d) %p\n",(int)allemobjlist.size(),this);
00141 #endif
00142 }

EMObject::EMObject bool  boolean  ) 
 

Definition at line 144 of file emobject.cpp.

References b.

00144                                :
00145         b(boolean), type(BOOL)
00146 {
00147 #ifdef MEMDEBUG
00148         allemobjlist.insert(this);
00149         printf("  +(%6d) %p\n",(int)allemobjlist.size(),this);
00150 #endif
00151 }

EMObject::EMObject short   ) 
 

Definition at line 153 of file emobject.cpp.

00153                              :
00154         si(sint), type(SHORT)
00155 {
00156 #ifdef MEMDEBUG
00157         allemobjlist.insert(this);
00158         printf("  +(%6d) %p\n",(int)allemobjlist.size(),this);
00159 #endif
00160 }

EMObject::EMObject int  num  ) 
 

Definition at line 162 of file emobject.cpp.

00162                           :
00163         n(num), type(INT)
00164 {
00165 #ifdef MEMDEBUG
00166         allemobjlist.insert(this);
00167         printf("  +(%6d) %p\n",(int)allemobjlist.size(),this);
00168 #endif
00169 }

EMObject::EMObject unsigned int  num  ) 
 

Definition at line 171 of file emobject.cpp.

00171                                    :
00172         ui(num), type(UNSIGNEDINT)
00173 {
00174 #ifdef MEMDEBUG
00175         allemobjlist.insert(this);
00176         printf("  +(%6d) %p\n",(int)allemobjlist.size(),this);
00177 #endif
00178 }

EMObject::EMObject float  ff  ) 
 

Definition at line 180 of file emobject.cpp.

References f, and EMAN::Util::goodf().

00180                            :
00181         type(FLOAT)
00182 {
00183 
00184 #ifdef MEMDEBUG
00185         allemobjlist.insert(this);
00186         printf("  +(%6d) %p\n",(int)allemobjlist.size(),this);
00187 #endif
00188         if(Util::goodf(&ff)) {
00189                 f = ff;
00190         }
00191         else{
00192                 f = 0.0f;
00193         }
00194 }

EMObject::EMObject double  dd  ) 
 

Definition at line 196 of file emobject.cpp.

References d, and EMAN::Util::goodf().

00196                             :
00197         type(DOUBLE)
00198 {
00199 
00200 #ifdef MEMDEBUG
00201         allemobjlist.insert(this);
00202         printf("  +(%6d) %p\n",(int)allemobjlist.size(),this);
00203 #endif
00204         if(Util::goodf(&dd)) {
00205                 d = dd;
00206         }
00207         else{
00208                 d = 0.0;
00209         }
00210 }

EMObject::EMObject const char *  s  ) 
 

Definition at line 212 of file emobject.cpp.

00212                                 :
00213         str(s), type(STRING)
00214 {
00215 #ifdef MEMDEBUG
00216         allemobjlist.insert(this);
00217         printf("  +(%6d) %p\n",(int)allemobjlist.size(),this);
00218 #endif
00219 }

EMObject::EMObject const string &  s  ) 
 

Definition at line 221 of file emobject.cpp.

00221                                    :
00222         str(s), type(STRING)
00223 {
00224 #ifdef MEMDEBUG
00225         allemobjlist.insert(this);
00226         printf("  +(%6d) %p\n",(int)allemobjlist.size(),this);
00227 #endif
00228 }

EMObject::EMObject float *  fp  ) 
 

Definition at line 230 of file emobject.cpp.

00230                            :
00231         fp(f), type(FLOAT_POINTER)
00232 {
00233 #ifdef MEMDEBUG
00234         allemobjlist.insert(this);
00235         printf("  +(%6d) %p\n",(int)allemobjlist.size(),this);
00236 #endif
00237 }

EMObject::EMObject int *  ip  ) 
 

Definition at line 239 of file emobject.cpp.

00239                          :
00240         ip(i), type(INT_POINTER)
00241 {
00242 #ifdef MEMDEBUG
00243         allemobjlist.insert(this);
00244         printf("  +(%6d) %p\n",(int)allemobjlist.size(),this);
00245 #endif
00246 }

EMObject::EMObject void *  vp  ) 
 

Definition at line 248 of file emobject.cpp.

References v, and vp.

00248                           :
00249         vp(v), type(VOID_POINTER)
00250 {
00251 #ifdef MEMDEBUG
00252         allemobjlist.insert(this);
00253         printf("  +(%6d) %p\n",(int)allemobjlist.size(),this);
00254 #endif
00255 }

EMObject::EMObject EMData em  ) 
 

Definition at line 257 of file emobject.cpp.

00257                                 :
00258         emdata(em), type(EMDATA)
00259 {
00260 #ifdef MEMDEBUG
00261         allemobjlist.insert(this);
00262         printf("  +(%6d) %p\n",(int)allemobjlist.size(),this);
00263 #endif
00264 }

EMObject::EMObject XYData xy  ) 
 

Definition at line 266 of file emobject.cpp.

00266                               :
00267         xydata(xy), type(XYDATA)
00268 {
00269 #ifdef MEMDEBUG
00270         allemobjlist.insert(this);
00271         printf("  +(%6d) %p\n",(int)allemobjlist.size(),this);
00272 #endif
00273 }

EMObject::EMObject Transform t  ) 
 

Definition at line 275 of file emobject.cpp.

References t.

00275                                :
00276         farray(t->get_matrix()), type(TRANSFORM)
00277 {
00278 #ifdef MEMDEBUG
00279         allemobjlist.insert(this);
00280         printf("  +(%6d) %p\n",(int)allemobjlist.size(),this);
00281 #endif
00282 }

EMObject::EMObject Ctf ctf  ) 
 

Definition at line 284 of file emobject.cpp.

00284                             :
00285         str(ctf->to_string()), type(CTF)
00286 {
00287 #ifdef MEMDEBUG
00288         allemobjlist.insert(this);
00289         printf("  +(%6d) %p\n",(int)allemobjlist.size(),this);
00290 #endif
00291 }

EMObject::EMObject const vector< int > &  v  ) 
 

Definition at line 293 of file emobject.cpp.

References v.

00293                                           :
00294         iarray(v), type(INTARRAY)
00295 {
00296 #ifdef MEMDEBUG
00297         allemobjlist.insert(this);
00298         printf("  +(%6d) %p\n",(int)allemobjlist.size(),this);
00299 #endif
00300 }

EMObject::EMObject const vector< float > &  v  ) 
 

Definition at line 302 of file emobject.cpp.

References v.

00302                                            :
00303         farray(v), type(FLOATARRAY)
00304 {
00305 #ifdef MEMDEBUG
00306         allemobjlist.insert(this);
00307         printf("  +(%6d) %p\n",(int)allemobjlist.size(),this);
00308 #endif
00309 }

EMObject::EMObject const vector< string > &  sarray  ) 
 

Definition at line 311 of file emobject.cpp.

00311                                                 :
00312         strarray(sarray), type(STRINGARRAY)
00313 {
00314 #ifdef MEMDEBUG
00315         allemobjlist.insert(this);
00316         printf("  +(%6d) %p\n",(int)allemobjlist.size(),this);
00317 #endif
00318 }

EMObject::EMObject const vector< Transform > &  tarray  ) 
 

Definition at line 320 of file emobject.cpp.

00320                                                    :
00321         transformarray(tarray), type(TRANSFORMARRAY)
00322 {
00323 #ifdef MEMDEBUG
00324         allemobjlist.insert(this);
00325         printf("  +(%6d) %p\n",(int)allemobjlist.size(),this);
00326 #endif
00327 }

EMObject::EMObject const EMObject that  ) 
 

Copy constructor.

copies pointer locations - does not take ownership deep copies all non pointer objects

Definition at line 950 of file emobject.cpp.

00951 {
00952         // init isn't necessary because that must have already called it!
00953         *this = that;
00954 #ifdef MEMDEBUG
00955         allemobjlist.insert(this);
00956         printf("  +(%6d) %p\n",(int)allemobjlist.size(),this);
00957 #endif
00958 }

EMObject::~EMObject  ) 
 

Desctructor Does not free pointers.

Definition at line 128 of file emobject.cpp.

00128                     {
00129 #ifdef MEMDEBUG
00130         allemobjlist.erase(this);
00131         printf("  -(%6d) %p\n",(int)allemobjlist.size(),this);
00132 #endif
00133 }


Member Function Documentation

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 765 of file emobject.cpp.

References LOGERR, NotExistingObjectException, t, and type_registry.

Referenced by operator bool(), operator const char *(), operator double(), operator EMData *(), operator float(), operator float *(), operator int(), operator int *(), operator short(), operator Transform *(), operator unsigned int(), operator vector(), operator void *(), and operator XYData *().

00766 {
00767 #ifdef _WIN32
00768         if (t == BOOL) {
00769                 return "BOOL";
00770         }else
00771         if ( t == SHORT) {
00772                 return "SHORT";
00773         }else
00774         if ( t == INT){
00775                 return "INT";
00776         }else
00777         if ( t == UNSIGNEDINT){
00778                 return "UNSIGNEDINT";
00779         } else
00780         if ( t == FLOAT){
00781                 return "FLOAT";
00782         } else
00783         if ( t == DOUBLE){
00784                 return "DOUBLE";
00785         }else
00786         if ( t == STRING){
00787                 return "STRING";
00788         }else
00789         if ( t == EMDATA){
00790                 return "EMDATA";
00791         }
00792         else
00793         if ( t == XYDATA){
00794                 return "XYDATA";
00795         }else
00796         if ( t == INTARRAY){
00797                 return "INTARRAY";
00798         }else
00799         if ( t == FLOATARRAY){
00800                 return "FLOATARRAY";
00801         } else
00802         if ( t == STRINGARRAY){
00803                 return "STRINGARRAY";
00804         }else
00805         if ( t == TRANSFORM){
00806                 return "TRANSFORM";
00807         }else
00808         if ( t == TRANSFORMARRAY){
00809                 return "TRANSFORMARRAY";
00810         }
00811         if ( t == CTF){
00812                 return "CTF";
00813         }else
00814         if ( t == FLOAT_POINTER){
00815                 return "FLOAT_POINTER";
00816         }else
00817         if ( t == INT_POINTER){
00818                 return "INT_POINTER";
00819         }else
00820         if ( t == UNKNOWN){
00821                 return "UNKNOWN";
00822         } else
00823         if ( t == VOID_POINTER){
00824                 return "VOID_POINTER";
00825         }
00826         else {
00827                 LOGERR("No such EMObject defined");
00828                 throw NotExistingObjectException("EMObject", "unknown type");
00829         }
00830 
00831 #else
00832 
00833         if  ( type_registry.find(t) != type_registry.end() )
00834                 return type_registry[t];
00835         else
00836                 LOGERR("No such EMObject defined");
00837                 throw NotExistingObjectException("EMObject", "unknown type");
00838 #endif  //_WIN32
00839 }

ObjectType EMAN::EMObject::get_type  )  const [inline]
 

Get the ObjectType This is an enumerated type first declared in the class EMObjectTypes.

Definition at line 228 of file emobject.h.

Referenced by EMAN::EMData::set_attr_python(), EMAN::Transform::set_params(), and EMAN::Transform::set_params_inverse().

00228 { 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 234 of file emobject.h.

00234 { return get_object_type_name(type); }

map< EMObject::ObjectType, string > EMObject::init  )  [static, private]
 

Definition at line 82 of file emobject.cpp.

Referenced by EMAN::EMUtil::getRenderMinMax().

00083 {
00084         map< EMObject::ObjectType, string> mymap;
00085         static bool first_construction = true;
00086         if ( first_construction )
00087         {
00088                 // Initialize the the type registry once and for all
00089                 mymap[BOOL] = "BOOL";
00090                 mymap[SHORT] = "SHORT";
00091                 mymap[INT] = "INT";
00092                 mymap[UNSIGNEDINT] = "UNSIGNEDINT";
00093                 mymap[FLOAT] = "FLOAT";
00094                 mymap[DOUBLE] = "DOUBLE";
00095                 mymap[STRING] = "STRING";
00096                 mymap[EMDATA] = "EMDATA";
00097                 mymap[XYDATA] = "XYDATA";
00098                 mymap[INTARRAY] = "INTARRAY";
00099                 mymap[FLOATARRAY] = "FLOATARRAY";
00100                 mymap[STRINGARRAY] = "STRINGARRAY";
00101                 mymap[TRANSFORM] = "TRANFORM";
00102                 mymap[CTF] = "CTF";
00103                 mymap[FLOAT_POINTER] = "FLOAT_POINTER";
00104                 mymap[INT_POINTER] = "INT_POINTER";
00105                 mymap[UNKNOWN] = "UNKNOWN";
00106                 mymap[VOID_POINTER] = "VOID_POINTER";
00107                 mymap[TRANSFORMARRAY] = "TRANSFORMARRAY";
00108                 first_construction = false;
00109         }
00110         
00111         return mymap;
00112 }

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 683 of file emobject.cpp.

References type.

Referenced by EMAN::EMUtil::dump_dict().

00684 {
00685         return (type == UNKNOWN);
00686 }

EMObject::operator bool  )  const
 

Conversion operators.

Definition at line 329 of file emobject.cpp.

References d, emdata, f, fp, get_object_type_name(), ip, n, si, type, TypeException, ui, vp, and xydata.

00330 {
00331         if (type == BOOL) {
00332                 return b;
00333         }
00334         else if (type == SHORT) {
00335                 return si != 0;
00336         }
00337         else if (type == INT) {
00338                 return n != 0;
00339         }
00340         else if (type == UNSIGNEDINT) {
00341                 return ui != 0;
00342         }
00343         else if (type == FLOAT) {
00344                 return f != 0;
00345         }
00346         else if (type == DOUBLE) {
00347                 return d != 0;
00348         }
00349         else if (type == EMDATA) {
00350                 return emdata != 0;
00351         }
00352         else if (type == XYDATA) {
00353                 return xydata != 0;
00354         }
00355         else if (type == FLOAT_POINTER) {
00356                 return fp != 0;
00357         }
00358         else if (type == INT_POINTER) {
00359                 return ip != 0;
00360         }
00361         else if (type == VOID_POINTER) {
00362                 return vp != 0;
00363         }
00364 //      else if (type == TRANSFORM) {
00365 //              return transform != 0;
00366 //      }
00367         // It seemed unconventional to return a boolean for the stl objects
00368         else {
00369                 if (type != UNKNOWN) {
00370                         throw TypeException("Cannot convert to bool this data type ",
00371                                                                 get_object_type_name(type));
00372                 }
00373         }
00374         return 0;
00375 }

EMObject::operator const char *  )  const
 

Definition at line 537 of file emobject.cpp.

References get_object_type_name(), str, STRING, type, and TypeException.

00538 {
00539         if (type != STRING && type != CTF) {
00540                 stringstream ss;
00541                 string return_string;
00542                 if ( type == INT )
00543                 {
00544                         ss << n;
00545                         ss >> return_string;
00546                         return return_string.c_str();
00547                 }
00548                 if ( type == UNSIGNEDINT )
00549                 {
00550                         ss << ui;
00551                         ss >> return_string;
00552                         return return_string.c_str();
00553                 }
00554                 else
00555                 if ( type == FLOAT )
00556                 {
00557                         ss << f;
00558                         ss >> return_string;
00559                         return return_string.c_str();
00560                 }
00561                 else
00562                 if ( type == DOUBLE )
00563                 {
00564                         ss << d;
00565                         ss >> return_string;
00566                         return return_string.c_str();
00567                 }
00568                 else if (type != UNKNOWN) {
00569                         throw TypeException("Cannot convert to string from this data type",
00570                                                                 get_object_type_name(type));
00571                 }
00572 
00573                 return "";
00574         }
00575         return str.c_str();
00576 }

EMObject::operator Ctf *  )  const
 

Definition at line 615 of file emobject.cpp.

References EMAN::Ctf::from_string(), and str.

00616 {
00617 /*      if(type != CTF) {
00618                 if(type != CTF) {
00619                         throw TypeException("Cannot convert to TRANSFORM* from this data type",
00620                                                                 get_object_type_name(type));
00621                 }
00622         }*/
00623         Ctf * ctf = 0;
00624         if(str[0] == 'O') {
00625                 ctf = new EMAN1Ctf();
00626                 ctf->from_string(str);
00627         }
00628         else if(str[0] == 'E') {
00629                 ctf = new EMAN2Ctf();
00630                 ctf->from_string(str);
00631         }
00632         return ctf;
00633 }

EMObject::operator double  )  const
 

Definition at line 467 of file emobject.cpp.

References b, get_object_type_name(), type, and TypeException.

00468 {
00469         if (type == BOOL) {
00470         return b?1.0:0.0;
00471         }
00472         else if (type == DOUBLE) {
00473                 return d;
00474         }
00475         else if (type == SHORT) {
00476                 return si;
00477         }
00478         else if (type == INT) {
00479                 return (double) n;
00480         }
00481         else if (type == UNSIGNEDINT) {
00482                 return (double) ui;
00483         }
00484         else if (type == FLOAT) {
00485                 return (double) f;
00486         }
00487         else {
00488                 if (type != UNKNOWN) {
00489                         throw TypeException("Cannot convert to double from this data type",
00490                                                                 get_object_type_name(type));
00491                 }
00492         }
00493         return 0;
00494 }

EMObject::operator EMData *  )  const
 

Definition at line 578 of file emobject.cpp.

References get_object_type_name(), type, and TypeException.

00579 {
00580         if (type != EMDATA) {
00581                 if (type != UNKNOWN) {
00582                         throw TypeException("Cannot convert to EMData* from this data type",
00583                                    get_object_type_name(type));
00584                 }
00585                 return 0;
00586         }
00587         return emdata;
00588 }

EMObject::operator float  )  const
 

Definition at line 434 of file emobject.cpp.

References b, get_object_type_name(), str, type, and TypeException.

00435 {
00436         if (type == BOOL) {
00437                 return b?1.0f:0.0f;
00438         }
00439         else if (type == FLOAT) {
00440                 return f;
00441         }
00442         else if (type == SHORT) {
00443                 return si;
00444         }
00445         else if (type == INT) {
00446                 return (float) n;
00447         }
00448         else if (type == UNSIGNEDINT) {
00449                 return (float) ui;
00450         }
00451         else if (type == DOUBLE) {
00452                 return (float) d;
00453         }
00454         else if (type == STRING) {
00455                 return (float)atof(str.c_str());
00456         }
00457         else {
00458                 if (type != UNKNOWN) {
00459                         throw TypeException("Cannot convert to float from this data type",
00460                                                                 get_object_type_name(type));
00461                 }
00462         }
00463 
00464         return 0;
00465 }

EMObject::operator float *  )  const
 

Definition at line 511 of file emobject.cpp.

References get_object_type_name(), type, and TypeException.

00512 {
00513         if (type != FLOAT_POINTER)
00514         {
00515                 if (type != UNKNOWN)
00516                         throw TypeException("Cannot convert to float pointer from this data type",
00517                                                                 get_object_type_name(type));
00518 
00519                 return 0;
00520         }
00521 
00522         return fp;
00523 }

EMObject::operator int  )  const
 

Definition at line 391 of file emobject.cpp.

References b, get_object_type_name(), type, and TypeException.

00392 {
00393         if (type == INT) {
00394                 return n;
00395         }
00396         else if (type == SHORT) {
00397                 return si;
00398         }
00399         else if (type == UNSIGNEDINT) {
00400                 return (int) ui;
00401         }
00402         else if (type == FLOAT) {
00403                 return (int) f;
00404         }
00405         else if (type == DOUBLE) {
00406                 return (int) d;
00407         }
00408         else if (type == BOOL) {
00409                 return b?1:0;
00410         }
00411         else {
00412                 if (type != UNKNOWN) {
00413                         throw TypeException("Cannot convert to int this data type ",
00414                                                                 get_object_type_name(type));
00415                 }
00416         }
00417         return 0;
00418 }

EMObject::operator int *  )  const
 

Definition at line 496 of file emobject.cpp.

References get_object_type_name(), type, and TypeException.

00497 {
00498         if (type != INT_POINTER)
00499         {
00500                 if (type != UNKNOWN)
00501                         throw TypeException("Cannot convert to float pointer from this data type",
00502                                                                 get_object_type_name(type));
00503 
00504                 return 0;
00505         }
00506 
00507         return ip;
00508 }

EMObject::operator short  )  const
 

Definition at line 377 of file emobject.cpp.

References get_object_type_name(), type, and TypeException.

00378 {
00379         if (type == SHORT) {
00380                 return si;
00381         }
00382         else {
00383         if (type != UNKNOWN) {
00384                                 throw TypeException("Cannot convert to int this data type ",
00385                                                                         get_object_type_name(type));
00386                         }
00387         }
00388         return 0;
00389 }

EMObject::operator Transform *  )  const
 

Definition at line 602 of file emobject.cpp.

References farray, get_object_type_name(), EMAN::Transform::set_matrix(), type, and TypeException.

00603 {
00604         if(type != TRANSFORM) {
00605                 if(type != UNKNOWN) {
00606                         throw TypeException("Cannot convert to TRANSFORM* from this data type",
00607                                                                 get_object_type_name(type));
00608                 }
00609         }
00610         Transform * transform = new Transform();
00611         transform->set_matrix(farray);
00612         return transform;
00613 }

EMObject::operator unsigned int  )  const
 

Definition at line 420 of file emobject.cpp.

References get_object_type_name(), type, and TypeException.

00421 {
00422         if (type == UNSIGNEDINT) {
00423                 return (unsigned int) ui;
00424         }
00425         else {
00426                 if (type != UNKNOWN) {
00427                         throw TypeException("Cannot convert to int this data type ",
00428                                                                 get_object_type_name(type));
00429                 }
00430         }
00431         return 0;
00432 }

EMAN::EMObject::operator vector  )  const
 

EMAN::EMObject::operator vector  )  const
 

EMAN::EMObject::operator vector  )  const
 

EMObject::operator vector< Transform >  )  const
 

Definition at line 635 of file emobject.cpp.

References get_object_type_name(), type, and TypeException.

00636 {
00637     if( type != INTARRAY )
00638     {
00639         if( type != UNKNOWN ) {
00640                 throw TypeException("Cannot convert to vector<int> from this data type", get_object_type_name(type) );
00641                 }
00642                 return vector<int>();
00643     }
00644     return iarray;
00645 }

EMObject::operator void *  )  const
 

Definition at line 526 of file emobject.cpp.

References get_object_type_name(), type, TypeException, and vp.

00527 {
00528         if (type == VOID_POINTER) return vp;
00529         else if (type == FLOAT_POINTER) return (void *)fp;
00530         else if (type == INT_POINTER) return (void *)ip;
00531         else if (type == EMDATA) return (void *) emdata;
00532         else if (type == XYDATA) return (void *) xydata;
00533 //      else if (type == TRANSFORM) return (void *) transform;
00534         else throw TypeException("Cannot convert to void pointer from this data type", get_object_type_name(type));
00535 }

EMObject::operator XYData *  )  const
 

Definition at line 590 of file emobject.cpp.

References get_object_type_name(), type, and TypeException.

00591 {
00592         if (type != XYDATA) {
00593                 if (type != UNKNOWN) {
00594                         throw TypeException("Cannot convert to XYData* from this data type",
00595                                    get_object_type_name(type));
00596                 }
00597                 return 0;
00598         }
00599         return xydata;
00600 }

EMObject & EMObject::operator= const EMObject that  ) 
 

Assigment operator copies pointer locations (emdata, xydata, transform) - does not take ownership deep copies all non pointer objects.

Definition at line 964 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, SHORT, si, str, strarray, STRING, STRINGARRAY, TRANSFORM, transformarray, TRANSFORMARRAY, type, ui, UNKNOWN, UNSIGNEDINT, VOID_POINTER, vp, vp, xydata, and XYDATA.

00965 {
00966 
00967 // This test breaks assignment when either the current or assigned values are (float)nan
00968 // it's also somewhat inherently stupid, since testing for equivalence may cost as much
00969 // as assignment.
00970 //      if ( *this != that )
00971         {
00972                 // First store the type of the input, At first I forgot to do this and it was a very
00973                 // difficult bug to track down
00974                 type = that.type;
00975 
00976 //              if ( type != this_type ) throw
00977 
00978 
00979                 switch (type)
00980                 {
00981                 case BOOL:
00982                         b = that.b;
00983                 break;
00984                 case SHORT:
00985                         si = that.si;
00986                 break;
00987                 case INT:
00988                         n = that.n;
00989                 break;
00990                 case UNSIGNEDINT:
00991                         ui = that.ui;
00992                 break;
00993                 case FLOAT:
00994                         f = that.f;
00995                 break;
00996                 case DOUBLE:
00997                         d = that.d;
00998                 break;
00999                 case CTF:
01000                 case STRING:
01001                         str = that.str;
01002                 break;
01003                 case FLOAT_POINTER:
01004                         // Warning - Pointer address copy.
01005                         fp = that.fp;
01006                 break;
01007                 case INT_POINTER:
01008                 // Warning - Pointer address copy.
01009                         ip = that.ip;
01010                 break;
01011                 case VOID_POINTER:
01012                         // Warning - Pointer address copy.
01013                         vp = that.vp;
01014                 break;
01015                 case EMDATA:
01016                         // Warning - Pointer address copy.
01017                         emdata = that.emdata;
01018                 break;
01019                 case XYDATA:
01020                         // Warning - Pointer address copy.
01021                         xydata = that.xydata;
01022                 break;
01023                 case TRANSFORM:
01024                 case FLOATARRAY:
01025                         farray = that.farray;
01026                 break;
01027                 case INTARRAY:
01028                         iarray = that.iarray;
01029                 break;
01030                 case STRINGARRAY:
01031                         strarray = that.strarray;
01032                 break;
01033                 case TRANSFORMARRAY:
01034                         transformarray = that.transformarray;
01035                 break;
01036                 case UNKNOWN:
01037                         // This is possible, nothing should happen
01038                         // The EMObject's default constructor has been called and
01039                         // as yet has no type - doing nothing is exactly as the
01040                         // the assignment operator should work.
01041                 break;
01042                 default:
01043                         LOGERR("No such EMObject defined");
01044                         throw NotExistingObjectException("EMObject", "unknown type");
01045                 break;
01046                 }
01047         }
01048 //      else
01049 //      {
01050 //              cerr << "Warning - attempt to assign EMObject onto itself. No action taken" << endl;
01051 //              cerr << "My type is " << get_object_type_name(type) << endl;
01052 //      }
01053 
01054         return *this;
01055 }

void EMObject::printInfo  )  const [private]
 

A debug function that prints as much information as possibe to cout.

Definition at line 116 of file emobject.cpp.

References to_str(), type, and type_registry.

00117 {
00118         cout << "The address of my type is " << &type << endl;
00119         cout << " Now printing the enumerated values in type_registry " << endl;
00120         for( map< ObjectType, string>::const_iterator it = type_registry.begin(); it != type_registry.end(); ++it )
00121         {
00122                 cout << it->first << " " << it->second << endl;
00123         }
00124         cout << "My type is " << to_str(type) << " and its enumerated value is " << type << endl;
00125         cout << "The address of the static type registry is " << &type_registry <<", it should be same for all EMObjects" << endl;
00126 }

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 693 of file emobject.cpp.

References d, f, LOGERR, n, NotExistingObjectException, si, and ui.

00694 {
00695         if (argtype == STRING) {
00696                 return str;
00697         }
00698         else {
00699                 char tmp_str[32];
00700                 if (argtype == BOOL) {
00701                         if (b)
00702                                 sprintf(tmp_str, "true");
00703                         else
00704                                 sprintf(tmp_str, "false");
00705                 }
00706                 else if (argtype == SHORT) {
00707                         sprintf(tmp_str, "%hd", si);
00708                 }
00709                 else if (argtype == INT) {
00710                         sprintf(tmp_str, "%d", n);
00711                 }
00712                 else if (argtype == UNSIGNEDINT) {
00713                         sprintf(tmp_str, "%d", ui);
00714                 }
00715                 else if (argtype == FLOAT) {
00716                         sprintf(tmp_str, "%f", f);
00717                 }
00718                 else if (argtype == DOUBLE) {
00719                         sprintf(tmp_str, "%f", d);
00720                 }
00721                 else if (argtype == EMDATA) {
00722                         sprintf(tmp_str, "EMDATA");
00723                 }
00724                 else if (argtype == FLOAT_POINTER) {
00725                         sprintf(tmp_str, "FLOAT_POINTER");
00726                 }
00727                 else if (argtype == INT) {
00728                         sprintf(tmp_str, "INT_POINTER");
00729                 }
00730                 else if (argtype == VOID_POINTER) {
00731                         sprintf(tmp_str, "VOID_POINTER");
00732                 }
00733                 else if (argtype == XYDATA) {
00734                         sprintf(tmp_str, "XYDATA");
00735                 }
00736                 else if (argtype == INTARRAY) {
00737                         sprintf(tmp_str, "INTARRAY");
00738                 }
00739                 else if (argtype == FLOATARRAY) {
00740                         sprintf(tmp_str, "FLOATARRAY");
00741                 }
00742                 else if (argtype == STRINGARRAY) {
00743                         sprintf(tmp_str, "STRINGARRAY");
00744                 }
00745                 else if (argtype == TRANSFORM) {
00746                         sprintf(tmp_str, "TRANSFORM");
00747                 }
00748                 else if (argtype == TRANSFORMARRAY) {
00749                         sprintf(tmp_str, "TRANSFORMARRAY");
00750                 }
00751                 else if (argtype == CTF) {
00752                         sprintf(tmp_str, "CTF");
00753                 }
00754                 else if (argtype == UNKNOWN) {
00755                         sprintf(tmp_str, "UNKNOWN");
00756                 }
00757                 else {
00758                         LOGERR("No such EMObject defined");
00759                         throw NotExistingObjectException("EMObject", "unknown type");
00760                 }
00761                 return string(tmp_str);
00762         }
00763 }

string EMObject::to_str  )  const
 

Calls to_str( this->type).

Definition at line 688 of file emobject.cpp.

References type.

Referenced by EMAN::EMUtil::dump_dict(), and printInfo().

00689 {
00690         return to_str(type);
00691 }


Friends And Related Function Documentation

bool operator!= const EMObject e1,
const EMObject e2
[friend]
 

Friend declaration operator!= namespace EMAN2 operator!= accesses private variables.

bool operator== const EMObject e1,
const EMObject e2
[friend]
 

Friend declaration operator== namespace EMAN2 operator== accesses private variables.


Member Data Documentation

bool EMAN::EMObject::b [private]
 

Definition at line 262 of file emobject.h.

Referenced by operator double(), operator float(), operator int(), operator=(), and EMAN::operator==().

double EMAN::EMObject::d [private]
 

Definition at line 267 of file emobject.h.

Referenced by EMObject(), operator bool(), operator=(), EMAN::operator==(), and to_str().

EMData* EMAN::EMObject::emdata [private]
 

Definition at line 271 of file emobject.h.

Referenced by operator bool(), operator=(), and EMAN::operator==().

float EMAN::EMObject::f [private]
 

Definition at line 266 of file emobject.h.

Referenced by EMAN::TomoAverager::add_image(), EMAN::EMData::calc_az_dist(), EMAN::EMData::calc_center_density(), EMAN::EMData::calc_radial_dist(), EMAN::FRCCmp::cmp(), EMAN::PhaseCmp::cmp(), EMObject(), EMAN::Util::hans(), EMAN::EMData::insert_rect_slice_ctf(), EMAN::EMData::insert_rect_slice_ctf_applied(), EMAN::PointArray::match_points(), operator bool(), operator=(), EMAN::operator==(), EMAN::Util::pad(), EMAN::ToMassCenterProcessor::process_inplace(), and to_str().

vector<float> EMAN::EMObject::farray [private]
 

Definition at line 277 of file emobject.h.

Referenced by operator Transform *(), operator=(), and EMAN::operator==().

float* EMAN::EMObject::fp [private]
 

Definition at line 268 of file emobject.h.

Referenced by operator bool(), operator=(), and EMAN::operator==().

vector<int> EMAN::EMObject::iarray [private]
 

Definition at line 276 of file emobject.h.

Referenced by operator=(), and EMAN::operator==().

int* EMAN::EMObject::ip [private]
 

Definition at line 269 of file emobject.h.

Referenced by operator bool(), operator=(), and EMAN::operator==().

int EMAN::EMObject::n [private]
 

Definition at line 264 of file emobject.h.

Referenced by operator bool(), operator=(), EMAN::operator==(), and to_str().

short EMAN::EMObject::si [private]
 

Definition at line 263 of file emobject.h.

Referenced by operator bool(), operator=(), EMAN::operator==(), and to_str().

string EMAN::EMObject::str [private]
 

Definition at line 275 of file emobject.h.

Referenced by operator const char *(), operator Ctf *(), operator float(), operator=(), and EMAN::operator==().

vector<string> EMAN::EMObject::strarray [private]
 

Definition at line 278 of file emobject.h.

Referenced by operator=(), and EMAN::operator==().

vector<Transform> EMAN::EMObject::transformarray [private]
 

Definition at line 279 of file emobject.h.

Referenced by operator=(), and EMAN::operator==().

ObjectType EMAN::EMObject::type [private]
 

Definition at line 280 of file emobject.h.

Referenced by is_null(), operator bool(), operator const char *(), operator double(), operator EMData *(), operator float(), operator float *(), operator int(), operator int *(), operator short(), 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]
 

Definition at line 79 of file emobject.cpp.

Referenced by get_object_type_name(), and printInfo().

unsigned int EMAN::EMObject::ui [private]
 

Definition at line 265 of file emobject.h.

Referenced by operator bool(), operator=(), EMAN::operator==(), and to_str().

void* EMAN::EMObject::vp [private]
 

Definition at line 270 of file emobject.h.

Referenced by operator=(), and EMAN::operator==().

XYData* EMAN::EMObject::xydata [private]
 

Definition at line 272 of file emobject.h.

Referenced by operator bool(), operator=(), and EMAN::operator==().


The documentation for this class was generated from the following files:
Generated on Tue Jun 11 13:48:02 2013 for EMAN2 by  doxygen 1.3.9.1