EMAN::GatanDM4::TagTable Class Reference

#include <dm4io.h>

List of all members.

Public Member Functions

 TagTable ()
 ~TagTable ()
void add (const string &name, const string &value)
void add_data (char *data)
string get_string (const string &name)
int get_int (const string &name)
float get_float (const string &name)
double get_double (const string &name)
int get_xsize () const
int get_ysize () const
int get_datatype () const
char * get_data () const
void dump () const
template<class T>
void become_host_endian (T *data, int n=1)
void set_endian (bool big_endian)

Private Member Functions

void set_thumb_index (int i)

Private Attributes

int img_index
bool is_big_endian
std::map< string, string > tags
vector< int > x_list
vector< int > y_list
vector< int > datatype_list
vector< char * > data_list

Static Private Attributes

static const char * IMAGE_WIDTH_TAG = "Dimensions #0"
static const char * IMAGE_HEIGHT_TAG = "Dimensions #1"
static const char * IMAGE_DATATYPE_TAG = "DataType"
static const char * IMAGE_THUMB_INDEX_TAG = "ImageIndex"


Detailed Description

Definition at line 45 of file dm4io.h.


Constructor & Destructor Documentation

TagTable::TagTable (  ) 

Definition at line 49 of file dm4io.cpp.

00050         :       img_index(0), is_big_endian(true)
00051 {
00052 }

TagTable::~TagTable (  ) 

Definition at line 54 of file dm4io.cpp.

References data_list.

00055 {
00056         for (unsigned int i = 0; i < data_list.size(); i++) {
00057                 if (data_list[i]) {
00058                         delete[]data_list[i];
00059                         data_list[i] = 0;
00060                 }
00061         }
00062 }


Member Function Documentation

void TagTable::add ( const string &  name,
const string &  value 
)

Definition at line 65 of file dm4io.cpp.

References datatype_list, IMAGE_DATATYPE_TAG, IMAGE_HEIGHT_TAG, IMAGE_THUMB_INDEX_TAG, IMAGE_WIDTH_TAG, set_thumb_index(), tags, x_list, and y_list.

Referenced by EMAN::GatanDM4::TagData::read_any(), EMAN::GatanDM4::TagData::read_array_data(), and EMAN::GatanDM4::TagData::read_native().

00066 {
00067         const char *value_str = value.c_str();
00068 
00069         if (name == IMAGE_WIDTH_TAG) {
00070                 x_list.push_back(atoi(value_str));
00071         }
00072         else if (name == IMAGE_HEIGHT_TAG) {
00073                 y_list.push_back(atoi(value_str));
00074         }
00075         else if (name == IMAGE_DATATYPE_TAG) {
00076                 datatype_list.push_back(atoi(value_str));
00077         }
00078         else if (name == IMAGE_THUMB_INDEX_TAG) {
00079                 set_thumb_index(atoi(value_str));
00080         }
00081         else {
00082                 tags[name] = value;
00083         }
00084 }

void TagTable::add_data ( char *  data  ) 

Definition at line 86 of file dm4io.cpp.

References data_list, and NullPointerException.

Referenced by EMAN::GatanDM4::TagData::read_array_data().

00087 {
00088         if (!data) {
00089                 throw NullPointerException("DM4 data is NULL");
00090         }
00091         else {
00092                 data_list.push_back(data);
00093         }
00094 }

template<class T>
void EMAN::GatanDM4::TagTable::become_host_endian ( T *  data,
int  n = 1 
) [inline]

Definition at line 66 of file dm4io.h.

References is_big_endian, EMAN::ByteOrder::is_host_big_endian(), and EMAN::ByteOrder::swap_bytes().

Referenced by EMAN::GatanDM4::TagData::read_array_data(), EMAN::GatanDM4::TagData::read_native(), and EMAN::GatanDM4::TagData::read_string().

00066                                                                                           {
00067                                 if (is_big_endian != ByteOrder::is_host_big_endian()) {
00068                                         ByteOrder::swap_bytes(data, n);
00069                                 }
00070                         }

void TagTable::dump (  )  const

Definition at line 116 of file dm4io.cpp.

References tags.

00117 {
00118         map < string, string >::const_iterator p;
00119 
00120         for (p = tags.begin(); p != tags.end(); p++) {
00121 //              LOGDEBUG("  %s: %s", (*p).first.c_str(), (*p).second.c_str());
00122                 printf("  %s: %s\n", (*p).first.c_str(), (*p).second.c_str());
00123         }
00124 }

