gdcmDictGroupName.cxx

Go to the documentation of this file.
00001 /*=========================================================================
00002                                                                                 
00003   Program:   gdcm
00004   Module:    $RCSfile: gdcmDictGroupName.cxx,v $
00005   Language:  C++
00006   Date:      $Date: 2007/05/23 14:18:09 $
00007   Version:   $Revision: 1.8 $
00008                                                                                 
00009   Copyright (c) CREATIS (Centre de Recherche et d'Applications en Traitement de
00010   l'Image). All rights reserved. See Doc/License.txt or
00011   http://www.creatis.insa-lyon.fr/Public/Gdcm/License.html for details.
00012                                                                                 
00013      This software is distributed WITHOUT ANY WARRANTY; without even
00014      the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
00015      PURPOSE.  See the above copyright notices for more information.
00016                                                                                 
00017 =========================================================================*/
00018 
00019 #include "gdcmDictGroupName.h"
00020 #include "gdcmUtil.h"
00021 #include "gdcmDictSet.h"
00022 #include "gdcmDebug.h"
00023 
00024 #include <fstream>
00025 #include <iostream>
00026 #include <iomanip>
00027 
00028 namespace GDCM_NAME_SPACE 
00029 {
00030 //-----------------------------------------------------------------------------
00033 void FillDefaultDictGroupName(DictGroupNameHT &groupName);
00034 
00035 //-----------------------------------------------------------------------------
00036 // Constructor / Destructor
00040 DictGroupName::DictGroupName() 
00041 {
00042    std::string filename = DictSet::BuildDictPath() + DICT_GROUP_NAME;
00043    std::ifstream from(filename.c_str());
00044    if ( !from )
00045    {
00046       gdcmWarningMacro("Can't open dictionary" << filename.c_str());
00047       FillDefaultDictGroupName(groupName);
00048    }
00049    else
00050    {
00051       char buff[1024];
00052       uint16_t key;
00053       TagName value;
00054    
00055       while (!from.eof()) 
00056       {
00057          from >> std::ws;
00058          from >> std::hex;
00059          from >> key;
00060          from >> std::ws;
00061          from.getline(buff, 1024, '"');
00062          from.getline(buff, 1024, '"');
00063          value = buff;
00064          if ( !from.eof() )
00065             groupName[key] = value;
00066 
00067          from.getline(buff, 1024, '\n');
00068       }
00069       from.close();
00070    }
00071 }
00072 
00076 DictGroupName::~DictGroupName()
00077 {
00078    groupName.clear();
00079 }
00080 
00081 //-----------------------------------------------------------------------------
00082 // Public
00084 const TagName &DictGroupName::GetName(uint16_t group)
00085 {
00086    DictGroupNameHT::const_iterator it = groupName.find(group);
00087    if ( it == groupName.end() )
00088    {
00089       return GDCM_UNFOUND;
00090    }
00091    return it->second;
00092 }
00093 
00094 //-----------------------------------------------------------------------------
00095 // Protected
00096 
00097 //-----------------------------------------------------------------------------
00098 // Private
00099 
00100 //-----------------------------------------------------------------------------
00101 // Print
00106 void DictGroupName::Print(std::ostream &os,std::string const &) 
00107 {
00108    std::ostringstream s;
00109 
00110    for (DictGroupNameHT::iterator it = groupName.begin(); it != groupName.end(); ++it)
00111    {
00112       s << "DictGroupName : 0x" << std::hex << std::setw(4) << it->first 
00113         << std::dec << " = " << it->second << std::endl;
00114    }
00115    os << s.str();
00116 }
00117 
00118 //-----------------------------------------------------------------------------
00119 } // end namespace gdcm

Generated on Fri Aug 24 12:59:30 2007 for gdcm by  doxygen 1.4.6