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

Go to the SVN repository for this file.

1 /* $Id: GBWorkspace.cpp 47479 2023-05-02 13:24:02Z ucko $
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  * 'gui_project.asn'.
35  */
36 
37 // standard includes
38 #include <ncbi_pch.hpp>
39 
40 // generated includes
45 #include <serial/iterator.hpp>
46 #include <gui/objutils/label.hpp>
47 
48 #include <algorithm>
49 
50 // generated classes
51 
53 
54 BEGIN_objects_SCOPE // namespace ncbi::objects::
55 
56 
58 {
59 public:
60  void GetLabel(const CObject& obj, string* str,
62  objects::CScope* scope) const
63  {
64  const CGBWorkspace* wks = dynamic_cast<const CGBWorkspace*>(&obj);
65  if (wks && wks->IsSetWorkspace()) {
67  string s;
68  for ( ; iter; ++iter) {
69  if ( !s.empty() ) {
70  s += "; ";
71  }
72  CLabel::GetLabel(*iter, &s, type, scope);
73  }
74  *str += s;
75  }
76  }
77 };
78 
79 
80 ///////////////////////////////////////////////////////////////////////////////
81 /// CGBWorkspace
82 
84 
86 {
87  m_Id = m_IdCounter.Add(1) - 1;
88 
89  if ( !CLabel::HasHandler(*CGBWorkspace::GetTypeInfo()) ) {
90  CLabel::RegisterLabelHandler(*CGBWorkspace::GetTypeInfo(),
92  }
93 }
94 
95 
96 // destructor
98 {
99 }
100 
101 
103 {
104  for (CTypeIterator<CGBProjectHandle> it(SetWorkspace()); it; ++it) {
105  if (&scope == it->GetScope()) {
106  return &*it;
107  }
108  }
109  return 0;
110 }
111 
112 
114 {
115  for (CTypeIterator<CGBProjectHandle> it(SetWorkspace()); it; ++it) {
116  if (id == it->GetId()) {
117  return &*it;
118  }
119  }
120  return 0;
121 }
122 
123 
125 {
127  if (parent) {
128  parent->RemoveProject(id);
129  return true;
130  }
131  return false;
132 }
133 
134 
135 string CGBWorkspace::MakeUniqueProjectTitle(const string& label) const
136 {
137  CUniqueLabelGenerator generator;
138  const CWorkspaceFolder& root = GetWorkspace();
139  for ( CTypeConstIterator<CGBProjectHandle> it(root); it; ++it) {
140  const string& s = it->GetTitle();
141  generator.AddExistingLabel(s);
142  }
143  return generator.MakeUniqueLabel(label);
144 }
145 
146 
147 vector<CGBProjectHandle::TId> CGBWorkspace::GetUnloadedProjects() const
148 {
149  vector<CGBProjectHandle::TId> projIds;
150  for (CTypeConstIterator<CGBProjectHandle> it(GetWorkspace()); it; ++it) {
151  if (!it->IsLoaded())
152  projIds.push_back(it->GetId());
153  }
154  return projIds;
155 }
156 
157 
158 vector<CGBProjectHandle::TId> CGBWorkspace::GetLoadedProjects() const
159 {
160  vector<CGBProjectHandle::TId> projIds;
161  for (CTypeConstIterator<CGBProjectHandle> it(GetWorkspace()); it; ++it) {
162  if (it->IsLoaded())
163  projIds.push_back(it->GetId());
164  }
165  return projIds;
166 }
167 
168 
169 END_objects_SCOPE // namespace ncbi::objects::
170 
172 
173 /* Original file checksum: lines: 65, chars: 1894, CRC32: 164c029b */
User-defined methods of the data storage class.
User-defined methods of the data storage class.
CAtomicCounter –.
Definition: ncbicntr.hpp:71
CAtomicCounter::TValue TId
void GetLabel(const CObject &obj, string *str, CLabel::ELabelType type, objects::CScope *scope) const
Definition: GBWorkspace.cpp:60
CGBWorkspace.
Definition: GBWorkspace.hpp:63
CGBProjectHandle * GetProjectFromId(CGBProjectHandle::TId id)
CGBProjectHandle * GetProjectFromScope(const CScope &scope)
vector< CGBProjectHandle::TId > GetLoadedProjects() const
~CGBWorkspace(void)
Definition: GBWorkspace.cpp:97
static CAtomicCounter m_IdCounter
CGBWorkspace.
Definition: GBWorkspace.hpp:99
vector< CGBProjectHandle::TId > GetUnloadedProjects() const
TId m_Id
instance run-time Id, unique within an application session
CGBWorkspace(void)
Definition: GBWorkspace.cpp:85
string MakeUniqueProjectTitle(const string &label) const
Create a unique label for a project.
bool RemoveProject(CGBProjectHandle::TId id)
CObject –.
Definition: ncbiobj.hpp:180
CScope –.
Definition: scope.hpp:92
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
CUniqueLabelGenerator Modifies the given label so that it becomes unique in the given set of labels b...
bool RemoveProject(CGBProjectHandle::TId id)
const CWorkspaceFolder * FindParentFolder(CGBProjectHandle::TId id) const
ILabelHandler interface.
Definition: label.hpp:136
static const char * str(char *buf, int n)
Definition: stats.c:84
TValue Add(int delta) THROWS_NONE
Atomically add value (=delta), and return new counter value.
Definition: ncbicntr.hpp:278
static void RegisterLabelHandler(const string &type, ILabelHandler &handler)
Definition: label.cpp:229
static void GetLabel(const CObject &obj, string *label, ELabelType type=eDefault)
Definition: label.cpp:140
string MakeUniqueLabel(const string &label) const
after considering all existing labels produces a modified unique version of the original label
static bool HasHandler(const CTypeInfo &type)
Definition: label.cpp:243
void AddExistingLabel(const string &label)
adds an existing label
ELabelType
Definition: label.hpp:60
#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[]
TWorkspace & SetWorkspace(void)
Assign a value to Workspace data member.
bool IsSetWorkspace(void) const
projects in this workspace Check if a value has been assigned to Workspace data member.
const TWorkspace & GetWorkspace(void) const
Get the Workspace member data.
Definition: type.c:6
Modified on Wed Apr 17 13:08:53 2024 by modify_doxy.py rev. 669887