Main Page | Alphabetical List | Compound List | File List | Compound Members | File Members

textid_map.h

Go to the documentation of this file.
00001 /*  This file is part of OMCSNetCPP
00002 
00003     OMCSNetCPP is free software; you can redistribute it and/or modify
00004     it under the terms of the GNU Lesser General Public License as published by
00005     the Free Software Foundation; either version 2.1 of the License, or
00006     (at your option) any later version.
00007 
00008     OMCSNetCPP is distributed in the hope that it will be useful,
00009     but WITHOUT ANY WARRANTY; without even the implied warranty of
00010     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00011     GNU Lesser General Public License for more details.
00012 
00013     You should have received a copy of the GNU Lesser General Public License
00014     along with OMCSNetCPP; if not, write to the Free Software
00015     Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00016  */
00017 
00020 #ifndef _TEXTID_MAP
00021 
00022 #define _TEXTID_MAP
00023 
00024 #include <map>
00025 #include <string>
00026 
00027 #include "semantic_id.h"
00028 
00029 
00031 class CTextIDMap
00032 {
00033         public:
00035                 SemanticID Lookup(const std::string &a_string)
00036                 {
00037                         CStringIDMap_i i;
00038 
00039                         i = m_idMap.find(a_string);
00040 
00041                         if (m_idMap.end() != i)
00042                         {
00043                                 return (*i).second;
00044                         }
00045 
00046                         return SEMANTIC_ID_NONE;
00047                 }
00048 
00050                 const std::string *Store(const std::string  &a_string,
00051                                          const SemanticID    a_id)
00052                 {
00053                         CStringIDMap_i i;
00054 
00055                         i = m_idMap.find(a_string);
00056 
00057                         if (m_idMap.end() == i)
00058                         {
00059                                 i = m_idMap.insert(m_idMap.begin(),
00060                                                 std::make_pair(a_string, a_id));
00061 
00062                                 if (m_idMap.end() != i)
00063                                 {
00064                                         return &((*i).first);
00065                                 }
00066                         }
00067                         else
00068                         {
00069                                 printf("%s found.. returning null.\n", a_string.c_str());
00070                         }
00071 
00072                         return NULL;
00073                 }
00074 
00076                 CTextIDMap() {}
00077 
00079                 ~CTextIDMap() {}
00080 
00081         private:
00083                 typedef std::map<std::string, SemanticID> CStringIDMap;
00085                 typedef CStringIDMap::iterator             CStringIDMap_i;
00087                 typedef CStringIDMap::const_iterator       CStringIDMap_ci;
00088 
00090                 CStringIDMap m_idMap;
00091 };
00092 
00093 #endif
00094 

Generated on Tue Sep 16 09:43:50 2003 for OMCSNetCPP by doxygen 1.3.3