EMAN2
Public Member Functions | Private Member Functions | Private Attributes | Static Private Attributes | List of all members
EMAN::Gatan::TagTable Class Reference

#include <dm3io.h>

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 44 of file dm3io.h.

Constructor & Destructor Documentation

◆ TagTable()

TagTable::TagTable ( )

Definition at line 46 of file dm3io.cpp.

47 : img_index(0), is_big_endian(true)
48{
49}

◆ ~TagTable()

TagTable::~TagTable ( )

Definition at line 51 of file dm3io.cpp.

52{
53 for (unsigned int i = 0; i < data_list.size(); i++) {
54 if (data_list[i]) {
55 delete [] data_list[i];
56 data_list[i] = 0;
57 }
58 }
59}
vector< char * > data_list
Definition: dm3io.h:90

References data_list.

Member Function Documentation

◆ add()

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

Definition at line 61 of file dm3io.cpp.

62{
63 const char *value_str = value.c_str();
64
65 if (name == IMAGE_WIDTH_TAG) {
66 x_list.push_back(atoi(value_str));
67 }
68 else if (name == IMAGE_HEIGHT_TAG) {
69 y_list.push_back(atoi(value_str));
70 }
71 else if (name == IMAGE_DATATYPE_TAG) {
72 datatype_list.push_back(atoi(value_str));
73 }
74 else if (name == IMAGE_THUMB_INDEX_TAG) {
75 set_thumb_index(atoi(value_str));
76 }
77 else {
78 tags[name] = value;
79 }
80}
vector< int > x_list
Definition: dm3io.h:87
static const char * IMAGE_HEIGHT_TAG
Definition: dm3io.h:78
vector< int > datatype_list
Definition: dm3io.h:89
static const char * IMAGE_THUMB_INDEX_TAG
Definition: dm3io.h:80
static const char * IMAGE_WIDTH_TAG
Definition: dm3io.h:77
void set_thumb_index(int i)
Definition: dm3io.cpp:142
vector< int > y_list
Definition: dm3io.h:88
static const char * IMAGE_DATATYPE_TAG
Definition: dm3io.h:79
std::map< string, string > tags
Definition: dm3io.h:86

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::Gatan::TagData::read_any(), EMAN::Gatan::TagData::read_array_data(), and EMAN::Gatan::TagData::read_native().

◆ add_data()

void TagTable::add_data ( char *  data)

Definition at line 82 of file dm3io.cpp.

83{
84 if (!data) {
85 throw NullPointerException("DM3 data is NULL");
86 }
87 else {
88 data_list.push_back(data);
89 }
90}
#define NullPointerException(desc)
Definition: exception.h:241

References data_list, and NullPointerException.

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

◆ become_host_endian()

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

Definition at line 65 of file dm3io.h.

65 {
67 ByteOrder::swap_bytes(data, n);
68 }
69 }
static bool is_host_big_endian()
Definition: byteorder.cpp:40
static void swap_bytes(T *data, size_t n=1)
swap the byte order of data with 'n' T-type elements.
Definition: byteorder.h:131

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

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

◆ dump()

void TagTable::dump ( ) const

Definition at line 112 of file dm3io.cpp.

113{
114 map < string, string >::const_iterator p;
115
116 for (p = tags.begin(); p != tags.end(); p++) {
117// LOGDEBUG(" %s: %s", (*p).first.c_str(), (*p).second.c_str());
118 printf(" %s: %s\n", (*p).first.c_str(), (*p).second.c_str());
119 }
120}

References tags.

◆ get_data()

char * TagTable::get_data ( ) const

Definition at line 137 of file dm3io.cpp.

138{
139 return data_list[img_index];
140}

References data_list, and img_index.

◆ get_datatype()

int TagTable::get_datatype ( ) const

Definition at line 132 of file dm3io.cpp.

133{
134 return datatype_list[img_index];
135}

References datatype_list, and img_index.

◆ get_double()

