EMAN2
Public Types | Public Member Functions | Private Attributes
EMAN::GatanDM4::TagEntry Class Reference

#include <dm4io.h>

Collaboration diagram for EMAN::GatanDM4::TagEntry:
Collaboration graph
[legend]

List of all members.

Public Types

enum  EntryType { GROUP_TAG = 20, DATA_TAG = 21 }

Public Member Functions

 TagEntry (FILE *data_file, TagTable *tagtable, TagGroup *parent_group)
 ~TagEntry ()
int read_tag_entry (bool nodata=false, int image_index=0, int num_images=1)

Private Attributes

FILE * in
TagTabletagtable
TagGroupparent_group
string name

Detailed Description

Definition at line 162 of file dm4io.h.


Member Enumeration Documentation

Enumerator:
GROUP_TAG 
DATA_TAG 

Definition at line 165 of file dm4io.h.

                        {
                                GROUP_TAG = 20,
                                DATA_TAG = 21
                        };

Constructor & Destructor Documentation

TagEntry::TagEntry ( FILE *  data_file,
TagTable tagtable,
TagGroup parent_group 
)

Definition at line 591 of file dm4io.cpp.

        :       in(data_file), tagtable(table), parent_group(parent), name("")
{
}
TagEntry::~TagEntry ( )

Definition at line 596 of file dm4io.cpp.

{
}

Member Function Documentation

int TagEntry::read_tag_entry ( bool  nodata = false,
int  image_index = 0,
int  num_images = 1 
)

Definition at line 600 of file dm4io.cpp.

References EMAN::ByteOrder::become_big_endian(), DATA_TAG, EMAN::GatanDM4::TagGroup::get_entry_id(), EMAN::GatanDM4::TagGroup::get_name(), GROUP_TAG, in, LOGERR, LOGVAR, name, parent_group, portable_fseek(), EMAN::GatanDM4::TagData::read_tag_data(), EMAN::GatanDM4::TagGroup::read_tag_group(), tagtable, and EMAN::GatanDM4::to_str().

Referenced by EMAN::GatanDM4::TagGroup::read_tag_group().

{
        LOGVAR("TagEntry::read_tag_entry()");
        int err = 0;
        long long pos = 0;
        char tagtype = 0;
        char *tmp_name = 0;

        pos = ftell(in);
        size_t nr;
        nr = fread(&tagtype, sizeof(char), 1, in);

        if (tagtype != GROUP_TAG && tagtype != DATA_TAG) {
                portable_fseek(in, sizeof(char) * 7, SEEK_CUR);
                nr = fread(&tagtype, sizeof(char), 1, in);
        }

        if (tagtype != GROUP_TAG && tagtype != DATA_TAG) {
                tagtype = fgetc(in);
                if (tagtype == EOF)
                {
                        return 1;
                }
                else{
                        LOGERR("TagEntry::read_tag_entry() invalid tag type: %d @ position %lld", tagtype, pos);
                        return 1;
                }
        }

        short name_len = 0;
        nr = fread(&name_len, sizeof(short), 1, in);

        ByteOrder::become_big_endian(&name_len);

        if (name_len != 0) {
                tmp_name = new char[name_len + 1];
                nr = fread(tmp_name, name_len, 1, in);
                tmp_name[name_len] = '\0';
        }
        else {
                string parent_name = parent_group->get_name();
                name_len = static_cast < short >(parent_name.size() + 4);
                tmp_name = new char[name_len + 1];
                sprintf(tmp_name, "%s #%d", parent_name.c_str(), parent_group->get_entry_id());
        }

        name = string(tmp_name);

        if (tmp_name) {
                delete [] tmp_name;
                tmp_name = NULL;
        }

        LOGVAR("\ntag name: '%s', len: %d, type: '%s'",
                   name.c_str(), name_len, GatanDM4::to_str((EntryType) tagtype));

        if (tagtype == DATA_TAG) {
                TagData tag_data(in, tagtable, name);
                err = tag_data.read_tag_data(nodata, image_index, num_images);
        }
        else if (tagtype == GROUP_TAG) {
                long long tot_size = 0; //size of DataType record + size of data
                nr = fread(&tot_size, sizeof(long long), 1, in);
                ByteOrder::become_big_endian(&tot_size);

                TagGroup group(in, tagtable, name);
                err = group.read_tag_group(nodata, image_index, num_images);
        }

/*
        long long tot_size = 0; //size of DataType record + size of data
        nr = fread(&tot_size, sizeof(long long), 1, in);
*/
        return err;
}

Member Data Documentation

Definition at line 177 of file dm4io.h.

Referenced by read_tag_entry().

Definition at line 180 of file dm4io.h.

Referenced by read_tag_entry().

Definition at line 179 of file dm4io.h.

Referenced by read_tag_entry().

Definition at line 178 of file dm4io.h.

Referenced by read_tag_entry().


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