- // 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 *)tag)->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 *)tag)->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)
-{
- guint32 length = tag->GetLength();
-
- if (gdcmValEntry* ValEntry = dynamic_cast< gdcmValEntry* >(tag) )
- {
- // The value of a tag MUST (see the DICOM norm) be an odd number of
- // bytes. When this is not the case, pad with an additional byte:
- if(length%2==1) {
- ValEntry->SetValue(ValEntry->GetValue()+"\0");
- ValEntry->SetLength(ValEntry->GetReadLength()+1);
- }
- WriteEntryTagVRLength(ValEntry, _fp, type);
- WriteEntryValue(ValEntry, _fp, type);
- return true;
- }
-
- if (gdcmBinEntry* BinEntry = dynamic_cast< gdcmBinEntry* >(tag) )
- {
- /// \todo FIXME : when voidArea belong to gdcmBinEntry only, fix
- /// voidArea length
- //
- // The value of a tag MUST (see the DICOM norm) be an odd number of
- // bytes. When this is not the case, pad with an additional byte:
-/*
- if(length%2==1) {
- tag->SetValue(tag->GetValue()+"\0");
- tag->SetLength(tag->GetReadLength()+1);
- }
-*/
- WriteEntryTagVRLength(tag, _fp, type);
- WriteEntryValue(tag, _fp, type);
- return true;
- }
-}
-
-/**
- * \brief writes on disc according to the requested format
- * (ACR-NEMA, ExplicitVR, ImplicitVR) the image
- * using the Chained List
- * \warning does NOT add the missing elements in the header :
- * it's up to the user doing it !
- * (function CheckHeaderCoherence to be written)
- * \warning DON'T try, right now, to write a DICOM image
- * from an ACR Header (meta elements will be missing!)
- * @param type type of the File to be written
- * (ACR-NEMA, ExplicitVR, ImplicitVR)
- * @param _fp already open file pointer
- */
-
-bool gdcmDocument::WriteEntries(FILE *_fp,FileType type)
-{
- /// \todo FIXME : explore recursively the whole structure...
- /// \todo (?) check write failures (after *each* fwrite)
-
- dbg.Verbose(0, "gdcmDocument::WriteEntries: entering.");
- for (TagDocEntryHT::iterator it = tagHT.begin(); it != tagHT.end(); ++it )
- {
- gdcmDocEntry * entry = it->second;
-
- if ( type == gdcmACR ){
- if (entry->GetGroup() < 0x0008)
- // Ignore pure DICOM V3 groups
- continue;
- if (entry->GetGroup() %2)
- // Ignore the "shadow" groups
- continue;
- if (entry->GetVR() == "SQ" ) // ignore Sequences
- continue;
- }
- if (! WriteEntry(entry, _fp, type) ) {
- dbg.Verbose(0, "gdcmDocument::WriteEntries: write failure.");
- return false;
- }
- }
- return true;
-}
-
-
-/**
- * \brief Swaps back the bytes of 4-byte long integer accordingly to
- * processor order.
- * @return The properly swaped 32 bits integer.
- */
-guint32 gdcmDocument::SwapLong(guint32 a) {
- switch (sw) {