+/// As gotten from:
+/// http://community.borland.com/article/0,1410,17203,0.html
+uint16_t ReferenceFileParser::axtoi(char *hexStg) {
+ int n = 0; // position in string
+ int m = 0; // position in digit[] to shift
+ int count; // loop index
+ int intValue = 0; // integer value of hex string
+ int digit[5]; // hold values to convert
+ while (n < 4) {
+ if (hexStg[n]=='\0')
+ break;
+ if (hexStg[n] > 0x29 && hexStg[n] < 0x40 ) //if 0 to 9
+ digit[n] = hexStg[n] & 0x0f; //convert to int
+ else if (hexStg[n] >='a' && hexStg[n] <= 'f') //if a to f
+ digit[n] = (hexStg[n] & 0x0f) + 9; //convert to int
+ else if (hexStg[n] >='A' && hexStg[n] <= 'F') //if A to F
+ digit[n] = (hexStg[n] & 0x0f) + 9; //convert to int
+ else break;
+ n++;
+ }
+ count = n;
+ m = n - 1;
+ n = 0;
+ while(n < count) {
+ // digit[n] is value of hex digit at position n
+ // (m << 2) is the number of positions to shift
+ // OR the bits into return value
+ intValue = intValue | (digit[n] << (m << 2));
+ m--; // adjust the position to set
+ n++; // next digit to process
+ }
+ return intValue;
+}
+
+void ReferenceFileParser::SetDataPath( std::string& inDataPath )
+{
+ DataPath = inDataPath;
+}
+
+bool ReferenceFileParser::AddKeyValuePairToMap( std::string& key, std::string& value )
+{
+ if ( !CurrentMapEntryValuesPtr )
+ return false;
+ if ( CurrentMapEntryValuesPtr->count(key) != 0 )
+ return false;
+ (*CurrentMapEntryValuesPtr)[key] = value;
+
+ return true; //??
+}
+
+void ReferenceFileParser::Print()
+{
+ for (MapFileValuesType::iterator i = ProducedMap.begin();
+ i != ProducedMap.end();
+ ++i)
+ {
+ std::cout << Indent << "FileName: " << i->first << std::endl;
+ MapEntryValuesPtr KeyValues = i->second;
+ for (MapEntryValues::iterator j = KeyValues->begin();
+ j != KeyValues->end();
+ ++j)
+ {
+ std::cout << Indent
+ << " Key: " << j->first
+ << " Value: " << j->second
+ << std::endl;
+ }
+ std::cout << Indent << std::endl;
+ }
+ std::cout << Indent << std::endl;
+}
+
+bool ReferenceFileParser::Check()
+{
+ for (MapFileValuesType::iterator i = ProducedMap.begin();
+ i != ProducedMap.end();
+ ++i)
+ {
+ std::string fileName = DataPath + i->first;
+ std::cout << Indent << "FileName: " << fileName << std::endl;
+ gdcm::Header* tested = new gdcm::Header( fileName.c_str() );
+ if( !tested->IsReadable() )
+ {
+ std::cerr << Indent << "Image not gdcm compatible:"
+ << fileName << std::endl;
+ delete tested;
+ return false;
+ }
+
+ MapEntryValuesPtr KeyValues = i->second;
+ for (MapEntryValues::iterator j = KeyValues->begin();
+ j != KeyValues->end();
+ ++j)
+ {
+ std::string key = j->first;
+
+ std::string groupString = key.substr( 0, 4 );
+ char* groupCharPtr;
+ groupCharPtr = new char(groupString.length() + 1);
+ strcpy( groupCharPtr, groupString.c_str() );
+
+ std::string groupElement = key.substr( key.find_first_of( "|" ) + 1, 4 );
+ char* groupElementPtr;
+ groupElementPtr = new char(groupElement.length() + 1);
+ strcpy( groupElementPtr, groupElement.c_str() );
+
+ uint16_t group = axtoi( groupCharPtr );
+ uint16_t element = axtoi( groupElementPtr );
+
+ std::string testedValue = tested->GetEntryByNumber(group, element);
+ if ( testedValue != j->second )
+ {
+ // Oops make sure this is only the \0 that differ
+ if( testedValue[j->second.size()] != '\0' ||
+ strncmp(testedValue.c_str(),
+ j->second.c_str(), j->second.size()) != 0)
+ {
+ std::cout << Indent << "Uncorrect value for key "
+ << key << std::endl
+ << Indent << " read value ["
+ << testedValue << "]" << std::endl
+ << Indent << " reference value ["
+ << j->second << "]" << std::endl;
+ return false;
+ }
+ }
+ }
+ delete tested;
+ std::cout << Indent << " OK" << std::endl;
+ }
+ std::cout << Indent << std::endl;
+ return true;
+}
+
+std::istream& ReferenceFileParser::eatwhite( std::istream& is )