double TagTable::get_double ( const string &  name)

Definition at line 107 of file dm3io.cpp.

108{
109 return atof(tags[name].c_str());
110}

References tags.

◆ get_float()

float TagTable::get_float ( const string &  name)

Definition at line 102 of file dm3io.cpp.

103{
104 return static_cast < float >(atof(tags[name].c_str()));
105}

References tags.

◆ get_int()

int TagTable::get_int ( const string &  name)

Definition at line 97 of file dm3io.cpp.

98{
99 return atoi(tags[name].c_str());
100}

References tags.

◆ get_string()

string TagTable::get_string ( const string &  name)

Definition at line 92 of file dm3io.cpp.

93{
94 return tags[name];
95}

References tags.

◆ get_xsize()

int TagTable::get_xsize ( ) const

Definition at line 122 of file dm3io.cpp.

123{
124 return x_list[img_index];
125}

References img_index, and x_list.

◆ get_ysize()

int TagTable::get_ysize ( ) const

Definition at line 127 of file dm3io.cpp.

128{
129 return y_list[img_index];
130}

References img_index, and y_list.

◆ set_endian()

void EMAN::Gatan::TagTable::set_endian ( bool  big_endian)
inline

Definition at line 71 of file dm3io.h.

72 {
73 is_big_endian = big_endian;
74 }

References is_big_endian.

◆ set_thumb_index()

void TagTable::set_thumb_index ( int  i)
private

Definition at line 142 of file dm3io.cpp.

143{
144 if (i != 0 && i != 1) {
145 throw OutofRangeException(0, 1, i, "image index");
146 }
147 else {
148 if (i == 0) {
149 img_index = 1;
150 }
151 else {
152 img_index = 0;
153 }
154 }
155}
#define OutofRangeException(low, high, input, objname)
Definition: exception.h:334

References img_index, and OutofRangeException.

Referenced by add().

Member Data Documentation

◆ data_list

vector< char *> EMAN::Gatan::TagTable::data_list
private

Definition at line 90 of file dm3io.h.

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

◆ datatype_list

vector< int > EMAN::Gatan::TagTable::datatype_list
private

Definition at line 89 of file dm3io.h.

Referenced by add(), and get_datatype().

◆ IMAGE_DATATYPE_TAG

const char * TagTable::IMAGE_DATATYPE_TAG = "DataType"
staticprivate

Definition at line 79 of file dm3io.h.

Referenced by add().

◆ IMAGE_HEIGHT_TAG

const char * TagTable::IMAGE_HEIGHT_TAG = "Dimensions #1"
staticprivate

Definition at line 78 of file dm3io.h.

Referenced by add().

◆ IMAGE_THUMB_INDEX_TAG

const char * TagTable::IMAGE_THUMB_INDEX_TAG = "ImageIndex"
staticprivate

Definition at line 80 of file dm3io.h.

Referenced by add().

◆ IMAGE_WIDTH_TAG

const char * TagTable::IMAGE_WIDTH_TAG = "Dimensions #0"
staticprivate

Definition at line 77 of file dm3io.h.

Referenced by add().

◆ img_index

int EMAN::Gatan::TagTable::img_index
private

Definition at line 84 of file dm3io.h.

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

◆ is_big_endian

bool EMAN::Gatan::TagTable::is_big_endian
private

Definition at line 85 of file dm3io.h.

Referenced by become_host_endian(), and set_endian().

◆ tags

std::map< string, string > EMAN::Gatan::TagTable::tags
private

Definition at line 86 of file dm3io.h.

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

◆ x_list

vector< int > EMAN::Gatan::TagTable::x_list
private

Definition at line 87 of file dm3io.h.

Referenced by add(), and get_xsize().

◆ y_list

vector< int > EMAN::Gatan::TagTable::y_list
private

Definition at line 88 of file dm3io.h.

Referenced by add(), and get_ysize().


The documentation for this class was generated from the following files: