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

Go to the SVN repository for this file.

1 /* $Id: project_item_extra.cpp 35093 2016-03-22 18:51:23Z 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: Liangshou Wu
27  *
28  * File Description:
29  *
30  */
31 
32 #include <ncbi_pch.hpp>
33 
35 
41 
44 
45 bool CProjectItemExtra::GetStr(const objects::CProjectItem& pi, const string& tag, string& value)
46 {
48 
49  for (auto d : pi.GetDescr()) {
50  if (d->IsUser()) {
51  const CUser_object& user = d->GetUser();
52  const CObject_id& type = user.GetType();
53  if (type.IsStr() && type.GetStr() == "ProjectItemExtra") {
54  userObj.Reset(&user);
55  break;
56  }
57  }
58  }
59 
60  if (!userObj)
61  return false;
62 
63  for (auto f : userObj->GetData()) {
64  const CObject_id& label = f->GetLabel();
65  if (label.IsStr() && label.GetStr() == tag) {
66  const CUser_field::TData& data = f->GetData();
67  if (data.IsStr()) {
68  value = data.GetStr();
69  return true;
70  }
71  }
72  }
73 
74  return false;
75 }
76 
77 void CProjectItemExtra::SetStr(objects::CProjectItem& pi, const string& tag, const string& value)
78 {
79  CRef<CAnnotdesc> desc;
80 
81  for (auto d : pi.GetDescr()) {
82  if (d->IsUser()) {
83  const CUser_object& user = d->GetUser();
84  const CObject_id& type = user.GetType();
85  if (type.IsStr() && type.GetStr() == "ProjectItemExtra") {
86  desc.Reset(d);
87  break;
88  }
89  }
90  }
91 
92  if (!desc) {
93  CRef<CUser_object> user(new CUser_object());
95  type->SetStr("ProjectItemExtra");
96  user->SetType(*type);
97 
98  desc.Reset(new CAnnotdesc());
99  desc->SetUser(*user);
100  pi.SetDescr().push_back(desc);
101  }
102 
103  CRef<CUser_field> field;
104 
105  for (auto f : desc->GetUser().GetData()) {
106  const CObject_id& label = f->GetLabel();
107  if (label.IsStr() && label.GetStr() == tag) {
108  field.Reset(f);
109  break;
110  }
111  }
112 
113  if (!field) {
114  field.Reset(new CUser_field());
116  label->SetStr(tag);
117  field->SetLabel(*label);
118  desc->SetUser().SetData().push_back(field);
119  }
120 
121  field->SetString(value);
122 }
123 
124 
125 
User-defined methods of the data storage class.
User-defined methods of the data storage class.
CAnnotdesc –.
Definition: Annotdesc.hpp:66
static void SetStr(objects::CProjectItem &pi, const string &tag, const string &value)
static bool GetStr(const objects::CProjectItem &pi, const string &tag, string &value)
CUser_field & SetString(const char *value)
Definition: User_field.cpp:445
static int type
Definition: getdata.c:31
char data[12]
Definition: iconv.c:80
const float pi
Definition: math.hpp:54
void Reset(void)
Reset reference object.
Definition: ncbiobj.hpp:1439
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
static const char label[]
TData & SetData(void)
Assign a value to Data data member.
void SetLabel(TLabel &value)
Assign a value to Label data member.
const TData & GetData(void) const
Get the Data member data.
void SetType(TType &value)
Assign a value to Type data member.
const TType & GetType(void) const
Get the Type member data.
TUser & SetUser(void)
Select the variant.
Definition: Annotdesc_.cpp:190
const TUser & GetUser(void) const
Get the variant data.
Definition: Annotdesc_.cpp:184
const GenericPointer< typename T::ValueType > T2 value
Definition: pointer.h:1227
const char * tag
double f(double x_, const double &y_)
Definition: njn_root.hpp:188
USING_SCOPE(objects)
Definition: type.c:6
Modified on Wed Sep 04 15:06:08 2024 by modify_doxy.py rev. 669887