OnixS ICE iMpact Multicast Price Feed Handler C++ library  8.18.0
API documentation
Containers.h
Go to the documentation of this file.
1 /*
2  * Copyright (c) Onix Solutions Limited. All rights reserved.
3  *
4  * This software owned by Onix Solutions Limited and is protected by copyright law
5  * and international copyright treaties.
6  *
7  * Access to and use of the software is governed by the terms of the applicable ONIXS Software
8  * Services Agreement (the Agreement) and Customer end user license agreements granting
9  * a non-assignable, non-transferable and non-exclusive license to use the software
10  * for it's own data processing purposes under the terms defined in the Agreement.
11  *
12  * Except as otherwise granted within the terms of the Agreement, copying or reproduction of any part
13  * of this source code or associated reference material to any other location for further reproduction
14  * or redistribution, and any amendments to this copyright notice, are expressly prohibited.
15  *
16  * Any reproduction or redistribution for sale or hiring of the Software not in accordance with
17  * the terms of the Agreement is a violation of copyright law.
18  */
19 
20 #pragma once
21 
22 #include <stdexcept>
23 
24 namespace OnixS { namespace ICE { namespace iMpact { namespace MarketData {
25 
26 /// Represents reference to segment
27 /// of built-in array of items.
28 template <typename ItemType, typename SizeType>
29 class ArrayRef
30 {
31 public:
32  typedef ItemType Item;
33  typedef ItemType* Iterator;
34 
35  typedef SizeType Index;
36  typedef SizeType Size;
37 
38  /// Initializes instance referencing to nothing.
40  : items_(0)
41  , size_(0)
42  {
43  }
44 
45  /// Initializes instance referencing to given data.
46  ArrayRef(Item* const items, const Size itemsCount)
47  : items_(items)
48  , size_(itemsCount)
49  {
50  }
51 
52  /// Initializes instance as copy of other one.
53  template <typename OtherItem, typename OtherSize>
55  : items_(other.items())
56  , size_(other.size())
57  {
58  }
59 
60  /// Re-initializes instance as copy of the other one.
61  template <typename OtherItem, typename OtherSize>
63  {
64  items_ = other.items();
65  size_ = other.size();
66 
67  return *this;
68  }
69 
70  /// Destructs the instance.
71  ~ArrayRef() {}
72 
73  /// Indicates whether array has no items.
74  bool empty() const
75  {
76  return (0 == size_);
77  }
78 
79  /// Number of items being referenced.
80  Size size() const
81  {
82  return size_;
83  }
84 
85  /// Gets raw pointer to items.
86  Item* items() const
87  {
88  return items_;
89  }
90 
91  /// Iterator referencing to the first item.
92  Iterator begin() const
93  {
94  return items_;
95  }
96 
97  /// Iterator referencing to the item behind the last item.
98  Iterator end() const
99  {
100  return (items_ + size_);
101  }
102 
103  /// Accesses to item by index.
104  Item& operator[](Index index) const
105  {
106  return items_[index];
107  }
108 
109  /// Accesses to item by index checking access bounds.
110  Item& at(const Index index) const
111  {
112  if (index < size_)
113  {
114  return items_[index];
115  }
116 
117  throw std::out_of_range("Index outside of range.");
118  }
119 
120  /// Resets array with new items and size.
121  void reset(Item* const items = 0, const Size size = 0)
122  {
123  items_ = items;
124  size_ = size;
125  }
126 
127 protected:
128  Item* items_;
129  Size size_;
130 };
131 
132 }}}} // namespace OnixS::ICE::iMpact::MarketData
~ArrayRef()
Destructs the instance.
Definition: Containers.h:71
ArrayRef(const ArrayRef< OtherItem, OtherSize > &other)
Initializes instance as copy of other one.
Definition: Containers.h:54
Size size() const
Number of items being referenced.
Definition: Containers.h:80
ArrayRef & operator=(const ArrayRef< OtherItem, OtherSize > &other)
Re-initializes instance as copy of the other one.
Definition: Containers.h:62
Item * items() const
Gets raw pointer to items.
Definition: Containers.h:86
ArrayRef(Item *const items, const Size itemsCount)
Initializes instance referencing to given data.
Definition: Containers.h:46
Item & operator[](Index index) const
Accesses to item by index.
Definition: Containers.h:104
ArrayRef()
Initializes instance referencing to nothing.
Definition: Containers.h:39
bool empty() const
Indicates whether array has no items.
Definition: Containers.h:74
void reset(Item *const items=0, const Size size=0)
Resets array with new items and size.
Definition: Containers.h:121
Item & at(const Index index) const
Accesses to item by index checking access bounds.
Definition: Containers.h:110
Iterator begin() const
Iterator referencing to the first item.
Definition: Containers.h:92
Iterator end() const
Iterator referencing to the item behind the last item.
Definition: Containers.h:98