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

Go to the SVN repository for this file.

1 /* $Id: Entrez2_id_list.cpp 96130 2022-02-14 17:11:53Z grichenk $
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 specifications from the ASN data definition file
34  * 'entrez2.asn'.
35  */
36 
37 // standard includes
38 
39 // generated includes
40 #include <ncbi_pch.hpp>
42 
44 
45 // generated classes
46 
48 
49 BEGIN_objects_SCOPE // namespace ncbi::objects::
50 
51 const size_t CEntrez2_id_list::sm_UidSize = sizeof(CEntrez2_id_list::TUid); // bytes
53 
54 
56 {
58  return TUidIterator(SetUids(), GetUidSizeBits());
59 }
60 
61 
64 {
65  if (CanGetUids()) {
67  } else {
69  }
70 }
71 
72 
73 // destructor
75 {
76 }
77 
78 
80 {
82  SetUids().resize(size * sizeof(TUid));
83  SetNum(size);
84 }
85 
86 
87 void CEntrez2_id_list::AssignUids(const vector<TUid>& uids)
88 {
89  Resize(uids.size());
90 
92  ITERATE (vector<TUid>, iter, uids) {
93  *it++ = *iter;
94  }
95 }
96 
97 
99 {
100  return GetUidSizeBytes() * 8;
101 }
102 
103 
105 {
106  // Max size - actual size of TUid
107  size_t ret = sizeof(TUid);
108  if ( !CanGetUids() || !CanGetNum() ) return ret;
109  // Min size - 4 bytes (legacy int TUid)
110  while ( ret > 4 && ret * GetNum() > GetUids().size() ) ret /= 2;
111  return ret;
112 }
113 
114 
116 {
117  if ( !CanGetNum() || !CanGetUids() ) return;
118  size_t num = GetNum();
119  vector<TUid> uids;
120  uids.reserve(num);
121  for (TConstUidIterator it = GetConstUidIterator(); !it.AtEnd(); ++it) {
122  uids.push_back(*it);
123  if (uids.back() > kMax_UI4) return;
124  }
125  SetUids().resize(num * sizeof(Int4));
126  auto it = TUidIterator(SetUids(), sizeof(Int4)*8);
127  ITERATE (vector<TUid>, iter, uids) {
128  *it++ = *iter;
129  }
130 }
131 
132 
134 {
135  // If using non-native UID size, always switch to the native one on modification.
136  if ( GetUidSizeBytes() == sizeof(TUid) ) return;
137  vector<TUid> uids;
138  uids.reserve(GetNum());
139  for (TConstUidIterator it = GetConstUidIterator(); !it.AtEnd(); ++it) {
140  uids.push_back(*it);
141  }
142  AssignUids(uids);
143 }
144 
145 
146 END_objects_SCOPE // namespace ncbi::objects::
147 
149 
150 /* Original file checksum: lines: 61, chars: 1906, CRC32: 6647067f */
CSafeStatic< CEntrez2_id_list::TUids > s_EmptyList
size_t GetUidSizeBytes(void) const
TConstUidIterator GetConstUidIterator() const
void AssignUids(const vector< TUid > &uids)
void x_SetNativeUidSize(void)
CResizingIterator< TUids, TUid > TUidIterator
void Resize(size_t size)
CConstResizingIterator< TUids, TUid > TConstUidIterator
static const size_t sm_UidSize
TUidIterator GetUidIterator()
size_t GetUidSizeBits(void) const
CSafeStatic<>::
#define ITERATE(Type, Var, Cont)
ITERATE macro to sequence through container elements.
Definition: ncbimisc.hpp:815
int32_t Int4
4-byte (32-bit) signed integer
Definition: ncbitype.h:102
#define kMax_UI4
Definition: ncbi_limits.h:219
#define END_NCBI_SCOPE
End previously defined NCBI scope.
Definition: ncbistl.hpp:103
#define BEGIN_NCBI_SCOPE
Define ncbi namespace.
Definition: ncbistl.hpp:100
TUids & SetUids(void)
Assign a value to Uids data member.
const TUids & GetUids(void) const
Get the Uids member data.
bool CanGetUids(void) const
Check if it is safe to call GetUids method.
TNum GetNum(void) const
Get the Num member data.
bool CanGetNum(void) const
Check if it is safe to call GetNum method.
TNum & SetNum(void)
Assign a value to Num data member.
const struct ncbi::grid::netcache::search::fields::SIZE size
Static variables safety - create on demand, destroy on application termination.
Modified on Thu Sep 21 03:44:48 2023 by modify_doxy.py rev. 669887