bio_tree.cpp
上传用户:yhdzpy8989
上传日期:2007-06-13
资源大小:13604k
文件大小:5k
源码类别:

生物技术

开发平台:

C/C++

  1. /*
  2.  * ===========================================================================
  3.  * PRODUCTION $Log: bio_tree.cpp,v $
  4.  * PRODUCTION Revision 1000.1  2004/06/01 18:09:20  gouriano
  5.  * PRODUCTION PRODUCTION: UPGRADED [GCC34_MSVC7] Dev-tree R1.4
  6.  * PRODUCTION
  7.  * ===========================================================================
  8.  */
  9. /*  $Id: bio_tree.cpp,v 1000.1 2004/06/01 18:09:20 gouriano Exp $
  10.  * ===========================================================================
  11.  *
  12.  *                            PUBLIC DOMAIN NOTICE
  13.  *               National Center for Biotechnology Information
  14.  *
  15.  *  This software/database is a "United States Government Work" under the
  16.  *  terms of the United States Copyright Act.  It was written as part of
  17.  *  the author's official duties as a United States Government employee and
  18.  *  thus cannot be copyrighted.  This software/database is freely available
  19.  *  to the public for use. The National Library of Medicine and the U.S.
  20.  *  Government have not placed any restriction on its use or reproduction.
  21.  *
  22.  *  Although all reasonable efforts have been taken to ensure the accuracy
  23.  *  and reliability of the software and data, the NLM and the U.S.
  24.  *  Government do not and cannot warrant the performance or results that
  25.  *  may be obtained by using this software or data. The NLM and the U.S.
  26.  *  Government disclaim all warranties, express or implied, including
  27.  *  warranties of performance, merchantability or fitness for any particular
  28.  *  purpose.
  29.  *
  30.  *  Please cite the author in any work or product based on this material.
  31.  *
  32.  * ===========================================================================
  33.  *
  34.  * Authors:  Anatoliy Kuznetsov
  35.  *
  36.  * File Description:  Things for representing and manipulating bio trees
  37.  *
  38.  */
  39. /// @file bio_tree.cpp
  40. /// Things for representing and manipulating bio trees
  41. #include <ncbi_pch.hpp>
  42. #include <algo/phy_tree/bio_tree.hpp>
  43. BEGIN_NCBI_SCOPE
  44. /*
  45. IBioTreeNode::~IBioTreeNode()
  46. {}
  47. */
  48. CBioTreeFeatureList::CBioTreeFeatureList()
  49. {
  50. }
  51. CBioTreeFeatureList::CBioTreeFeatureList(const CBioTreeFeatureList& flist)
  52.  : m_FeatureList(flist.m_FeatureList)
  53. {}
  54. CBioTreeFeatureList& 
  55. CBioTreeFeatureList::operator=(const CBioTreeFeatureList& flist)
  56. {
  57.     m_FeatureList.assign(flist.m_FeatureList.begin(), 
  58.                          flist.m_FeatureList.end());
  59.     return *this;
  60. }
  61. void CBioTreeFeatureList::SetFeature(TBioTreeFeatureId id, 
  62.                                      const string&     value)
  63. {
  64.     NON_CONST_ITERATE(TFeatureList, it, m_FeatureList) {
  65.         if (it->id == id) {
  66.             it->value = value;
  67.             return;
  68.         }
  69.     }
  70.     m_FeatureList.push_back(CBioTreeFeaturePair(id, value));
  71. }
  72. const string& 
  73. CBioTreeFeatureList::GetFeatureValue(TBioTreeFeatureId id) const
  74. {
  75.     ITERATE(TFeatureList, it, m_FeatureList) {
  76.         if (it->id == id) {
  77.             return it->value;
  78.         }
  79.     }
  80.     return kEmptyStr;
  81. }
  82. void CBioTreeFeatureList::RemoveFeature(TBioTreeFeatureId id)
  83. {
  84.     NON_CONST_ITERATE(TFeatureList, it, m_FeatureList) {
  85.         if (it->id == id) {
  86.             m_FeatureList.erase(it);
  87.             return;
  88.         }
  89.     }
  90. }
  91. CBioTreeFeatureDictionary::CBioTreeFeatureDictionary()
  92.  : m_IdCounter(0)
  93. {
  94. }
  95. CBioTreeFeatureDictionary::CBioTreeFeatureDictionary(
  96.                                       const CBioTreeFeatureDictionary& btr)
  97.  : m_Dict(btr.m_Dict),
  98.    m_Name2Id(btr.m_Name2Id),
  99.    m_IdCounter(btr.m_IdCounter)
  100. {
  101. }
  102. CBioTreeFeatureDictionary& 
  103. CBioTreeFeatureDictionary::operator=(const CBioTreeFeatureDictionary& btr)
  104. {
  105.     Clear();
  106.     ITERATE(TFeatureDict, it, btr.m_Dict) {
  107.         m_Dict.insert(*it);
  108.     }
  109.     ITERATE(TFeatureNameIdx, it, btr.m_Name2Id) {
  110.         m_Name2Id.insert(*it);
  111.     }
  112.     return *this;
  113. }
  114. void CBioTreeFeatureDictionary::Clear()
  115. {
  116.     m_Dict.clear();
  117.     m_Name2Id.clear();
  118.     m_IdCounter = 0;
  119. }
  120. bool 
  121. CBioTreeFeatureDictionary::HasFeature(const string& feature_name) 
  122. {
  123.     TFeatureNameIdx::const_iterator it = m_Name2Id.find(feature_name);
  124.     return (it != m_Name2Id.end());
  125. }
  126. bool 
  127. CBioTreeFeatureDictionary::HasFeature(TBioTreeFeatureId id)
  128. {
  129.     TFeatureDict::const_iterator it = m_Dict.find(id);
  130.     return (it != m_Dict.end());
  131. }
  132. TBioTreeFeatureId 
  133. CBioTreeFeatureDictionary::Register(const string& feature_name)
  134. {
  135.     ++m_IdCounter;
  136.     m_Dict.insert(
  137.            pair<TBioTreeFeatureId, string>(m_IdCounter, feature_name));
  138.     m_Name2Id.insert(
  139.            pair<string, TBioTreeFeatureId>(feature_name, m_IdCounter));
  140.     return m_IdCounter;
  141. }
  142. TBioTreeFeatureId 
  143. CBioTreeFeatureDictionary::GetId(const string& feature_name) const
  144. {
  145.     TFeatureNameIdx::const_iterator it = m_Name2Id.find(feature_name);
  146.     if (it == m_Name2Id.end()) {
  147.         return 0;
  148.     }
  149.     return it->second;
  150. }
  151. END_NCBI_SCOPE
  152. /*
  153.  * ===========================================================================
  154.  * $Log: bio_tree.cpp,v $
  155.  * Revision 1000.1  2004/06/01 18:09:20  gouriano
  156.  * PRODUCTION: UPGRADED [GCC34_MSVC7] Dev-tree R1.4
  157.  *
  158.  * Revision 1.4  2004/05/21 21:41:03  gorelenk
  159.  * Added PCH ncbi_pch.hpp
  160.  *
  161.  * Revision 1.3  2004/05/19 12:45:18  kuznets
  162.  * + CBioTreeFeatureDictionary::Clear()
  163.  *
  164.  * Revision 1.2  2004/05/10 15:46:35  kuznets
  165.  * Minor changes.
  166.  *
  167.  * Revision 1.1  2004/04/06 17:58:31  kuznets
  168.  * Initial revision
  169.  *
  170.  *
  171.  * ===========================================================================
  172.  */