- return ( PubElValSet.SetElValueByNumber (content, group, element) );
-}
-
-/**
- * \ingroup gdcmHeader
- * \brief Accesses an existing gdcmElValue in the PubElValSet of this instance
- * through it's (group, element) and modifies it's length with
- * the given value.
- * \warning Use with extreme caution.
- * @param length new length to substitute with
- * @param group group of the ElVal to modify
- * @param element element of the ElVal to modify
- * @return 1 on success, 0 otherwise.
- */
-
-bool gdcmHeader::SetPubElValLengthByNumber(guint32 length, guint16 group,
- guint16 element) {
- return ( PubElValSet.SetElValueLengthByNumber (length, group, element) );
-}
-
-/**
- * \ingroup gdcmHeader
- * \brief Searches within elements parsed with the public dictionary
- * and then within the elements parsed with the shadow dictionary
- * for the element value of a given tag.
- * @param tagName name of the searched element.
- * @return Corresponding element value when it exists,
- * and the string GDCM_UNFOUND ("gdcm::Unfound") otherwise.
- */
-std::string gdcmHeader::GetElValByName(std::string tagName) {
- std::string pub = GetPubElValByName(tagName);
- return pub;
-}
-
-/**
- * \ingroup gdcmHeader
- * \brief Searches within elements parsed with the public dictionary
- * and then within the elements parsed with the shadow dictionary
- * for the element value representation of a given tag.
- *
- * Obtaining the VR (Value Representation) might be needed by caller
- * to convert the string typed content to caller's native type
- * (think of C++ vs Python). The VR is actually of a higher level
- * of semantics than just the native C++ type.
- * @param tagName name of the searched element.
- * @return Corresponding element value representation when it exists,
- * and the string GDCM_UNFOUND ("gdcm::Unfound") otherwise.
- */
-std::string gdcmHeader::GetElValRepByName(std::string tagName) {
- std::string pub = GetPubElValRepByName(tagName);
- return pub;
-}
-
-/**
- * \ingroup gdcmHeader
- * \brief Searches within elements parsed with the public dictionary
- * and then within the elements parsed with the shadow dictionary
- * for the element value of a given tag.
- * @param group Group of the searched tag.
- * @param element Element of the searched tag.
- * @return Corresponding element value representation when it exists,
- * and the string GDCM_UNFOUND ("gdcm::Unfound") otherwise.
- */
-std::string gdcmHeader::GetElValByNumber(guint16 group, guint16 element) {
- std::string pub = GetPubElValByNumber(group, element);
- return pub;
-}
-
-/**
- * \ingroup gdcmHeader
- * \brief Searches within elements parsed with the public dictionary
- * and then within the elements parsed with the shadow dictionary
- * for the element value representation of a given tag.
- *
- * Obtaining the VR (Value Representation) might be needed by caller
- * to convert the string typed content to caller's native type
- * (think of C++ vs Python). The VR is actually of a higher level
- * of semantics than just the native C++ type.
- * @param group Group of the searched tag.
- * @param element Element of the searched tag.
- * @return Corresponding element value representation when it exists,
- * and the string GDCM_UNFOUND ("gdcm::Unfound") otherwise.
- */
-std::string gdcmHeader::GetElValRepByNumber(guint16 group, guint16 element) {
- std::string pub = GetPubElValRepByNumber(group, element);
- return pub;
-}
-
-/**
- * \ingroup gdcmElValSet
- * \brief Sets the value (string) of the target Dicom Element
- * @param content string value of the Dicom Element
- * @param tagName name of the searched Dicom Element.
- * @return true when found
- */
-bool gdcmHeader::SetElValueByName(std::string content,
- std::string tagName) {
-
- gdcmDictEntry *dictEntry = RefPubDict->GetTagByName(tagName);
- if( dictEntry == NULL)
- return false;
-
-
- TagKey key = gdcmDictEntry::TranslateToKey(dictEntry->GetGroup(),
- dictEntry->GetElement());
- if ( ! PubElValSet.GetTagHt().count(key))
- return false;
- int l = content.length();
- if(l%2) { // Odd length are padded with a space (020H).
- l++;
- content = content + '\0';
- }
-
- //tagHt[key]->SetValue(content);
- gdcmElValue * a;
- IterHT p;
- TagElValueHT::iterator p2;
- // DO NOT remove the following lines : they explain the stuff
- //p= tagHt.equal_range(key); // get a pair of iterators first-last synonym
- //p2=p.first; // iterator on the first synonym
- //a=p2->second; // H Table target column (2-nd col)
-
- // or, easier :
- a = ((PubElValSet.GetTagHt().equal_range(key)).first)->second;
-
- a-> SetValue(content);
-
- //std::string vr = tagHt[key]->GetVR();
- std::string vr = a->GetVR();
-
- guint32 lgr;
- if( (vr == "US") || (vr == "SS") )
- lgr = 2;
- else if( (vr == "UL") || (vr == "SL") )
- lgr = 4;
- else
- lgr = l;
- //tagHt[key]->SetLength(lgr);
- a->SetLength(lgr);
- return true;
-}
-
-/**
- * \ingroup gdcmHeader
- * \brief
- * @param exception_on_error
- * @return
- */
-FILE *gdcmHeader::OpenFile(bool exception_on_error)
- throw(gdcmFileError) {
- fp=fopen(filename.c_str(),"rb");
- if(exception_on_error) {
- if(!fp)
- throw gdcmFileError("gdcmHeader::gdcmHeader(const char *, bool)");
- }
-
- if ( fp ) {
- guint16 zero;
- fread(&zero, (size_t)2, (size_t)1, fp);
-
- //ACR -- or DICOM with no Preamble
- if( zero == 0x0008 || zero == 0x0800 || zero == 0x0002 || zero == 0x0200)
- return(fp);
-
- //DICOM
- fseek(fp, 126L, SEEK_CUR);
- char dicm[4];
- fread(dicm, (size_t)4, (size_t)1, fp);
- if( memcmp(dicm, "DICM", 4) == 0 )
- return(fp);
-
- fclose(fp);
- dbg.Verbose(0, "gdcmHeader::gdcmHeader not DICOM/ACR", filename.c_str());
- }
- else {
- dbg.Verbose(0, "gdcmHeader::gdcmHeader cannot open file", filename.c_str());
- }
- return(NULL);
-}
-
-/**
- * \ingroup gdcmHeader
- * \brief
- * @return TRUE if the close was successfull
- */
-bool gdcmHeader::CloseFile(void) {
- int closed = fclose(fp);
- fp = (FILE *)0;
- if (! closed)
- return false;
- return true;
-}
-
-/**
- * \ingroup gdcmHeader
- * \brief Parses the header of the file but WITHOUT loading element values.
- */
-void gdcmHeader::ParseHeader(bool exception_on_error) throw(gdcmFormatError) {
- gdcmElValue * newElValue = (gdcmElValue *)0;