NCBI C++ ToolKit
seqdesc_title_change.cpp
Go to the documentation of this file.

Go to the SVN repository for this file.

1 /* $Id: seqdesc_title_change.cpp 25347 2012-03-01 18:22:54Z katargir $
2  * ===========================================================================
3  *
4  * PUBLIC DOMAIN NOTICE
5  * National Center for Biotechnology Information
6  *
7  * This software/database is a "United States Government Work" under the
8  * terms of the United States Copyright Act. It was written as part of
9  * the author's official duties as a United States Government employee and
10  * thus cannot be copyrighted. This software/database is freely available
11  * to the public for use. The National Library of Medicine and the U.S.
12  * Government have not placed any restriction on its use or reproduction.
13  *
14  * Although all reasonable efforts have been taken to ensure the accuracy
15  * and reliability of the software and data, the NLM and the U.S.
16  * Government do not and cannot warrant the performance or results that
17  * may be obtained by using this software or data. The NLM and the U.S.
18  * Government disclaim all warranties, express or implied, including
19  * warranties of performance, merchantability or fitness for any particular
20  * purpose.
21  *
22  * Please cite the author in any work or product based on this material.
23  *
24  * ===========================================================================
25  *
26  * Authors: Roman Katargin
27  *
28  * File Description:
29  *
30  */
31 
32 #include <ncbi_pch.hpp>
33 
34 #include <gui/objutils/objects.hpp>
36 
38 
41 
43 {
44  CBioseq_EditHandle eh = m_BH.GetEditHandle();
46  CBioseq& bioseq = const_cast<CBioseq&>(*bsc);
47 
48  if (!bioseq.IsSetDescr()) {
49  m_SeqDescrCreated = true;
50  CRef<CSeq_descr> seq_descr(new CSeq_descr());
51  bioseq.SetDescr(*seq_descr);
52  }
53 
54  CSeq_descr::Tdata& seq_descr = bioseq.SetDescr();
55  CSeq_descr::Tdata::iterator desc_it = seq_descr.begin();
56  for (; desc_it != seq_descr.end(); ++desc_it) {
57  if ((**desc_it).IsTitle())
58  break;
59  }
60 
61  CRef<CSeqdesc> seqdesc;
62  if (desc_it == seq_descr.end()) {
63  m_TitleCreated = true;
64  seqdesc.Reset(new CSeqdesc());
65  seqdesc->SetTitle(NcbiEmptyString);
66  seq_descr.push_back(seqdesc);
67  desc_it = seq_descr.end();
68  --desc_it;
69  }
70  else
71  seqdesc = *desc_it;
72 
73  string old_title = seqdesc->GetTitle();
74  seqdesc->SetTitle(m_Title);
75  m_Title = old_title;
76 }
77 
79 {
80  CBioseq_EditHandle eh = m_BH.GetEditHandle();
82  CBioseq& bioseq = const_cast<CBioseq&>(*bsc);
83 
84  if (!bioseq.IsSetDescr()) {
85  return; // Something is wrong
86  }
87 
88  CSeq_descr::Tdata& seq_descr = bioseq.SetDescr();
89  CSeq_descr::Tdata::iterator desc_it = seq_descr.begin();
90  for (; desc_it != seq_descr.end(); ++desc_it) {
91  if ((**desc_it).IsTitle())
92  break;
93  }
94 
95  if (desc_it == seq_descr.end()) {
96  return; // Something is wrong
97  }
98 
99  string new_title = (**desc_it).GetTitle();
100 
101  if (m_TitleCreated) {
102  m_TitleCreated = false;
103  seq_descr.erase(desc_it);
104  }
105  else {
106  (**desc_it).SetTitle(m_Title);
107  }
108 
109  m_Title = new_title;
110 
111  if (m_SeqDescrCreated) {
112  m_SeqDescrCreated = false;
113  bioseq.ResetDescr();
114  }
115 }
116 
CBioseq_EditHandle –.
virtual void Unexecute()
Undo (opposite to Execute())
objects::CBioseq_Handle m_BH
virtual void Execute()
Do the editing action.
@Seq_descr.hpp User-defined methods of the data storage class.
Definition: Seq_descr.hpp:55
TBioseqCore GetBioseqCore(void) const
Get bioseq core structure.
void Reset(void)
Reset reference object.
Definition: ncbiobj.hpp:773
#define END_NCBI_SCOPE
End previously defined NCBI scope.
Definition: ncbistl.hpp:103
#define BEGIN_NCBI_SCOPE
Define ncbi namespace.
Definition: ncbistl.hpp:100
#define NcbiEmptyString
Definition: ncbistr.hpp:122
list< CRef< CSeqdesc > > Tdata
Definition: Seq_descr_.hpp:91
void ResetDescr(void)
Reset Descr data member.
Definition: Bioseq_.cpp:60
TTitle & SetTitle(void)
Select the variant.
Definition: Seqdesc_.hpp:1039
const TTitle & GetTitle(void) const
Get the variant data.
Definition: Seqdesc_.hpp:1032
bool IsSetDescr(void) const
descriptors Check if a value has been assigned to Descr data member.
Definition: Bioseq_.hpp:303
void SetDescr(TDescr &value)
Assign a value to Descr data member.
Definition: Bioseq_.cpp:65
USING_SCOPE(objects)
Modified on Wed Feb 21 09:54:41 2024 by modify_doxy.py rev. 669887