Wire Sysio Wire Sysion 1.0.0
Loading...
Searching...
No Matches
enum_type.hpp
Go to the documentation of this file.
1#pragma once
3#include <fc/io/raw_fwd.hpp>
4#include <fc/variant.hpp>
5
6namespace fc
7{
8 template<typename IntType, typename EnumType>
9 class enum_type
10 {
11 public:
12 explicit enum_type( EnumType t )
13 :value(t){}
14
15 explicit enum_type( IntType t )
16 :value( (EnumType)t ){}
17
19
20 explicit operator IntType()const { return static_cast<IntType>(value); }
21 operator EnumType()const { return value; }
22 operator std::string()const { return fc::reflector<EnumType>::to_string(value); }
23
24 enum_type& operator=( IntType i ) { value = (EnumType)i; return *this;}
25 enum_type& operator=( EnumType i ) { value = i; return *this;}
26 bool operator<( EnumType i ) const { return value < i; }
27 bool operator>( EnumType i ) const { return value > i; }
28
29 bool operator<(const enum_type& e) const { return value < e.value;}
30 bool operator>(const enum_type& e) const { return value > e.value;}
31
32 bool operator<=(const enum_type& e) const { return value <= e.value;}
33 bool operator>=(const enum_type& e) const { return value >= e.value;}
34
35 friend bool operator==( const enum_type& e, IntType i ){ return e.value == (EnumType)i;}
36 friend bool operator==( const enum_type& e, EnumType i ){ return e.value == i; }
37
38 friend bool operator==( const enum_type& e, const enum_type& i ){ return e.value == i.value; }
39 friend bool operator==( IntType i, const enum_type& e){ return e.value == (EnumType)i; }
40 friend bool operator==( EnumType i, const enum_type& e ){ return e.value == i; }
41
42 friend bool operator!=( const enum_type& e, IntType i ){ return e.value != (EnumType)i;}
43 friend bool operator!=( const enum_type& e, EnumType i ){ return e.value != i; }
44 friend bool operator!=( const enum_type& e, const enum_type& i ){ return e.value != i.value; }
45
46 EnumType value;
47 };
48
49
50 template<typename IntType, typename EnumType>
52 {
53 vo = (EnumType)var.value;
54 }
55 template<typename IntType, typename EnumType>
57 {
58 vo.value = var.as<EnumType>();
59 }
60
61
63 namespace raw
64 {
65 template<typename Stream, typename IntType, typename EnumType>
66 inline void pack( Stream& s, const fc::enum_type<IntType,EnumType>& tp )
67 {
68 fc::raw::pack( s, static_cast<IntType>(tp) );
69 }
70
71 template<typename Stream, typename IntType, typename EnumType>
73 {
74 IntType t;
75 fc::raw::unpack( s, t );
76 tp = t;
77 }
78 }
79
80}
81
82
friend bool operator==(const enum_type &e, const enum_type &i)
Definition enum_type.hpp:38
friend bool operator==(EnumType i, const enum_type &e)
Definition enum_type.hpp:40
friend bool operator==(const enum_type &e, EnumType i)
Definition enum_type.hpp:36
friend bool operator==(IntType i, const enum_type &e)
Definition enum_type.hpp:39
enum_type(EnumType t)
Definition enum_type.hpp:12
friend bool operator!=(const enum_type &e, EnumType i)
Definition enum_type.hpp:43
bool operator>(EnumType i) const
Definition enum_type.hpp:27
enum_type & operator=(IntType i)
Definition enum_type.hpp:24
bool operator<=(const enum_type &e) const
Definition enum_type.hpp:32
bool operator<(const enum_type &e) const
Definition enum_type.hpp:29
EnumType value
Definition enum_type.hpp:46
bool operator>=(const enum_type &e) const
Definition enum_type.hpp:33
bool operator<(EnumType i) const
Definition enum_type.hpp:26
friend bool operator!=(const enum_type &e, const enum_type &i)
Definition enum_type.hpp:44
friend bool operator!=(const enum_type &e, IntType i)
Definition enum_type.hpp:42
bool operator>(const enum_type &e) const
Definition enum_type.hpp:30
enum_type(IntType t)
Definition enum_type.hpp:15
enum_type & operator=(EnumType i)
Definition enum_type.hpp:25
friend bool operator==(const enum_type &e, IntType i)
Definition enum_type.hpp:35
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
Concept for reading and writing characters.
void unpack(Stream &s, std::deque< T > &value)
Definition raw.hpp:540
void pack(Stream &s, const std::deque< T > &value)
Definition raw.hpp:531
namespace sysio::chain
Definition authority.cpp:3
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
defines visit functions for T Unless this is specialized, visit() will not be defined for T.
Definition reflect.hpp:33
char * s