OnixS ICE iMpact Multicast Price Feed Handler C++ library  8.7.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.
72  {
73  }
74 
75  /// Indicates whether array has no items.
76  bool empty() const
77  {
78  return (0 == size_);
79  }
80 
81  /// Number of items being referenced.
82  Size size() const
83  {
84  return size_;
85  }
86 
87  /// Gets raw pointer to items.
88  Item* items() const
89  {
90  return items_;
91  }
92 
93  /// Iterator referencing to the first item.
94  Iterator begin() const
95  {
96  return items_;
97  }
98 
99  /// Iterator referencing to the item behind the last item.
100  Iterator end() const
101  {
102  return (items_ + size_);
103  }
104 
105  /// Accesses to item by index.
106  Item& operator[](Index index) const
107  {
108  return items_[index];
109  }
110 
111  /// Accesses to item by index checking access bounds.
112  Item& at(const Index index) const
113  {
114  if (index < size_)
115  return items_[index];
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 MarketData, iMpact, ICE, OnixS
~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:82
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:88
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:106
ArrayRef()
Initializes instance referencing to nothing.
Definition: Containers.h:39
bool empty() const
Indicates whether array has no items.
Definition: Containers.h:76
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:112
Iterator begin() const
Iterator referencing to the first item.
Definition: Containers.h:94
Iterator end() const
Iterator referencing to the item behind the last item.
Definition: Containers.h:100