/[ghosts]/ghosts/gedcomparser/src/GEDCOMParser/LineageLinkageGedcom.cpp
ViewVC logotype

Diff of /ghosts/gedcomparser/src/GEDCOMParser/LineageLinkageGedcom.cpp

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 1.10 by cpcp, Sun Feb 23 21:34:44 2003 UTC revision 1.11 by cpcp, Thu Mar 13 19:59:05 2003 UTC
# Line 25  Line 25 
25  #include "GEDCOMParser/GEDCOMFactory.hh"  #include "GEDCOMParser/GEDCOMFactory.hh"
26  #include "GEDCOMParser/GEDCOMFactoryAccessor.hh"  #include "GEDCOMParser/GEDCOMFactoryAccessor.hh"
27    
28    #include <iostream>
29    
30  GEDCOMParser::Header * GEDCOMParser::LineageLinkageGedcom::setHeader(GEDCOMParser::Header * const data = 0)  GEDCOMParser::Header * GEDCOMParser::LineageLinkageGedcom::setHeader(GEDCOMParser::Header * const data = 0)
31  {  {
32    GEDCOMParser::Header  * tmp_data = data;    GEDCOMParser::Header  * tmp_data = data;
# Line 218  GEDCOMParser::SubmitterRecord * GEDCOMPa Line 220  GEDCOMParser::SubmitterRecord * GEDCOMPa
220    return _submitter_records[id].getPtr();    return _submitter_records[id].getPtr();
221  }  }
222    
223    GEDCOMParser::SpouseToFamilyLink * GEDCOMParser::LineageLinkageGedcom::AddSpouse(GEDCOMParser::IndividualRecord * spouse)
224    {
225      GEDCOMParser::SpouseToFamilyLink * family_link = 0;
226      if (spouse != 0)
227        {
228          family_link = spouse->addSpouseToFamilyLink();
229          GEDCOMParser::FamilyRecord * family_record = addFamilyRecord();
230          family_record->setSpouse(*spouse);
231          family_link->setFamsXref(family_record->getId());
232        }
233      return family_link;
234    }
235    
236    void GEDCOMParser::LineageLinkageGedcom::RemoveSpouseToFamilyLink(GEDCOMParser::IndividualRecord  * individual, GEDCOMParser::SpouseToFamilyLink * family_link_to_delete)
237    {
238      if (individual != 0)
239        {
240          SmartPtr < GEDCOMParser::FamilyRecord > family = _family_records[family_link_to_delete->getFamsXref()];
241          SmartPtr < GEDCOMParser::IndividualRecord > spouse;
242          GEDCOMParser::SpouseToFamilyLinks_t spouse_links;
243          GEDCOMParser::SpouseToFamilyLinks_t::iterator spouse_link_iter;
244          std::string const & spouse_id = family->getSpouseId(*individual);
245          
246          if (spouse_id != "")
247            {
248              spouse = _individual_records[spouse_id];
249              spouse_links = spouse->getSpouseToFamilyLinks();
250              spouse_link_iter = find_if(spouse_links.begin(), spouse_links.end(), GEDCOMParser::SpouseToFamilyLink::IsEqualByFamsXref(family->getId()));
251            }
252          family->RemoveSpouse(*individual);
253          individual->RemoveFamilyLink(family_link_to_delete);
254          if (FamilyIsUsed(family.getPtr()) == false)
255            {
256              RemoveFamilyRecord(*(family.getPtr()));
257            }
258          if (spouse_id != "")
259            {
260              if (spouse_link_iter != spouse_links.end())
261                {
262                  RemoveSpouseToFamilyLink(spouse.getPtr(), (*spouse_link_iter).getPtr());
263                }
264            }
265        }
266      return;
267    }
268    
269    void GEDCOMParser::LineageLinkageGedcom::RemoveFamilyRecord(GEDCOMParser::FamilyRecord const &family)
270    {
271      GEDCOMParser::FamilyRecords_t::iterator family_iter = _family_records.find(family.getId());
272      _family_records.erase(family_iter);
273      return;
274    }
275    
276    GEDCOMParser::ChildToFamilyLink * GEDCOMParser::LineageLinkageGedcom::AddParents(GEDCOMParser::IndividualRecord * child)
277    {
278      GEDCOMParser::ChildToFamilyLink * family_link = 0;
279      if (child != 0)
280        {
281          family_link = child->addChildToFamilyLink();
282          GEDCOMParser::FamilyRecord * family_record = addFamilyRecord();
283          family_record->addChilXref(child->getId());
284          family_link->setFamcXref(family_record->getId());
285        }
286      return family_link;
287    }
288    
289    void GEDCOMParser::LineageLinkageGedcom::RemoveChildToFamilyLink(GEDCOMParser::IndividualRecord * individual, GEDCOMParser::ChildToFamilyLink * family_link_to_delete)
290    {
291      if (individual != 0)
292        {
293          SmartPtr < GEDCOMParser::FamilyRecord > family = _family_records[family_link_to_delete->getFamcXref()];
294          family->RemoveChilXref(individual->getId());
295          individual->RemoveFamilyLink(family_link_to_delete);
296          if (FamilyIsUsed(family.getPtr()) == false)
297            {
298              RemoveFamilyRecord(*(family.getPtr()));
299            }
300        }
301      return;
302    }
303    
304  SmartPtr<GEDCOMParser::Header> const & GEDCOMParser::LineageLinkageGedcom::getHeader(void) const  SmartPtr<GEDCOMParser::Header> const & GEDCOMParser::LineageLinkageGedcom::getHeader(void) const
305  {  {
306    return _header;    return _header;
# Line 324  bool GEDCOMParser::LineageLinkageGedcom: Line 407  bool GEDCOMParser::LineageLinkageGedcom:
407  }  }
408    
409    
410    bool GEDCOMParser::LineageLinkageGedcom::FamilyIsUsed(GEDCOMParser::FamilyRecord const * const family) const
411    {
412      bool res = false;
413      std::string family_id = family->getId();
414      GEDCOMParser::IndividualRecords_t::const_iterator individu_iter = _individual_records.begin();
415      do
416        {
417          GEDCOMParser::ChildToFamilyLinks_t const child_links = (*individu_iter).second->getChildToFamilyLinks();
418          GEDCOMParser::ChildToFamilyLinks_t::const_iterator child_link_iter = find_if(child_links.begin(), child_links.end(), GEDCOMParser::ChildToFamilyLink::IsEqualByFamcXref(family_id));
419          if (child_link_iter != child_links.end())
420            {
421              res = true;
422            }
423          if (res == false)
424            {
425              GEDCOMParser::SpouseToFamilyLinks_t spouse_links = (*individu_iter).second->getSpouseToFamilyLinks();
426              GEDCOMParser::SpouseToFamilyLinks_t::const_iterator spouse_link_iter = find_if(spouse_links.begin(), spouse_links.end(), GEDCOMParser::SpouseToFamilyLink::IsEqualByFamsXref(family_id));
427              if (spouse_link_iter != spouse_links.end())
428                {
429                  res = true;
430                }
431            }
432          individu_iter++;
433        }
434      while ((res == false) && (individu_iter != _individual_records.end()));
435      return res;
436    }
437    
438  GEDCOMParser::IndividualRecords_t GEDCOMParser::LineageLinkageGedcom::getRootIndividuals(void) const  GEDCOMParser::IndividualRecords_t GEDCOMParser::LineageLinkageGedcom::getRootIndividuals(void) const
439  {  {
440    int cpt_individus = 0;    int cpt_individus = 0;

Legend:
Removed from v.1.10  
changed lines
  Added in v.1.11

savannah-hackers-public@gnu.org
ViewVC Help
Powered by ViewVC 1.1.26