X-Git-Url: https://git.creatis.insa-lyon.fr/pubgit/?a=blobdiff_plain;f=src%2FgdcmSeqEntry.cxx;h=fb0dfdfc2110af4526b38cd02d1ae2f2637a54ec;hb=a716f958bd2a6105ac06997fa9509ebaad6fc285;hp=9e510814df433678865a4f339247394f51e68858;hpb=d1c68c2c2ae9fadf927053150f7fbc625a7c7366;p=gdcm.git diff --git a/src/gdcmSeqEntry.cxx b/src/gdcmSeqEntry.cxx index 9e510814..fb0dfdfc 100644 --- a/src/gdcmSeqEntry.cxx +++ b/src/gdcmSeqEntry.cxx @@ -3,8 +3,8 @@ Program: gdcm Module: $RCSfile: gdcmSeqEntry.cxx,v $ Language: C++ - Date: $Date: 2005/02/01 10:29:56 $ - Version: $Revision: 1.52 $ + Date: $Date: 2005/11/07 09:46:36 $ + Version: $Revision: 1.62 $ Copyright (c) CREATIS (Centre de Recherche et d'Applications en Traitement de l'Image). All rights reserved. See Doc/License.txt or @@ -46,7 +46,7 @@ SeqEntry::SeqEntry( DictEntry *e ) } /** - * \brief Constructor from a given SeqEntry + * \brief Constructor from a given DocEntry * @param e Pointer to existing Doc entry * @param depth depth level of the current Seq entry */ @@ -67,14 +67,7 @@ SeqEntry::SeqEntry( DocEntry *e, int depth ) */ SeqEntry::~SeqEntry() { - for(ListSQItem::iterator cc = Items.begin(); cc != Items.end(); ++cc) - { - delete *cc; - } - if (SeqTerm) - { - delete SeqTerm; - } + ClearSQItem(); } //----------------------------------------------------------------------------- @@ -89,10 +82,11 @@ void SeqEntry::WriteContent(std::ofstream *fp, FileType filetype) uint16_t seq_term_gr = 0xfffe; uint16_t seq_term_el = 0xe0dd; uint32_t seq_term_lg = 0xffffffff; - - //uint16_t item_term_gr = 0xfffe; - //uint16_t item_term_el = 0xe00d; - + + // ignore 'Zero length' Sequences + if ( GetReadLength() == 0 ) + return; + DocEntry::WriteContent(fp, filetype); for(ListSQItem::iterator cc = Items.begin(); cc != Items.end(); @@ -108,6 +102,56 @@ void SeqEntry::WriteContent(std::ofstream *fp, FileType filetype) binary_write(*fp, seq_term_lg); } +/** + * \brief Compute the full length of the SeqEntry (not only value + * length) depending on the VR. + */ +uint32_t SeqEntry::ComputeFullLength() +{ + uint32_t l = 12; // Tag (4) + VR (explicit) 4 + 4 (length); + for(ListSQItem::iterator cc = Items.begin(); + cc != Items.end(); + ++cc) + { + l += (*cc)->ComputeFullLength(); + } + l += 8; // seq_term Tag (4) + seq_term_lg (4) + return l; +} + +/** + * \brief adds the passed ITEM to the ITEM chained List for this SeQuence. + * @param sqItem SQItem to be pushed back in the SeqEntry + * @param itemNumber ordinal number of the SQItem + * \note NOT end-user intendend method ! + */ +void SeqEntry::AddSQItem(SQItem *sqItem, int itemNumber) +{ +// FIXME : SQItemNumber is supposed to be the ordinal number of the SQItem +// within the Sequence. +// Either only 'push_back' is allowed, +// and we just have to do something like SeqEntry::lastNb++ +// Or we can add (or remove) anywhere, and SQItemNumber will be broken + sqItem->SetSQItemNumber(itemNumber); + Items.push_back(sqItem); + sqItem->Register(); +} + +/** + * \brief Remove all SQItem. + */ +void SeqEntry::ClearSQItem() +{ + for(ListSQItem::iterator cc = Items.begin(); cc != Items.end(); ++cc) + { + (*cc)->Unregister(); + } + if (SeqTerm) + { + SeqTerm->Unregister(); + } +} + /** * \brief Get the first entry while visiting the SeqEntry * \return The first SQItem if found, otherwhise NULL @@ -171,20 +215,19 @@ unsigned int SeqEntry::GetNumberOfSQItems() } /** - * \brief adds the passed ITEM to the ITEM chained List for this SeQuence. - * @param sqItem SQItem to be pushed back in the SeqEntry - * @param itemNumber ordinal number of the SQItem - * \note NOT end-user intendend method ! + * \brief Sets the Sequence Delimitation Item + * \param e Delimitation item */ -void SeqEntry::AddSQItem(SQItem *sqItem, int itemNumber) +void SeqEntry::SetDelimitationItem(DocEntry *e) { -// FIXME : SQItemNumber is supposed to be the ordinal number of the SQItem -// within the Sequence. -// Either only 'push_back' is allowed, -// and we just have to do something like SeqEntry::lastNb++ -// Or we can add (or remove) anywhere, and SQItemNumber will be broken - sqItem->SetSQItemNumber(itemNumber); - Items.push_back(sqItem); + if( SeqTerm != e ) + { + if( SeqTerm ) + SeqTerm->Unregister(); + SeqTerm = e; + if( SeqTerm ) + SeqTerm->Register(); + } } //----------------------------------------------------------------------------- @@ -219,10 +262,12 @@ void SeqEntry::Print( std::ostream &os, std::string const & ) // at end, print the sequence terminator item, if any if (DelimitorMode) { - for ( int i = 0; i < SQDepthLevel; i++ ) - { + int i; + for ( i = 0; i < SQDepthLevel; i++ ) + os << " | " ; + os << " --- " << std::endl; + for ( i = 0; i < SQDepthLevel; i++ ) os << " | " ; - } if (SeqTerm != NULL) { SeqTerm->SetPrintLevel(PrintLevel); @@ -232,7 +277,7 @@ void SeqEntry::Print( std::ostream &os, std::string const & ) else { // fuse - gdcmVerboseMacro(" -------- should have a sequence terminator item"); + gdcmWarningMacro(" -------- should have a sequence terminator item"); } } }