NCBI C++ ToolKit
seq_entry_edit_commands.hpp
Go to the documentation of this file.

Go to the SVN repository for this file.

1 #ifndef OBJECTS_OBJMGR_IMPL___SEQ_ENTRY_EDIT_COMMNADS__HPP
2 #define OBJECTS_OBJMGR_IMPL___SEQ_ENTRY_EDIT_COMMNADS__HPP
3 
4 /* $Id: seq_entry_edit_commands.hpp 33815 2007-05-04 17:18:18Z kazimird $
5 * ===========================================================================
6 *
7 * PUBLIC DOMAIN NOTICE
8 * National Center for Biotechnology Information
9 *
10 * This software/database is a "United States Government Work" under the
11 * terms of the United States Copyright Act. It was written as part of
12 * the author's official duties as a United States Government employee and
13 * thus cannot be copyrighted. This software/database is freely available
14 * to the public for use. The National Library of Medicine and the U.S.
15 * Government have not placed any restriction on its use or reproduction.
16 *
17 * Although all reasonable efforts have been taken to ensure the accuracy
18 * and reliability of the software and data, the NLM and the U.S.
19 * Government do not and cannot warrant the performance or results that
20 * may be obtained by using this software or data. The NLM and the U.S.
21 * Government disclaim all warranties, express or implied, including
22 * warranties of performance, merchantability or fitness for any particular
23 * purpose.
24 *
25 * Please cite the author in any work or product based on this material.
26 *
27 * ===========================================================================
28 *
29 * Author: Maxim Didenko
30 *
31 * File Description:
32 *
33 */
34 
35 #include <corelib/ncbistd.hpp>
36 #include <corelib/ncbiobj.hpp>
37 
39 
43 #include <objmgr/bioseq_handle.hpp>
44 
45 #include <string>
46 
49 
50 class CScope_Impl;
51 
52 ///////////////////////////////////////////////////////////////////////////////
53 ///////////////////////////////////////////////////////////////////////////////
54 
55 template<typename Handle, typename Data>
57 
58 template<typename Data>
61  typedef typename TTrait::TStorage TStorage;
62 
63  static inline CBioseq_EditHandle Do(CScope_Impl& scope,
64  const CSeq_entry_EditHandle& handle,
65  TStorage data)
66  { return scope.SelectSeq(handle, TTrait::Restore(data)); }
67 };
68 
69 template<typename Data>
72  typedef typename TTrait::TStorage TStorage;
73 
74  static inline CBioseq_set_EditHandle Do(CScope_Impl& scope,
75  const CSeq_entry_EditHandle& handle,
76  TStorage data)
77  { return scope.SelectSet(handle, TTrait::Restore(data)); }
78 };
79 
80 template<typename Handle, typename Data>
82 {
83 public:
84 
87  typedef typename TTrait::TStorage TStorage;
88  typedef typename TTrait::TRef TRef;
89 
91  TRef data,
92  CScope_Impl& scope)
93  : m_Handle(handle), m_Data(TTrait::Store(data)), m_Scope(scope) {}
94 
96 
97  virtual void Do(IScopeTransaction_Impl& tr)
98  {
100  m_RetHandle = Action::Do(m_Scope, m_Handle, m_Data);
101  if (!m_RetHandle)
102  return;
103  tr.AddCommand(CRef<IEditCommand>(this));
104  IEditSaver* saver = GetEditSaver(m_Handle);
105  if (saver) {
106  tr.AddEditSaver(saver);
107  saver->Attach(old_id, m_Handle, m_RetHandle, IEditSaver::eDo);
108  }
109 
110  }
111  virtual void Undo()
112  {
114  IEditSaver* saver = GetEditSaver(m_Handle);
115  if (saver) {
117  }
118  }
119  Handle GetRet() const { return m_RetHandle; }
120 
121 private:
126 };
127 
128 template<typename Handle, typename Data>
131  typedef Handle TReturn;
132  static inline TReturn GetRet(CMD* cmd) { return cmd->GetRet(); }
133 };
134 
135 
136 ///////////////////////////////////////////////////////////////////////////////
137 ///////////////////////////////////////////////////////////////////////////////
139 {
140 public:
142  CScope_Impl& scope);
144 
145  virtual void Do(IScopeTransaction_Impl& tr);
146  virtual void Undo();
147 
148 private:
153 };
154 
155 ///////////////////////////////////////////////////////////////////////////////
156 ///////////////////////////////////////////////////////////////////////////////
157 
159 {
160 public:
161 
163  CScope_Impl& scope)
164  : m_Handle(handle), m_Scope(scope), m_Index(-1) {}
165 
167 
168  virtual void Do(IScopeTransaction_Impl& tr);
169  virtual void Undo();
170 
171 private:
175  int m_Index;
176 };
177 
178 ///////////////////////////////////////////////////////////////////////////////
179 ///////////////////////////////////////////////////////////////////////////////
180 
182 {
183 public:
184 
186  CScope_Impl& scope)
187  : m_Handle(handle), m_Scope(scope) {}
188 
189  virtual ~CRemoveTSE_EditCommand();
190 
191  virtual void Do(IScopeTransaction_Impl& tr);
192  virtual void Undo();
193 
194 private:
197 };
198 
199 ///////////////////////////////////////////////////////////////////////////////
200 ///////////////////////////////////////////////////////////////////////////////
201 
202 template<>
205  static inline void Set(IEditSaver& saver,
206  const Handle& handle,
207  const CSeq_descr& data,
209  {
210  if (handle.IsSeq())
211  saver.SetDescr(handle.GetSeq(), data, mode);
212  else if (handle.IsSet())
213  saver.SetDescr(handle.GetSet(), data, mode);
214  }
215 
216  static inline void Reset(IEditSaver& saver,
217  const Handle& handle,
219  {
220  if (handle.IsSeq())
221  saver.ResetDescr(handle.GetSeq(), mode);
222  else if (handle.IsSet())
223  saver.ResetDescr(handle.GetSet(), mode);
224  }
225 
226  static inline void Add(IEditSaver& saver,
227  const Handle& handle,
228  const CSeq_descr& data,
230  {
231  if (handle.IsSeq())
232  saver.AddDescr(handle.GetSeq(), data, mode);
233  else if (handle.IsSet())
234  saver.AddDescr(handle.GetSet(), data, mode);
235  }
236 };
237 
238 template<>
241  static inline void Add(IEditSaver& saver,
242  const Handle& handle,
243  const CSeqdesc& desc,
245  {
246 
247  if (handle.IsSeq())
248  saver.AddDesc(handle.GetSeq(),desc,mode);
249  else if (handle.IsSet())
250  saver.AddDesc(handle.GetSet(),desc,mode);
251  }
252  static inline void Remove(IEditSaver& saver,
253  const Handle& handle,
254  const CSeqdesc& desc,
256  {
257  if (handle.IsSeq())
258  saver.RemoveDesc(handle.GetSeq(),desc,mode);
259  else if (handle.IsSet())
260  saver.RemoveDesc(handle.GetSet(),desc,mode);
261  }
262 };
263 
264 
265 ///////////////////////////////////////////////////////////////////////////////
266 ///////////////////////////////////////////////////////////////////////////////
267 
268 template<typename Annot>
270 {
271 public:
273  typedef typename TTrait::TStorage TStorage;
274  typedef typename TTrait::TRef TRef;
275 
277  TRef annot,
278  CScope_Impl& scope)
279  : m_Handle(handle), m_Annot(TTrait::Store(annot)), m_Scope(scope)
280  {}
281 
283 
284  virtual void Do(IScopeTransaction_Impl& tr)
285  {
288  if (!m_AnnotHandle)
289  return;
290  tr.AddCommand(CRef<IEditCommand>(this));
291  IEditSaver* saver = GetEditSaver(m_Handle);
292  if (saver) {
293  tr.AddEditSaver(saver);
295  }
296 
297  }
298  virtual void Undo()
299  {
302  IEditSaver* saver = GetEditSaver(m_Handle);
303  if (saver) {
305  }
306  }
307 
309 
310 private:
314 
316 
317 };
318 
319 template<typename Annot>
323  static inline TReturn GetRet(CMD* cmd) { return cmd->GetRet(); }
324 };
325 
326 
329 
330 #endif // OBJECTS_OBJMGR_IMPL___SEQ_ENTRY_EDIT_COMMNADS__HPP
static CRef< CScope > m_Scope
CSeq_annot_EditHandle m_AnnotHandle
CAttachAnnot_EditCommand(const CSeq_entry_EditHandle &handle, TRef annot, CScope_Impl &scope)
virtual void Do(IScopeTransaction_Impl &tr)
CSeq_annot_EditHandle GetRet() const
MemetoTrait< Annot, IsCRef< Annot >::value > TTrait
CBioseq_EditHandle –.
CBioseq_set_EditHandle –.
CRef –.
Definition: ncbiobj.hpp:618
CSeq_entry_EditHandle m_Handle
CRemoveTSE_EditCommand(const CSeq_entry_EditHandle &handle, CScope_Impl &scope)
void RemoveAnnot(const CSeq_annot_EditHandle &annot)
CBioseq_set_EditHandle SelectSet(const CSeq_entry_EditHandle &entry, CBioseq_set &seqset)
Definition: scope_impl.cpp:817
void SelectNone(const CSeq_entry_EditHandle &entry)
CSeq_annot_EditHandle AttachAnnot(const CSeq_entry_EditHandle &entry, CSeq_annot &annot)
Definition: scope_impl.cpp:878
CBioseq_EditHandle SelectSeq(const CSeq_entry_EditHandle &entry, CBioseq &seq)
Definition: scope_impl.cpp:760
@Seq_descr.hpp User-defined methods of the data storage class.
Definition: Seq_descr.hpp:55
CSeq_entry_Handle –.
int m_Index
CScope_Impl & m_Scope
CSeq_entry_EditHandle m_Handle
CBioseq_set_EditHandle m_ParentHandle
CSeq_entry_Remove_EditCommand(const CSeq_entry_EditHandle &handle, CScope_Impl &scope)
CScope_Impl & m_Scope
CBioseq_EditHandle m_BioseqHandle
CSeq_entry_EditHandle m_Handle
CBioseq_set_EditHandle m_BioseqSetHandle
virtual void Undo()
Handle m_RetHandle
CSeq_entry_Select_EditCommand(const CSeq_entry_EditHandle &handle, TRef data, CScope_Impl &scope)
MemetoTrait< Data, IsCRef< Data >::value > TTrait
TTrait::TStorage TStorage
virtual void Do(IScopeTransaction_Impl &tr)
CScope_Impl & m_Scope
TStorage m_Data
CSeq_entry_EditHandle m_Handle
virtual ~CSeq_entry_Select_EditCommand()
Handle GetRet() const
SeqEntrySelectAction< Handle, Data > Action
TTrait::TRef TRef
Interface (functor) for object editing.
virtual void Do(IScopeTransaction_Impl &)=0
virtual void Undo()=0
Edit Saver Interface.
Definition: edit_saver.hpp:72
virtual void Remove(const CSeq_entry_Handle &entry, const CSeq_annot_Handle &what, ECallMode)=0
ECallMode
This flag can be used for optimization purpose.
Definition: edit_saver.hpp:76
@ eUndo
The method is called when a modification has just been undone.
Definition: edit_saver.hpp:78
@ eDo
The method is called when a modification has just been done.
Definition: edit_saver.hpp:77
virtual void SetDescr(const CBioseq_Handle &, const CSeq_descr &, ECallMode)=0
virtual void AddDesc(const CBioseq_Handle &, const CSeqdesc &, ECallMode)=0
virtual void RemoveDesc(const CBioseq_Handle &, const CSeqdesc &, ECallMode)=0
virtual void AddDescr(const CBioseq_Handle &, const CSeq_descr &, ECallMode)=0
Description operations.
virtual void Attach(const CBioObjectId &old_id, const CSeq_entry_Handle &entry, const CBioseq_Handle &what, ECallMode)=0
virtual void ResetDescr(const CBioseq_Handle &, ECallMode)=0
virtual void Detach(const CSeq_entry_Handle &entry, const CBioseq_Handle &what, ECallMode)=0
virtual void AddCommand(TCommand)=0
virtual void AddEditSaver(IEditSaver *)=0
Include a standard set of the NCBI C++ Toolkit most basic headers.
IEditSaver * GetEditSaver(const Handle &handle)
static CS_COMMAND * cmd
Definition: ct_dynamic.c:26
char data[12]
Definition: iconv.c:80
#define Handle
Definition: ncbistd.hpp:119
const CBioObjectId & GetBioObjectId(void) const
Get unique object id.
TSet GetSet(void) const
TSeq GetSeq(void) const
bool IsSet(void) const
bool IsSeq(void) const
#define END_NCBI_SCOPE
End previously defined NCBI scope.
Definition: ncbistl.hpp:103
#define END_SCOPE(ns)
End the previously defined scope.
Definition: ncbistl.hpp:75
#define BEGIN_NCBI_SCOPE
Define ncbi namespace.
Definition: ncbistl.hpp:100
#define BEGIN_SCOPE(ns)
Define a new scope.
Definition: ncbistl.hpp:72
#define NCBI_XOBJMGR_EXPORT
Definition: ncbi_export.h:1307
mdb_mode_t mode
Definition: lmdb++.h:38
Portable reference counted smart and weak pointers using CWeakRef, CRef, CObject and CObjectEx.
Handle TReturn
static TReturn GetRet(CMD *cmd)
CSeq_entry_Select_EditCommand< Handle, Data > CMD
static void Add(IEditSaver &saver, const Handle &handle, const CSeq_descr &data, IEditSaver::ECallMode mode)
static void Reset(IEditSaver &saver, const Handle &handle, IEditSaver::ECallMode mode)
CSeq_entry_EditHandle Handle
static void Set(IEditSaver &saver, const Handle &handle, const CSeq_descr &data, IEditSaver::ECallMode mode)
static void Add(IEditSaver &saver, const Handle &handle, const CSeqdesc &desc, IEditSaver::ECallMode mode)
CSeq_entry_EditHandle Handle
static void Remove(IEditSaver &saver, const Handle &handle, const CSeqdesc &desc, IEditSaver::ECallMode mode)
static TRef Restore(TStorage t)
MemetoTrait< Data, IsCRef< Data >::value > TTrait
static CBioseq_EditHandle Do(CScope_Impl &scope, const CSeq_entry_EditHandle &handle, TStorage data)
MemetoTrait< Data, IsCRef< Data >::value > TTrait
static CBioseq_set_EditHandle Do(CScope_Impl &scope, const CSeq_entry_EditHandle &handle, TStorage data)
#define _ASSERT
Modified on Fri Sep 20 14:57:41 2024 by modify_doxy.py rev. 669887