-gdcmDict::gdcmDict(char * FileName) {
- std::ifstream from(FileName);
- dbg.Error(!from, "gdcmDictSet::gdcmDictSet:",
- "can't open dictionary");
- guint16 group, element;
- // CLEANME : use defines for all those constants
- char buff[1024];
- char trash[10];
- TagKey key, vr, fourth, name;
- while (!from.eof()) {
- from >> hex >> group >> element;
- eatwhite(from);
- from.getline(buff, 256, ' ');
- vr = buff;
- eatwhite(from);
- from.getline(buff, 256, ' ');
- fourth = buff;
- from.getline(buff, 256, '\n');
- name = buff;
- gdcmDictEntry * newEntry = new gdcmDictEntry(group, element,
- vr, fourth, name);
- entries[gdcmDictEntry::TranslateToKey(group, element)] = newEntry;
- }
- from.close();
+#include <fstream>
+#include <iostream>
+#include <iomanip>
+
+namespace gdcm
+{
+//-----------------------------------------------------------------------------
+/// \brief auto generated function, to fill up the Dicom Dictionnary,
+/// if relevant file is not found on user's disk
+void FillDefaultDataDict(Dict *d);
+
+//-----------------------------------------------------------------------------
+// Constructor / Destructor
+/**
+ * \brief Constructor
+ */
+Dict::Dict( )
+{
+ Filename="";
+}
+
+/**
+ * \brief Constructor
+ * @param filename from which to build the dictionary.
+ */
+Dict::Dict(std::string const &filename)
+{
+
+ std::ifstream from( filename.c_str() );
+ if ( !from )
+ {
+ gdcmWarningMacro( "Can't open dictionary" << filename.c_str());
+ // Using default embeded one:
+ FillDefaultDataDict( this );
+ }
+ else
+ {
+ DoTheLoadingJob(from);
+ Filename = filename;
+ }
+}
+
+/**
+ * \brief Destructor
+ */
+Dict::~Dict()
+{
+ ClearEntry();
+}
+
+//-----------------------------------------------------------------------------
+// Public
+
+/**
+ * \brief Add a all the entries held in a source dictionary
+ * \note it concerns only Private Dictionnary
+ * @param filename from which to build the dictionary.
+ */
+bool Dict::AddDict(std::string const &filename)
+{
+
+ std::ifstream from( filename.c_str() );
+ if ( !from )
+ {
+ gdcmWarningMacro( "Can't open dictionary" << filename.c_str());
+ return false;
+ }
+ else
+ {
+ DoTheLoadingJob(from);
+ return true;
+ }
+}
+
+
+/**
+ * \brief Removes from the current Dicom Dict all the entries held in a source dictionary
+ * \note it concerns only Private Dictionnary
+ * @param filename from which we read the entries to remove.
+ */
+bool Dict::RemoveDict(std::string const &filename)
+{
+ std::ifstream from( filename.c_str() );
+ if ( !from )
+ {
+ gdcmWarningMacro( "Can't open dictionary" << filename.c_str());
+ return false;
+ }
+ else
+ {
+ uint16_t group;
+ uint16_t elem;
+ TagName vr;
+ TagName vm;
+ TagName name;
+
+ while (!from.eof() && from)
+ {
+ from >> std::hex;
+ from >> group;
+ from >> elem;
+ from >> vr;
+ from >> vm;
+ // from >> std::ws; //remove white space
+ std::getline(from, name);
+
+ RemoveEntry(DictEntry::TranslateToKey(group, elem));
+ }
+ from.close();
+ return true;
+ }
+}
+
+/**
+ * \brief adds a new Dicom Dictionary Entry
+ * @param newEntry entry to add
+ * @return false if Dicom Element already exists
+ */
+bool Dict::AddEntry(DictEntry const &newEntry)
+{
+ const TagKey &key = newEntry.GetKey();
+
+ if ( KeyHt.count(key) == 1 )
+ {
+ gdcmErrorMacro( "Already present:" << key );
+ return false;
+ }
+ else
+ {
+ KeyHt.insert( TagKeyHT::value_type(newEntry.GetKey(), newEntry));
+ return true;
+ }