-void gdcmDocument::LoadDocEntrySafe(gdcmDocEntry * entry) {
- long PositionOnEntry = ftell(fp);
- LoadDocEntry(entry);
- fseek(fp, PositionOnEntry, SEEK_SET);
-}
-
-
-/**
- * \brief Writes in a file (according to the requested format)
- * the group, the element, the value representation and the length
- * of a single gdcmDocEntry passed as argument.
- * @param tag pointer on the gdcmDocEntry to be written
- * @param _fp already open file pointer
- * @param type type of the File to be written
- */
-void gdcmDocument::WriteEntryTagVRLength(gdcmDocEntry *tag,
- FILE *_fp,
- FileType type)
-{
- guint16 group = tag->GetGroup();
- VRKey vr = tag->GetVR();
- guint16 el = tag->GetElement();
- guint32 lgr = tag->GetReadLength();
-
- if ( (group == 0xfffe) && (el == 0x0000) )
- // Fix in order to make some MR PHILIPS images e-film readable
- // see gdcmData/gdcm-MR-PHILIPS-16-Multi-Seq.dcm:
- // we just *always* ignore spurious fffe|0000 tag !
- return;
-
- fwrite ( &group,(size_t)2 ,(size_t)1 ,_fp); //group
- fwrite ( &el,(size_t)2 ,(size_t)1 ,_fp); //element
-
- if ( type == gdcmExplicitVR ) {
-
- // Special case of delimiters:
- if (group == 0xfffe) {
- // Delimiters have NO Value Representation and have NO length.
- // Hence we skip writing the VR and length and we pad by writing
- // 0xffffffff
-
- int ff=0xffffffff;
- fwrite (&ff,(size_t)4 ,(size_t)1 ,_fp);
- return;
- }
-
- guint16 z=0;
- guint16 shortLgr = lgr;
- if (vr == "unkn") { // Unknown was 'written'
- // deal with Little Endian
- fwrite ( &shortLgr,(size_t)2 ,(size_t)1 ,_fp);
- fwrite ( &z, (size_t)2 ,(size_t)1 ,_fp);
- } else {
- fwrite (vr.c_str(),(size_t)2 ,(size_t)1 ,_fp);
- if ( (vr == "OB") || (vr == "OW") || (vr == "SQ") )
- {
- fwrite ( &z, (size_t)2 ,(size_t)1 ,_fp);
- fwrite ( &lgr,(size_t)4 ,(size_t)1 ,_fp);
- } else {
- fwrite ( &shortLgr,(size_t)2 ,(size_t)1 ,_fp);
- }
- }
- }
- else // IMPLICIT VR
- {
- fwrite ( &lgr,(size_t)4 ,(size_t)1 ,_fp);
- }
-}
-
-/**
- * \brief Writes in a file (according to the requested format)
- * the value of a single gdcmDocEntry passed as argument.
- * @param tag Pointer on the gdcmDocEntry to be written
- * @param _fp Already open file pointer
- * @param type type of the File to be written
- */
-
-// \todo TODO : to be re -written recursively !
-void gdcmDocument::WriteEntryValue(gdcmDocEntry *Entry, FILE *_fp,FileType type)
-{
- (void)type;
- guint16 group = Entry->GetGroup();
- VRKey vr = Entry->GetVR();
- guint32 lgr = Entry->GetReadLength();
-
- if (vr == "SQ")
- // SeQuences have no value:
- return;
- if (group == 0xfffe)
- // Delimiters have no associated value:
- return;
-
-// if (gdcmBinEntry* BinEntry = dynamic_cast< gdcmBinEntry* >(Entry) ) {
- void *voidArea;
- gdcmBinEntry *BinEntry= (gdcmBinEntry *)Entry;;
- voidArea = BinEntry->GetVoidArea();
- if (voidArea != NULL)
- { // there is a 'non string' LUT, overlay, etc
- fwrite ( voidArea,(size_t)lgr ,(size_t)1 ,_fp); // Elem value
- return;
- }
-// }
-
- if (vr == "US" || vr == "SS")
- {
- // some 'Short integer' fields may be mulivaluated
- // each single value is separated from the next one by '\'
- // we split the string and write each value as a short int
- std::vector<std::string> tokens;
- tokens.erase(tokens.begin(),tokens.end()); // clean any previous value
- Tokenize (((gdcmValEntry *)Entry)->GetValue(), tokens, "\\");
- for (unsigned int i=0; i<tokens.size();i++)
- {
- guint16 val_uint16 = atoi(tokens[i].c_str());
- void *ptr = &val_uint16;
- fwrite ( ptr,(size_t)2 ,(size_t)1 ,_fp);
- }
- tokens.clear();
- return;
- }
- if (vr == "UL" || vr == "SL")
- {
- // Some 'Integer' fields may be multivaluated (multiple instances
- // of integers). But each single integer value is separated from the
- // next one by '\' (backslash character). Hence we split the string
- // along the '\' and write each value as an int:
- std::vector<std::string> tokens;
- tokens.erase(tokens.begin(),tokens.end()); // clean any previous value
- Tokenize (((gdcmValEntry *)Entry)->GetValue(), tokens, "\\");
- for (unsigned int i=0; i<tokens.size();i++)
- {
- guint32 val_uint32 = atoi(tokens[i].c_str());
- void *ptr = &val_uint32;
- fwrite ( ptr,(size_t)4 ,(size_t)1 ,_fp);
- }
- tokens.clear();
- return;
- }
- fwrite (((gdcmValEntry *)Entry)->GetValue().c_str(),
- (size_t)lgr ,(size_t)1, _fp); // Elem value
-}
-
-/**
- * \brief Writes in a file (according to the requested format)
- * a single gdcmDocEntry passed as argument.
- * \sa WriteEntryValue, WriteEntryTagVRLength.
- * @param tag Pointer on the gdcmDocEntry to be written
- * @param _fp Already open file pointer
- * @param type type of the File to be written
- */
-
-bool gdcmDocument::WriteEntry(gdcmDocEntry *tag, FILE *_fp,FileType type)