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

Go to the SVN repository for this file.

1 #ifndef OBJECTS_OBJMGR_IMPL___SEQ_ANNOT_EDIT_COMMNADS__HPP
2 #define OBJECTS_OBJMGR_IMPL___SEQ_ANNOT_EDIT_COMMNADS__HPP
3 
4 /* $Id: seq_annot_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 
43 
45 
46 #include <string>
47 
50 
51 ///////////////////////////////////////////////////////////////////////////////
52 ///////////////////////////////////////////////////////////////////////////////
53 template<>
56  static inline void Do(CScope_Impl& scope,
57  const CSeq_entry_EditHandle& ,
58  const Handle& handle)
59  {
60  scope.RemoveAnnot(handle);
61  }
62  static inline void Undo(CScope_Impl& scope,
63  const CSeq_entry_EditHandle& entry,
64  const Handle& handle)
65  {
66  scope.AttachAnnot(entry, handle);
67  }
68  static inline void DoInDB(IEditSaver& saver,
69  const CSeq_entry_EditHandle& entry,
70  const Handle& handle )
71  { saver.Remove(entry, handle, IEditSaver::eDo); }
72  static inline void UndoInDB(IEditSaver& saver,
73  const CBioObjectId& ,
74  const CSeq_entry_EditHandle& entry,
75  const Handle& handle)
76  { saver.Attach(entry, handle, IEditSaver::eUndo); }
77 };
78 
79 
82 
83 
84 
85 
86 
87 ///////////////////////////////////////////////////////////////////////////////
88 ///////////////////////////////////////////////////////////////////////////////
89 template<typename Handle>
91 
92 template<>
95  typedef CSeq_feat TData;
96  static inline CConstRef<TData> GetData(const THandle& handle)
97  { return handle.GetSeq_feat(); }
98 };
99 
100 template<>
103  typedef CSeq_align TData;
104  static inline CConstRef<TData> GetData(const THandle& handle)
105  { return handle.GetSeq_align(); }
106 };
107 
108 template<>
111  typedef CSeq_graph TData;
112  static inline CConstRef<TData> GetData(const THandle& handle)
113  { return handle.GetSeq_graph(); }
114 };
115 
116 template<typename Handle>
118 {
119 public:
120 
122  typedef typename TResolver::TData TData;
123 
125  const TData& data)
126  : m_Handle(handle), m_Data(&data),
127  m_WasRemoved(handle.IsRemoved())
128  {}
129 
131 
132  virtual void Do(IScopeTransaction_Impl& tr)
133  {
134  IEditSaver* saver = GetEditSaver(m_Handle.GetAnnot());
135  if (!m_WasRemoved) {
136  m_OldData = TResolver::GetData(m_Handle);
137  }
138  m_Handle.x_RealReplace(*m_Data);
139 
140  tr.AddCommand(CRef<IEditCommand>(this));
141  if (saver) {
142  tr.AddEditSaver(saver);
143  if( !m_WasRemoved )
145  else
146  saver->Add(m_Handle.GetAnnot(),
148  }
149 
150  }
151  virtual void Undo()
152  {
153  if (!m_WasRemoved)
154  m_Handle.x_RealReplace(*m_OldData);
155  else
156  m_Handle.x_RealRemove();
157  IEditSaver* saver = GetEditSaver(m_Handle.GetAnnot());
158  if (saver) {
159  if (!m_WasRemoved)
161  else
162  saver->Remove(m_Handle.GetAnnot(), *m_Data, IEditSaver::eUndo);
163  }
164  }
165 
166 private:
170 
172 };
173 
174 ///////////////////////////////////////////////////////////////////////////////
175 ///////////////////////////////////////////////////////////////////////////////
176 template<typename Handle>
178 {
179 public:
180 
182  typedef typename TResolver::TData TData;
183 
185  const TData& data)
186  : m_Handle(handle), m_Data(&data)
187  {}
188 
190 
191  virtual void Do(IScopeTransaction_Impl& tr)
192  {
194  tr.AddCommand(CRef<IEditCommand>(this));
195  IEditSaver* saver = GetEditSaver(m_Handle);
196  if (saver) {
197  tr.AddEditSaver(saver);
198  saver->Add(m_Handle, *m_Data, IEditSaver::eDo);
199  }
200  }
201  virtual void Undo()
202  {
203  IEditSaver* saver = GetEditSaver(m_Handle);
204  m_Ret.x_RealRemove();
205  if (saver) {
207  }
208  }
209 
210  Handle GetRet() const { return m_Ret; }
211 
212 private:
215 
217 };
218 
219 
220 template<typename Handle>
223  typedef Handle TReturn;
224  static inline TReturn GetRet(TCMD* cmd) { return cmd->GetRet(); }
225 };
226 
227 ///////////////////////////////////////////////////////////////////////////////
228 ///////////////////////////////////////////////////////////////////////////////
229 template<typename Handle>
231 {
232 public:
233 
235  typedef typename TResolver::TData TData;
236 
238  : m_Handle(handle) {}
239 
241 
242  virtual void Do(IScopeTransaction_Impl& tr)
243  {
244  IEditSaver* saver = GetEditSaver(m_Handle.GetAnnot());
245  m_Data = TResolver::GetData(m_Handle);
246  m_Handle.x_RealRemove();
247  tr.AddCommand(CRef<IEditCommand>(this));
248  if (saver) {
249  tr.AddEditSaver(saver);
250  saver->Remove(m_Handle.GetAnnot(), *m_Data, IEditSaver::eDo);
251  }
252  }
253  virtual void Undo()
254  {
255  m_Handle.x_RealReplace(*m_Data);
256  IEditSaver* saver = GetEditSaver(m_Handle.GetAnnot());
257  if (saver) {
258  saver->Add(m_Handle.GetAnnot(),
260  //saver->Replace(m_Handle, *m_Data, IEditSaver::eUndo);
261  }
262  }
263 
264 private:
267 };
268 
269 
272 
273 #endif // OBJECTS_OBJMGR_IMPL___SEQ_ANNOT_EDIT_COMMNADS__HPP
CRef –.
Definition: ncbiobj.hpp:618
void RemoveAnnot(const CSeq_annot_EditHandle &annot)
CSeq_annot_EditHandle AttachAnnot(const CSeq_entry_EditHandle &entry, CSeq_annot &annot)
Definition: scope_impl.cpp:877
AnnotDataResolver< Handle > TResolver
CSeq_annot_Add_EditCommand(const CSeq_annot_EditHandle &handle, const TData &data)
virtual void Do(IScopeTransaction_Impl &tr)
virtual void Do(IScopeTransaction_Impl &tr)
CSeq_annot_Remove_EditCommand(const Handle &handle)
AnnotDataResolver< Handle > TResolver
virtual void Do(IScopeTransaction_Impl &tr)
AnnotDataResolver< Handle > TResolver
CSeq_annot_Replace_EditCommand(const Handle &handle, const TData &data)
CSeq_entry_Handle –.
CSeq_feat_EditHandle –.
namespace ncbi::objects::
Definition: Seq_feat.hpp:58
Interface (functor) for object editing.
Edit Saver Interface.
Definition: edit_saver.hpp:72
virtual void Remove(const CSeq_entry_Handle &entry, const CSeq_annot_Handle &what, ECallMode)=0
virtual void Replace(const CSeq_feat_Handle &handle, const CSeq_feat &old_value, ECallMode)=0
@ 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 Add(const CSeq_annot_Handle &handle, const CSeq_feat &obj, ECallMode)=0
virtual void Attach(const CBioObjectId &old_id, 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.
static CS_COMMAND * cmd
Definition: ct_dynamic.c:26
IEditSaver * GetEditSaver(const Handle &handle)
#define Handle
Definition: ncbistd.hpp:119
CConstRef< CSeq_graph > GetSeq_graph(void) const
Get constant reference to the current seq-graph.
virtual CConstRef< CSeq_feat > GetSeq_feat(void) const
CSeq_feat_EditHandle x_RealAdd(const CSeq_feat &new_obj) const
CConstRef< CSeq_align > GetSeq_align(void) const
Get const reference to current seq-align.
#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
Portable reference counted smart and weak pointers using CWeakRef, CRef, CObject and CObjectEx.
CRemove_EditCommand< CSeq_annot_EditHandle > CRemoveAnnot_EditCommand
static CConstRef< TData > GetData(const THandle &handle)
static CConstRef< TData > GetData(const THandle &handle)
static CConstRef< TData > GetData(const THandle &handle)
static void Undo(CScope_Impl &scope, const CSeq_entry_EditHandle &entry, const Handle &handle)
static void UndoInDB(IEditSaver &saver, const CBioObjectId &, const CSeq_entry_EditHandle &entry, const Handle &handle)
static void DoInDB(IEditSaver &saver, const CSeq_entry_EditHandle &entry, const Handle &handle)
static void Do(CScope_Impl &scope, const CSeq_entry_EditHandle &, const Handle &handle)
Modified on Wed Feb 21 09:54:02 2024 by modify_doxy.py rev. 669887