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

concept_map.cpp

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 #include "concept_map.h"
00021 #include "concept.h"
00022 
00023 
00024 void CConceptMap::Store(CSemanticConcept *a_concept)
00025 {
00026         CSemanticConceptMap_i i;
00027 
00028         i = m_conceptMap.find(a_concept->GetID());
00029 
00030         if (m_conceptMap.end() == i)
00031         {
00032                 m_conceptMap[a_concept->GetID()] = a_concept;
00033         }
00034 }
00035 
00036 bool CConceptMap::Load(FILE       *a_fp,
00037                        CTextIDMap &a_idMap)
00038 {
00039         if (!a_fp)
00040         {
00041                 return false;
00042         }
00043 
00044         u_int l_size = 0;
00045 
00046         fread(&l_size, sizeof(u_int), 1, a_fp);
00047 
00048         printf("Loading %d concepts..\n", l_size);
00049 
00050         CSemanticConcept *l_concept = NULL;
00051 
00052         for (u_int i = 0;i < l_size;++i)
00053         {
00054                 l_concept = new CSemanticConcept("", NULL, NULL);
00055 
00056                 if (l_concept)
00057                 {
00058                         if (false == l_concept->Load(a_fp, a_idMap))
00059                         {
00060                                 printf("error loading concept %d of %d\n",
00061                                         i, l_size);
00062 
00063                                 return false;
00064                         }
00065                 }
00066 
00067                 Store(l_concept);
00068         }
00069 
00070         return true;
00071 }
00072 
00073 bool CConceptMap::Save(FILE *a_fp)
00074 {
00075         if (!a_fp)
00076         {
00077                 return false;
00078         }
00079 
00080         u_int l_size = m_conceptMap.size();
00081 
00082         fwrite(&l_size, sizeof(u_int), 1, a_fp);
00083 
00084         CSemanticConceptMap_i i;
00085 
00086         for (i = m_conceptMap.begin();i != m_conceptMap.end();++i)
00087         {
00088                 if (false == (*i).second->Save(a_fp))
00089                 {
00090                         return false;
00091                 }
00092         }
00093 
00094         return true;
00095 }
00096 

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