EMAN2
Public Types | Public Member Functions | Private Attributes | List of all members
EMAN::GatanDM4::TagEntry Class Reference

#include <dm4io.h>

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

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 158 of file dm4io.h.

Member Enumeration Documentation

◆ EntryType

Enumerator
GROUP_TAG 
DATA_TAG 

Definition at line 161 of file dm4io.h.

162 {
163 GROUP_TAG = 20,
164 DATA_TAG = 21
165 };

Constructor & Destructor Documentation

◆ TagEntry()

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

Definition at line 587 of file dm4io.cpp.

588 : in(data_file), tagtable(table), parent_group(parent), name("")
589{
590}
TagTable * tagtable
Definition: dm4io.h:174
TagGroup * parent_group
Definition: dm4io.h:175

◆ ~TagEntry()

TagEntry::~TagEntry ( )

Definition at line 592 of file dm4io.cpp.

593{
594}

Member Function Documentation

◆ read_tag_entry()

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

Definition at line 596 of file dm4io.cpp.

597{
598 LOGVAR("TagEntry::read_tag_entry()");
599 int err = 0;
600 long long pos = 0;
601 char tagtype = 0;
602 char *tmp_name = 0;
603
604 pos = ftell(in);
605 size_t nr;
606 nr = fread(&tagtype, sizeof(char), 1, in); nr++;
607
608 if (tagtype != GROUP_TAG && tagtype != DATA_TAG) {
609 portable_fseek(in, sizeof(char) * 7, SEEK_CUR);
610 nr = fread(&tagtype, sizeof(char), 1, in); nr++;
611 }
612
613 if (tagtype != GROUP_TAG && tagtype != DATA_TAG) {
614 tagtype = fgetc(in);
615 if (tagtype == EOF)
616 {
617 return 1;
618 }
619 else{
620 LOGERR("TagEntry::read_tag_entry() invalid tag type: %d @ position %lld", tagtype, pos);
621 return 1;
622 }
623 }
624
625 short name_len = 0;
626 nr = fread(&name_len, sizeof(short), 1, in); nr++;
627
629
630 if (name_len != 0) {
631 tmp_name = new char[name_len + 1];
632 nr = fread(tmp_name, name_len, 1, in); nr++;
633 tmp_name[name_len] = '\0';
634 }
635 else {
636 string parent_name = parent_group->get_name();
637 name_len = static_cast < short >(parent_name.size() + 4);
638 tmp_name = new char[name_len + 1];
639 sprintf(tmp_name, "%s #%d", parent_name.c_str(), parent_group->get_entry_id());
640 }
641
642 name = string(tmp_name);
643
644 if (tmp_name) {
645 delete [] tmp_name;
646 tmp_name = NULL;
647 }
648
649 LOGVAR("\ntag name: '%s', len: %d, type: '%s'",
650 name.c_str(), name_len, GatanDM4::to_str((EntryType) tagtype));
651
652 if (tagtype == DATA_TAG) {
653 TagData tag_data(in, tagtable, name);
654 err = tag_data.read_tag_data(nodata, image_index, num_images);
655 }
656 else if (tagtype == GROUP_TAG) {
657 long long tot_size = 0; //size of DataType record + size of data
658 nr = fread(&tot_size, sizeof(long long), 1, in); nr++;
660
661 TagGroup group(in, tagtable, name);
662 err = group.read_tag_group(nodata, image_index, num_images);
663 }
664
665/*
666 long long tot_size = 0; //size of DataType record + size of data
667 nr = fread(&tot_size, sizeof(long long), 1, in); nr++;
668*/
669 return err;
670}
static void become_big_endian(T *data, size_t n=1)
convert data from host byte order to big endian order.
Definition: byteorder.h:112
string get_name() const
Definition: dm4io.cpp:728
#define LOGERR
Definition: log.h:51
#define LOGVAR
Definition: log.h:57
const char * to_str(GatanDM4::TagData::Type type)
Definition: dm4io.cpp:1083
int portable_fseek(FILE *fp, off_t offset, int whence)

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().

Member Data Documentation

◆ in

FILE* EMAN::GatanDM4::TagEntry::in
private

Definition at line 173 of file dm4io.h.

Referenced by read_tag_entry().

◆ name

string EMAN::GatanDM4::TagEntry::name
private

Definition at line 176 of file dm4io.h.

Referenced by read_tag_entry().

◆ parent_group

TagGroup* EMAN::GatanDM4::TagEntry::parent_group
private

Definition at line 175 of file dm4io.h.

Referenced by read_tag_entry().

◆ tagtable

TagTable* EMAN::GatanDM4::TagEntry::tagtable
private

Definition at line 174 of file dm4io.h.

Referenced by read_tag_entry().


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