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

Go to the SVN repository for this file.

1 /* $Id: ProjectFolder.cpp 62336 2014-04-02 14:55:10Z 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  * Author: .......
27  *
28  * File Description:
29  * .......
30  *
31  * Remark:
32  * This code was originally generated by application DATATOOL
33  * using the following specifications:
34  * 'gbproj.asn'.
35  */
36 
37 // standard includes
38 #include <ncbi_pch.hpp>
39 
40 // generated includes
42 #include <serial/iterator.hpp>
43 
44 // generated classes
45 
47 
48 BEGIN_objects_SCOPE // namespace ncbi::objects::
49 
51 
52 // destructor
54 {
55 }
56 
57 
58 /// CIdSelector finds a Project Item by Id
60 {
61 public:
63  : m_Id(id), m_Item(NULL) {}
64 
65  virtual bool Visit(CProjectItem& item)
66  {
67  if(item.GetId() == m_Id) {
68  m_Item = &item;
69  return false; // stop iterating
70  }
71  return true; // continue
72  }
73 
74 public:
77 };
78 
79 
80 /// CLabelSelector finds a Project Item by Label
82 {
83 public:
85  : m_Label(label), m_Item(NULL) {}
86 
87  virtual bool Visit(CProjectItem& item)
88  {
89  if(item.GetLabel() == m_Label) {
90  m_Item = &item;
91  return false; // stop iterating
92  }
93  return true; // continue
94  }
95 
96 public:
97  string m_Label;
99 };
100 
101 
103 {
104 public:
106  : m_Object(&object), m_Item(NULL) {}
107 
108  virtual bool Visit(CProjectItem& item)
109  {
110  if(item.GetObject() == m_Object) {
111  m_Item = &item;
112  return false; // stop iterating
113  }
114  return true; // continue
115  }
116 
117 public:
120 };
121 
122 
124 {
125  CPrjItemSelector_Label selector(label);
126  ForEachProjectItem(selector, false);
127  return selector.m_Item;
128 }
129 
130 
132 {
133  if (!CanGetItems())
134  return 0;
135 
136  ITERATE (TItems, it, GetItems()) {
137  if ((*it)->GetId() == id) {
138  return *it;
139  }
140  }
141  return 0;
142 }
143 
144 
146 {
147  const CProjectItem* item = const_cast<const CProjectFolder&>(*this).GetProjectItem(id);
148  return const_cast<CProjectItem*>(item);
149 }
150 
151 
153 {
154  if (!CanGetFolders())
155  return 0;
156 
157  ITERATE (TFolders, it, GetFolders()) {
158  if ((*it)->GetId() == id) {
159  return *it;
160  }
161  }
162  return 0;
163 }
164 
165 
167 {
168  const CProjectFolder* item = const_cast<const CProjectFolder&>(*this).GetProjectFolder(id);
169  return const_cast<CProjectFolder*>(item);
170 }
171 
172 
174 {
175  const CProjectItem* item = 0;
176  for (CTypeConstIterator<CProjectItem> it(*this); it; ++it) {
177  if (it->GetId() == id) {
178  item = &*it;
179  break;
180  }
181  }
182  return item;
183 }
184 
186 {
187  const CProjectItem* item = const_cast<const CProjectFolder&>(*this).FindProjectItemById(id);
188  return const_cast<CProjectItem*>(item);
189 }
190 
191 
193  bool recursive)
194 {
195  CPrjItemSelector_Data selector(object);
196  ForEachProjectItem(selector, recursive);
197  return selector.m_Item;
198 }
199 
200 
202 {
203  const CProjectFolder* folder = 0;
204  for (CTypeConstIterator<CProjectFolder> it(*this); it; ++it) {
205  if (this == &*it)
206  continue;
207  if (it->GetId() == id) {
208  folder = &*it;
209  break;
210  }
211  }
212 
213  return folder;
214 }
215 
216 
218 {
219  const CProjectFolder* parent = const_cast<const CProjectFolder&>(*this).FindChildFolderById(id);
220  return const_cast<CProjectFolder*>(parent);
221 }
222 
223 
225 {
227  CProjectFolder& child = **it;
228  if(child.SetInfo().SetTitle() == title) {
229  return &child;
230  }
231  }
232  return NULL; // not found
233 }
234 
236 {
237  for (CTypeConstIterator<CProjectFolder> it(*this); it; ++it) {
238  if (it->GetProjectItem(id)) {
239  return &*it;
240  }
241  }
242  return 0;
243 }
244 
246 {
247  const CProjectFolder* parent = const_cast<const CProjectFolder&>(*this).FindProjectItemFolder(id);
248  return const_cast<CProjectFolder*>(parent);
249 }
250 
252 {
253  for (CTypeIterator<CProjectFolder> it(*this); it; ++it) {
254  CProjectFolder::TFolders& folders = it->SetFolders();
255  for (CProjectFolder::TFolders::iterator it2 = folders.begin(); it2 != folders.end(); ++it2) {
256  if ((*it2)->GetId() == id) {
257  CRef<CProjectFolder> removed(*it2);
258  folders.erase(it2);
259  return removed;
260  }
261  }
262  }
263  return CRef<CProjectFolder>();
264 }
265 
267 {
268  CRef<CProjectItem> ref(&child_item);
269  TItems& items = SetItems();
270  items.push_back(ref);
271 }
272 
273 
275 {
276  if(IsSetItems()) {
277  CRef<CProjectItem> ref(&child_item);
278  TItems& items = SetItems();
279  TItems::iterator it = std::find(items.begin(), items.end(), ref);
280  if(it != items.end()) {
281  items.erase(it);
282  return true;
283  }
284  }
285  return false;
286 }
287 
288 
290 {
291  if(IsSetItems()) {
292  TItems& items = SetItems();
293  NON_CONST_ITERATE(TItems, it, items) {
294  CProjectItem& item = **it;
295  if(item.GetId() == id) {
296  items.erase(it);
297  return true;
298  }
299  }
300  }
301  return false;
302 }
303 
304 
306 {
307  if(IsSetItems()) {
308  TItems& items = SetItems();
309  NON_CONST_ITERATE(TItems, it, items) {
310  CProjectItem& item = **it;
311  }
312  items.clear();
313  }
314 }
315 
316 
318 {
319  CRef<CProjectFolder> ref(&child_folder);
320  TFolders& folders = SetFolders();
321  folders.push_back(ref);
322 }
323 
324 
326 {
327  TFolders& folders = SetFolders();
328  CRef<CProjectFolder> ref(&child_folder);
329  TFolders::iterator it = std::find(folders.begin(), folders.end(), ref);
330 
331  if(it != folders.end()) {
332  folders.erase(it);
333  } else {
334  NCBI_THROW(CException, eUnknown, "Folder is not found.");
335  }
336 }
337 
338 
340 {
341  TFolders& folders = SetFolders();
342  NON_CONST_ITERATE(TFolders, it, folders) {
343  CProjectFolder& sub_folder = **it;
344  if(sub_folder.GetId() == folder_id) {
345  folders.erase(it);
346  return;
347  }
348  }
349  NCBI_THROW(CException, eUnknown, "Folder is not found.");
350 }
351 
353  bool recursive)
354 {
355  bool ok = true;
356 
357  if(IsSetItems()) {
358  // iterate through Project Items in this Folder
359  TItems& items = SetItems();
360  NON_CONST_ITERATE(TItems, it, items) {
361  CProjectItem& item = **it;
362  ok = visitor.Visit(item);
363  if( ! ok)
364  return false;
365  }
366  }
367 
368  if(recursive) {
369  // recursively iterate through child Folders
370  TFolders& folders = SetFolders();
371  NON_CONST_ITERATE(TFolders, it, folders) {
372  CProjectFolder& child = **it;
373  ok = child.ForEachProjectItem(visitor, true);
374  if( ! ok) {
375  return false;
376  }
377  }
378  }
379  return true;
380 }
381 
382 
383 END_objects_SCOPE // namespace ncbi::objects::
384 
386 
387 /* Original file checksum: lines: 57, chars: 1734, CRC32: b33bdb51 */
User-defined methods of the data storage class.
CAtomicCounter –.
Definition: ncbicntr.hpp:71
virtual bool Visit(CProjectItem &item)
const CSerialObject * m_Object
CPrjItemSelector_Data(const CSerialObject &object)
CIdSelector finds a Project Item by Id.
CProjectItem::TId m_Id
CPrjItemSelector_Id(CProjectItem::TId id)
virtual bool Visit(CProjectItem &item)
CProjectItem * m_Item
CLabelSelector finds a Project Item by Label.
CPrjItemSelector_Label(const string &label)
virtual bool Visit(CProjectItem &item)
virtual bool Visit(objects::CProjectItem &item)=0
const CProjectFolder * FindChildFolderById(TId id) const
void AddChildItem(CProjectItem &child_item)
CProjectItem * FindProjectItemById(CProjectItem::TId id)
static CAtomicCounter m_IdCounter
CAtomicCounter::TValue TId
const CProjectFolder * FindProjectItemFolder(CProjectItem::TId id) const
CProjectItem * FindProjectItemByLabel(const string &label)
void RemoveChildFolder(CProjectFolder &child_folder)
bool RemoveChildItem(CProjectItem &child_item)
TId GetId() const
const CProjectFolder * GetProjectFolder(CProjectFolder::TId id) const
CProjectItem * FindProjectItemByData(const CSerialObject &object, bool recursive)
const CProjectItem * GetProjectItem(CProjectItem::TId id) const
void RemoveAllChildItems()
CRef< CProjectFolder > RemoveProjectFolder(CProjectFolder::TId id)
CProjectFolder * FindChildFolderByTitle(const string &title)
bool ForEachProjectItem(IProjectItemVisitor &visitor, bool recursive)
applies the given visitor to all project items until the visitor returns false
void AddChildFolder(CProjectFolder &child_folder)
const CSerialObject * GetObject() const
retrieve the object pointed to as a CObject*
Base class for all serializable objects.
Definition: serialbase.hpp:150
Template class for iteration on objects of class C (non-medifiable version)
Definition: iterator.hpp:767
Template class for iteration on objects of class C.
Definition: iterator.hpp:673
#define ITERATE(Type, Var, Cont)
ITERATE macro to sequence through container elements.
Definition: ncbimisc.hpp:815
#define NON_CONST_ITERATE(Type, Var, Cont)
Non constant version of ITERATE macro.
Definition: ncbimisc.hpp:822
#define NULL
Definition: ncbistd.hpp:225
#define NCBI_THROW(exception_class, err_code, message)
Generic macro to throw an exception, given the exception class, error code and message string.
Definition: ncbiexpt.hpp:704
#define END_NCBI_SCOPE
End previously defined NCBI scope.
Definition: ncbistl.hpp:103
#define BEGIN_NCBI_SCOPE
Define ncbi namespace.
Definition: ncbistl.hpp:100
static const char label[]
list< CRef< CProjectItem > > TItems
TId GetId(void) const
Get the Id member data.
TFolders & SetFolders(void)
Assign a value to Folders data member.
bool IsSetItems(void) const
Check if a value has been assigned to Items data member.
const TLabel & GetLabel(void) const
Get the Label member data.
const TFolders & GetFolders(void) const
Get the Folders member data.
list< CRef< CProjectFolder > > TFolders
void SetInfo(TInfo &value)
Assign a value to Info data member.
bool CanGetItems(void) const
Check if it is safe to call GetItems method.
const TItems & GetItems(void) const
Get the Items member data.
bool CanGetFolders(void) const
Check if it is safe to call GetFolders method.
TItems & SetItems(void)
Assign a value to Items data member.
Modified on Wed Feb 21 09:55:54 2024 by modify_doxy.py rev. 669887