Wire Sysio Wire Sysion 1.0.0
Loading...
Searching...
No Matches
array.hpp
Go to the documentation of this file.
1#pragma once
3#include <fc/variant.hpp>
6
7namespace fc {
8
13 template<typename T, size_t N>
14 class array {
15 public:
21 T& at( size_t pos ) { FC_ASSERT( pos < N, "array out-of-bounds" ); return data[pos]; }
22 const T& at( size_t pos )const { FC_ASSERT( pos < N, "array out-of-bounds" ); return data[pos]; }
24
25 T& operator[]( size_t pos ) { FC_ASSERT( pos < N, "array out-of-bounds" ); return data[pos]; }
26 const T& operator[]( size_t pos )const { FC_ASSERT( pos < N, "array out-of-bounds" ); return data[pos]; }
27
28
29 const T* begin()const { return &data[0]; }
30 const T* end()const { return &data[N]; }
31
32 T* begin() { return &data[0]; }
33 T* end() { return &data[N]; }
34
35 size_t size()const { return N; }
36
37 T data[N];
38 };
39
41 template<size_t N>
42 class array<unsigned char,N>
43 {
44 public:
45 typedef unsigned char T;
46 array(){ memset( data, 0, sizeof(data) ); }
52 T& at( size_t pos ) { FC_ASSERT( pos < N, "array out-of-bounds" ); return data[pos]; }
53 const T& at( size_t pos )const { FC_ASSERT( pos < N, "array out-of-bounds" ); return data[pos]; }
55
56 T* begin() { return &data[0]; }
57 const T* begin()const { return &data[0]; }
58 const T* end()const { return &data[N]; }
59
60 size_t size()const { return N; }
61
62 T data[N];
63 };
64
66 template<size_t N>
67 class array<char,N>
68 {
69 public:
70 typedef char T;
71 array(){ memset( data, 0, sizeof(data) ); }
77 T& at( size_t pos ) { FC_ASSERT( pos < N, "array out-of-bounds" ); return data[pos]; }
78 const T& at( size_t pos )const { FC_ASSERT( pos < N, "array out-of-bounds" ); return data[pos]; }
80
81 T* begin() { return &data[0]; }
82 const T* begin()const { return &data[0]; }
83 const T* end()const { return &data[N]; }
84
85 size_t size()const { return N; }
86
87 T data[N];
88 };
89
90 template<typename T, size_t N>
91 bool operator == ( const array<T,N>& a, const array<T,N>& b )
92 { return 0 == memcmp( a.data, b.data, N*sizeof(T) ); }
93 template<typename T, size_t N>
94 bool operator < ( const array<T,N>& a, const array<T,N>& b )
95 { return memcmp( a.data, b.data, N*sizeof(T) ) < 0 ; }
96
97 template<typename T, size_t N>
98 bool operator > ( const array<T,N>& a, const array<T,N>& b )
99 { return memcmp( a.data, b.data, N*sizeof(T) ) > 0 ; }
100
101 template<typename T, size_t N>
102 bool operator != ( const array<T,N>& a, const array<T,N>& b )
103 { return 0 != memcmp( a.data, b.data, N*sizeof(T) ); }
104
105 template<typename T, size_t N>
106 void to_variant( const array<T,N>& bi, variant& v )
107 {
108 v = std::vector<char>( (const char*)&bi, ((const char*)&bi) + sizeof(bi) );
109 }
110 template<typename T, size_t N>
111 void from_variant( const variant& v, array<T,N>& bi )
112 {
113 std::vector<char> ve = v.as< std::vector<char> >();
114 if( ve.size() )
115 {
116 memcpy(&bi, ve.data(), fc::min<size_t>(ve.size(),sizeof(bi)) );
117 }
118 else
119 memset( &bi, char(0), sizeof(bi) );
120 }
121
122
123 template<typename T,size_t N> struct get_typename< fc::array<T,N> >
124 {
125 static const char* name()
126 {
127 static std::string _name = std::string("fc::array<")+std::string(fc::get_typename<T>::name())+","+ fc::to_string(N) + ">";
128 return _name.c_str();
129 }
130 };
131}
132
133#include <unordered_map>
134#include <fc/crypto/city.hpp>
135namespace std
136{
137 template<typename T, size_t N>
138 struct hash<fc::array<T,N> >
139 {
140 size_t operator()( const fc::array<T,N>& e )const
141 {
142 return fc::city_hash_size_t( (char*)&e, sizeof(e) );
143 }
144 };
145}
size_t size() const
Definition array.hpp:85
const T * begin() const
Definition array.hpp:82
T & at(size_t pos)
Definition array.hpp:77
const T * end() const
Definition array.hpp:83
const T & at(size_t pos) const
Definition array.hpp:78
const T & at(size_t pos) const
Definition array.hpp:53
const T * end() const
Definition array.hpp:58
const T * begin() const
Definition array.hpp:57
size_t size() const
Definition array.hpp:35
T * begin()
Definition array.hpp:32
const T * begin() const
Definition array.hpp:29
const T & at(size_t pos) const
Definition array.hpp:22
const T & operator[](size_t pos) const
Definition array.hpp:26
T & operator[](size_t pos)
Definition array.hpp:25
T * end()
Definition array.hpp:33
const T * end() const
Definition array.hpp:30
T & at(size_t pos)
Definition array.hpp:21
stores null, int64, uint64, double, bool, string, std::vector<variant>, and variant_object's.
Definition variant.hpp:191
T as() const
Definition variant.hpp:327
Defines exception's used by fc.
#define FC_ASSERT(TEST,...)
Checks a condition and throws an assert_exception if the test is FALSE.
namespace sysio::chain
Definition authority.cpp:3
bool operator<(const array< T, N > &a, const array< T, N > &b)
Definition array.hpp:94
bool operator>(const array< T, N > &a, const array< T, N > &b)
Definition array.hpp:98
fc::string to_string(double)
Definition string.cpp:131
bool operator!=(const array< T, N > &a, const array< T, N > &b)
Definition array.hpp:102
bool operator==(const array< T, N > &a, const array< T, N > &b)
Definition array.hpp:91
size_t city_hash_size_t(const char *buf, size_t len)
Definition city.hpp:62
const T & min(const T &a, const T &b)
Definition utility.hpp:140
void from_variant(const fc::variant &v, sysio::chain::chain_id_type &cid)
void to_variant(const sysio::chain::shared_public_key &var, fc::variant &vo)
Definition authority.cpp:4
value::array array
Definition name.hpp:106
const GenericPointer< typename T::ValueType > T2 T::AllocatorType & a
Definition pointer.h:1181
#define T(meth, val, expected)
const int N
Definition quantize.cpp:54
size_t operator()(const fc::array< T, N > &e) const
Definition array.hpp:140
memset(pInfo->slotDescription, ' ', 64)
memcpy((char *) pInfo->slotDescription, s, l)