char * TagTable::get_data (  )  const

Definition at line 141 of file dm4io.cpp.

References data_list, and img_index.

00142 {
00143         return data_list[img_index];
00144 }

int TagTable::get_datatype (  )  const

Definition at line 136 of file dm4io.cpp.

References datatype_list, and img_index.

00137 {
00138         return datatype_list[img_index];
00139 }

double TagTable::get_double ( const string &  name  ) 

Definition at line 111 of file dm4io.cpp.

References tags.

00112 {
00113         return atof(tags[name].c_str());
00114 }

float TagTable::get_float ( const string &  name  ) 

Definition at line 106 of file dm4io.cpp.

References tags.

00107 {
00108         return static_cast < float >(atof(tags[name].c_str()));
00109 }

int TagTable::get_int ( const string &  name  ) 

Definition at line 101 of file dm4io.cpp.

References tags.

00102 {
00103         return atoi(tags[name].c_str());
00104 }

string TagTable::get_string ( const string &  name  ) 

Definition at line 96 of file dm4io.cpp.

References tags.

00097 {
00098         return tags[name];
00099 }

int TagTable::get_xsize (  )  const

Definition at line 126 of file dm4io.cpp.

References img_index, and x_list.

00127 {
00128         return x_list[img_index];
00129 }

int TagTable::get_ysize (  )  const

Definition at line 131 of file dm4io.cpp.

References img_index, and y_list.

00132 {
00133         return y_list[img_index];
00134 }

void EMAN::GatanDM4::TagTable::set_endian ( bool  big_endian  )  [inline]

Definition at line 72 of file dm4io.h.

References is_big_endian.

00073                         {
00074                                 is_big_endian = big_endian;
00075                         }

void TagTable::set_thumb_index ( int  i  )  [private]

Definition at line 146 of file dm4io.cpp.

References img_index, and OutofRangeException.

Referenced by add().

00147 {
00148         if (i != 0 && i != 1) {
00149                 throw OutofRangeException(0, 1, i, "image index");
00150         }
00151         else {
00152                 if (i == 0) {
00153                         img_index = 1;
00154                 }
00155                 else {
00156                         img_index = 0;
00157                 }
00158         }
00159 }


Member Data Documentation

vector< char *> EMAN::GatanDM4::TagTable::data_list [private]

Definition at line 91 of file dm4io.h.

Referenced by add_data(), get_data(), and ~TagTable().

vector< int > EMAN::GatanDM4::TagTable::datatype_list [private]

Definition at line 90 of file dm4io.h.

Referenced by add(), and get_datatype().

const char * TagTable::IMAGE_DATATYPE_TAG = "DataType" [static, private]

Definition at line 80 of file dm4io.h.

Referenced by add().

const char * TagTable::IMAGE_HEIGHT_TAG = "Dimensions #1" [static, private]

Definition at line 79 of file dm4io.h.

Referenced by add().

const char * TagTable::IMAGE_THUMB_INDEX_TAG = "ImageIndex" [static, private]

Definition at line 81 of file dm4io.h.

Referenced by add().

const char * TagTable::IMAGE_WIDTH_TAG = "Dimensions #0" [static, private]

Definition at line 78 of file dm4io.h.

Referenced by add().

int EMAN::GatanDM4::TagTable::img_index [private]

Definition at line 85 of file dm4io.h.

Referenced by get_data(), get_datatype(), get_xsize(), get_ysize(), and set_thumb_index().

bool EMAN::GatanDM4::TagTable::is_big_endian [private]

Definition at line 86 of file dm4io.h.

Referenced by become_host_endian(), and set_endian().

std::map< string, string > EMAN::GatanDM4::TagTable::tags [private]

Definition at line 87 of file dm4io.h.

Referenced by add(), dump(), get_double(), get_float(), get_int(), and get_string().

vector< int > EMAN::GatanDM4::TagTable::x_list [private]

Definition at line 88 of file dm4io.h.

Referenced by add(), and get_xsize().

vector< int > EMAN::GatanDM4::TagTable::y_list [private]

Definition at line 89 of file dm4io.h.

Referenced by add(), and get_ysize().


The documentation for this class was generated from the following files:
Generated on Tue Jun 11 12:45:38 2013 for EMAN2 by  doxygen 1.4.7