ATLAS Offline Software
PackedArray.h
Go to the documentation of this file.
1 // This file's extension implies that it's C, but it's really -*- C++ -*-.
2 
3 /*
4  Copyright (C) 2002-2019 CERN for the benefit of the ATLAS collaboration
5 */
6 
7 // $Id: PackedArray.h,v 1.2 2007-06-14 22:38:48 ssnyder Exp $
15 #ifndef CXXUTILS_PACKEDARRAY_H
16 #define CXXUTILS_PACKEDARRAY_H
17 
18 
19 #include <vector>
20 #include <cstddef>
21 
22 
23 namespace CxxUtils {
24 
25 
42 {
43 private:
44  // Type of the underlying vector holding the data.
45  typedef std::vector<unsigned int> basetype;
46 
47 public:
48  // Standard STL container typedefs.
49  typedef size_t size_type;
50  typedef unsigned int value_type;
51  typedef basetype::allocator_type allocator_type;
52 
57  class proxy
58  {
59  public:
61  proxy (PackedArray& arr, size_type n) : m_arr (arr), m_n (n) {}
62 
64  operator value_type() const { return m_arr.get (m_n); }
65 
67  proxy& operator= (value_type v) { m_arr.set (m_n, v); return *this; }
68 
69  private:
72 
75  };
76 
77 
85  PackedArray (int bitsize = 8,
86  const allocator_type& allocator = allocator_type());
87 
97  PackedArray (int bitsize,
98  size_type n,
99  value_type val = 0,
100  const allocator_type& allocator = allocator_type());
101 
107  void assign (size_type n, value_type u);
108 
113 
117  size_type size() const;
118 
122  size_type max_size() const;
123 
128  size_type capacity() const;
129 
135  void resize (size_type sz, value_type c = 0);
136 
140  bool empty() const;
141 
147  void reserve (size_type n);
148 
153  value_type get(size_type n) const;
154 
160  void set(size_type n, value_type val);
161 
171 
181 
190  value_type at(size_type n) const;
191 
200  proxy at(size_type n);
201 
209  value_type front() const;
210 
218  value_type back() const;
219 
227  proxy front();
228 
236  proxy back();
237 
242  void push_back (value_type x);
243 
247  void pop_back();
248 
253  void swap (PackedArray& other);
254 
258  void clear();
259 
266  void set_bitsize (int bitsize);
267 
271  int bitsize () const;
272 
273 
274 private:
277 
280 
283 
286 
289  size_t nbase (size_type n) const;
290 
292  size_t tondx (size_type n) const;
293 
295  int tooff (size_type n) const;
296 
298  value_type doget (size_type ndx, int off) const;
299 
301  void doset (size_type ndx, int off, value_type v);
302 
304  void range_check (size_type n) const;
305 };
306 
307 
308 } // namespace CxxUtils
309 
310 
311 #endif // not CXXUTILS_PACKEDARRAY_H
CxxUtils::PackedArray::operator[]
value_type operator[](size_type n) const
Access an element, as an rvalue.
Definition: PackedArray.cxx:317
CxxUtils::PackedArray::m_vec
basetype m_vec
Underlying vector holding the data.
Definition: PackedArray.h:285
CxxUtils::PackedArray::assign
void assign(size_type n, value_type u)
Set the container to multiple copies of the same value.
Definition: PackedArray.cxx:185
fitman.sz
sz
Definition: fitman.py:527
CxxUtils::PackedArray::push_back
void push_back(value_type x)
Add an element to the end of the collection.
Definition: PackedArray.cxx:423
CxxUtils::PackedArray::back
value_type back() const
Access the last element in the collection as an rvalue.
Definition: PackedArray.cxx:387
CxxUtils::PackedArray::nbase
size_t nbase(size_type n) const
Calculate the number of entries in the base vector needed to hold entries with the current bitsize.
Definition: PackedArray.cxx:48
CxxUtils::PackedArray::swap
void swap(PackedArray &other)
Swap this collection with another.
Definition: PackedArray.cxx:449
CxxUtils::PackedArray::reserve
void reserve(size_type n)
Attempt to preallocate enough memory for a specified number of elements.
Definition: PackedArray.cxx:282
CxxUtils::PackedArray::m_size
size_type m_size
The current number of entries in the container.
Definition: PackedArray.h:279
CxxUtils::PackedArray::proxy::proxy
proxy(PackedArray &arr, size_type n)
Constructor, from a PackedArray and index n.
Definition: PackedArray.h:61
CxxUtils::PackedArray::size
size_type size() const
Returns the number of elements in the collection.
Definition: PackedArray.cxx:209
CxxUtils::PackedArray::proxy::m_n
size_type m_n
Index of the element referenced by the proxy.
Definition: PackedArray.h:74
CxxUtils::PackedArray::basetype
std::vector< unsigned int > basetype
Definition: PackedArray.h:45
CxxUtils::PackedArray::tooff
int tooff(size_type n) const
Find the bit offset of entry within its entry in the base vector.
Definition: PackedArray.cxx:70
x
#define x
CxxUtils::PackedArray::bitsize
int bitsize() const
Return the bitsize of the container.
Definition: PackedArray.cxx:486
Trk::u
@ u
Enums for curvilinear frames.
Definition: ParamDefs.h:83
CxxUtils::PackedArray::at
value_type at(size_type n) const
Access an element, as an rvalue.
Definition: PackedArray.cxx:345
CxxUtils::PackedArray::empty
bool empty() const
Returns true if the collection is empty.
Definition: PackedArray.cxx:271
CxxUtils::PackedArray
An array of unsigned values of some bit size, packed tightly.
Definition: PackedArray.h:42
CxxUtils::PackedArray::doget
value_type doget(size_type ndx, int off) const
Return the entry at base index ndx/offset off.
Definition: PackedArray.cxx:83
CxxUtils::PackedArray::get_allocator
allocator_type get_allocator() const
Returns the allocator of the underlying vector.
Definition: PackedArray.cxx:200
CxxUtils::PackedArray::PackedArray
PackedArray(int bitsize=8, const allocator_type &allocator=allocator_type())
Constructor.
Definition: PackedArray.cxx:143
CxxUtils::PackedArray::proxy::m_arr
PackedArray & m_arr
Reference to the container referenced by the proxy.
Definition: PackedArray.h:71
beamspotman.n
n
Definition: beamspotman.py:731
CxxUtils
Definition: aligned_vector.h:29
CxxUtils::PackedArray::range_check
void range_check(size_type n) const
Check that n is in range and throw out_of_range if not.
Definition: PackedArray.cxx:128
CxxUtils::PackedArray::resize
void resize(size_type sz, value_type c=0)
Resizes the collection to the specified number of elements.
Definition: PackedArray.cxx:239
CxxUtils::PackedArray::front
value_type front() const
Access the first element in the collection as an rvalue.
Definition: PackedArray.cxx:374
CxxUtils::PackedArray::allocator_type
basetype::allocator_type allocator_type
Definition: PackedArray.h:51
CxxUtils::PackedArray::m_bitsize
int m_bitsize
The current bitsize of the container.
Definition: PackedArray.h:276
CxxUtils::PackedArray::get
value_type get(size_type n) const
Return the entry at index n.
Definition: PackedArray.cxx:292
CxxUtils::PackedArray::m_mask
value_type m_mask
Mask with m_bitsize bits set.
Definition: PackedArray.h:282
CxxUtils::PackedArray::proxy
proxy class for representing an lvalue to an element of PackedArray.
Definition: PackedArray.h:58
python.PyAthena.v
v
Definition: PyAthena.py:157
CxxUtils::PackedArray::tondx
size_t tondx(size_type n) const
Find the index in the base vector where entry starts.
Definition: PackedArray.cxx:59
InDetDD::other
@ other
Definition: InDetDD_Defs.h:16
CxxUtils::PackedArray::set_bitsize
void set_bitsize(int bitsize)
Change the bitsize of the container.
Definition: PackedArray.cxx:474
CxxUtils::PackedArray::proxy::operator=
proxy & operator=(value_type v)
Set the element referenced by the proxy to v.
Definition: PackedArray.h:67
Pythia8_RapidityOrderMPI.val
val
Definition: Pythia8_RapidityOrderMPI.py:14
CxxUtils::PackedArray::set
void set(size_type n, value_type val)
Set the entry at index n.
Definition: PackedArray.cxx:303
CxxUtils::PackedArray::pop_back
void pop_back()
Remove the last element from the collection.
Definition: PackedArray.cxx:436
CxxUtils::PackedArray::value_type
unsigned int value_type
Definition: PackedArray.h:50
CxxUtils::PackedArray::doset
void doset(size_type ndx, int off, value_type v)
Set the entry at base index ndx/offset off to v.
Definition: PackedArray.cxx:110
value_type
Definition: EDM_MasterSearch.h:11
CxxUtils::PackedArray::clear
void clear()
Erase all the elements in the collection.
Definition: PackedArray.cxx:461
python.compressB64.c
def c
Definition: compressB64.py:93
CxxUtils::PackedArray::capacity
size_type capacity() const
Returns the total number of elements that the collection can hold before needing to allocate more mem...
Definition: PackedArray.cxx:228
CxxUtils::PackedArray::max_size
size_type max_size() const
Returns the size() of the largest possible collection.
Definition: PackedArray.cxx:218
CxxUtils::PackedArray::size_type
size_t size_type
Definition: PackedArray.h:49