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