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

link.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 //#define DEBUG
00021 
00022 #include "link.h"
00023 #include "link_list.h"
00024 #include "concept.h"
00025 #include "find_cfg.h"
00026 #include "debug.h"
00027 
00028 bool CSemanticLink::FindPathTo(const SemanticID       a_dstID,
00029                                                    CFindPathConfig &a_config)
00030 {
00031         DPRINT("visiting link.\n");
00032 
00033         a_config.VisitLink(this);
00034 
00035         if (m_dest)
00036         {
00037                 if (m_dest->GetID() == a_dstID)
00038                 {
00039                         DPRINT("adding path to results.\n");
00040 
00041                         a_config.AddPathToResults();
00042 
00043                         a_config.LeaveLink();
00044 
00045                         return true;
00046                 }
00047                 else if (true == a_config.AllowVisit())
00048                 {
00049                         DPRINT("queueing path.\n");
00050                         a_config.QueuePath();
00051                 }
00052         }
00053         else DPRINT("invalid link\n");
00054 
00055 
00056         a_config.LeaveLink();
00057 
00058         return false;
00059 }
00060 
00061 
00062 CSemanticLink::CSemanticLink()
00063 {
00064         m_source = NULL;
00065         m_dest   = NULL;
00066 
00067         m_sourceID = 0;
00068         m_destID   = 0;
00069 
00070         m_linkID = SEMANTIC_ID_NONE;
00071 
00072         m_type     = RELATION_NONE;
00073 }
00074 
00075 
00076 void CSemanticLink::SetSource(CSemanticConcept *a_concept)
00077 {
00078         if (a_concept)
00079         {
00080                 m_source = a_concept;
00081 
00082                 m_sourceID = m_source->GetID();
00083         }
00084 }
00085 
00086 void CSemanticLink::SetDest(CSemanticConcept *a_concept)
00087 {
00088         if (a_concept)
00089         {
00090                 m_dest = a_concept;
00091 
00092                 m_destID = m_dest->GetID();
00093         }
00094 }
00095 
00096 bool CSemanticLink::Load(FILE        *a_fp,
00097                          CConceptMap &a_conceptMap)
00098 {
00099         if (!a_fp)
00100         {
00101                 return false;
00102         }
00103 
00104         fread(&m_sourceID, sizeof(SemanticID), 1, a_fp);
00105 
00106         fread(&m_destID, sizeof(SemanticID), 1, a_fp);
00107 
00108         fread(&m_linkID, sizeof(SemanticID), 1, a_fp);
00109 
00110         fread(&m_type, sizeof(RelationType), 1, a_fp);
00111 
00112         CSemanticConcept *l_concept = NULL;
00113 
00114         l_concept = a_conceptMap.Lookup(m_sourceID);
00115 
00116         if (!l_concept)
00117         {
00118                 printf("error linking source concept [%d]\n", (int)m_sourceID);
00119 
00120                 return false;
00121         }
00122 
00123         m_source = l_concept;
00124 
00125         l_concept = a_conceptMap.Lookup(m_destID);
00126 
00127         if (!l_concept)
00128         {
00129                 printf("error linking dest concept [%d]\n", (int)m_destID);
00130 
00131                 return false;
00132         }
00133 
00134         m_dest = l_concept;
00135 
00136         m_source->AddLink(this, m_type);
00137 
00138         m_dest->AddBackwardLink(this, m_type);
00139 
00140         return true;
00141 }
00142 
00143 

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