BitShares-Core  6.1.0
BitShares blockchain implementation and command-line interface software
vote.hpp
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2015 Cryptonomex, Inc., and contributors.
3  *
4  * The MIT License
5  *
6  * Permission is hereby granted, free of charge, to any person obtaining a copy
7  * of this software and associated documentation files (the "Software"), to deal
8  * in the Software without restriction, including without limitation the rights
9  * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10  * copies of the Software, and to permit persons to whom the Software is
11  * furnished to do so, subject to the following conditions:
12  *
13  * The above copyright notice and this permission notice shall be included in
14  * all copies or substantial portions of the Software.
15  *
16  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19  * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21  * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
22  * THE SOFTWARE.
23  */
24 
25 #pragma once
26 
28 
29 namespace graphene { namespace protocol {
30 
52 {
55  uint32_t content = 0;
56 
57  friend size_t hash_value( vote_id_type v ) { return std::hash<uint32_t>()(v.content); }
58  enum vote_type
59  {
64  };
65 
66  vote_id_type() = default;
68  explicit vote_id_type(vote_type type, uint32_t instance = 0)
69  : content(instance<<8 | type)
70  {}
72  explicit vote_id_type(const std::string& serial)
73  { try {
74  auto colon = serial.find(':');
75  FC_ASSERT( colon != std::string::npos );
76  *this = vote_id_type( vote_type( std::stoul(serial.substr(0, colon)) ),
77  uint32_t( std::stoul(serial.substr(colon+1)) ) );
78  } FC_CAPTURE_AND_RETHROW( (serial) ) }
79 
82  {
83  content &= 0xffffff00;
84  content |= type & 0xff;
85  }
87  vote_type type()const
88  {
89  return vote_type(content & 0xff);
90  }
91 
93  void set_instance(uint32_t instance)
94  {
95  assert(instance < 0x01000000);
96  content &= 0xff;
97  content |= instance << 8;
98  }
100  uint32_t instance()const
101  {
102  return content >> 8;
103  }
104 
106  {
107  content = other.content;
108  return *this;
109  }
112  {
113  set_instance(instance);
114  return *this;
115  }
117  operator uint32_t()const
118  {
119  return instance();
120  }
121 
123  explicit operator std::string()const
124  {
125  return std::to_string(type()) + ":" + std::to_string(instance());
126  }
127 };
128 
129 } } // graphene::protocol
130 
131 namespace fc
132 {
133 
134 class variant;
135 
136 void to_variant( const graphene::protocol::vote_id_type& var, fc::variant& vo, uint32_t max_depth = 1 );
137 void from_variant( const fc::variant& var, graphene::protocol::vote_id_type& vo, uint32_t max_depth = 1 );
138 
139 } // fc
140 
141 FC_REFLECT_TYPENAME( fc::flat_set<graphene::protocol::vote_id_type> )
142 
145 
#define FC_REFLECT(TYPE, MEMBERS)
Specializes fc::reflector for TYPE.
Definition: reflect.hpp:388
Definition: api.cpp:48
void to_variant(const graphene::protocol::vote_id_type &var, fc::variant &vo, uint32_t max_depth=1)
Definition: vote.cpp:32
vote_id_type(vote_type type, uint32_t instance=0)
Construct this vote_id_type with provided type and instance.
Definition: vote.hpp:68
FC_REFLECT_TYPENAME(fc::log_message)
FC_REFLECT_ENUM(graphene::net::core_message_type_enum,(trx_message_type)(block_message_type)(core_message_type_first)(item_ids_inventory_message_type)(blockchain_item_ids_inventory_message_type)(fetch_blockchain_item_ids_message_type)(fetch_items_message_type)(item_not_available_message_type)(hello_message_type)(connection_accepted_message_type)(connection_rejected_message_type)(address_request_message_type)(address_message_type)(closing_connection_message_type)(current_time_request_message_type)(current_time_reply_message_type)(check_firewall_message_type)(check_firewall_reply_message_type)(get_current_connections_request_message_type)(get_current_connections_reply_message_type)(core_message_type_last))(different_chain)(already_connected)(connected_to_self)(not_accepting_connections)(blocked)(invalid_hello_message)(client_too_old))(inbound)(outbound))(firewalled)(not_firewalled))(unable_to_connect)(connection_successful)) namespace std
#define GRAPHENE_DECLARE_EXTERNAL_SERIALIZATION(type)
Definition: types.hpp:85
vote_id_type & operator=(vote_id_type other)
Definition: vote.hpp:105
void set_type(vote_type type)
Set the type of this vote_id_type.
Definition: vote.hpp:81
#define FC_CAPTURE_AND_RETHROW(...)
Definition: exception.hpp:479
#define FC_ASSERT(TEST,...)
Checks a condition and throws an assert_exception if the test is FALSE.
Definition: exception.hpp:345
stores null, int64, uint64, double, bool, string, std::vector<variant>, and variant_object&#39;s.
Definition: variant.hpp:198
vote_id_type(const std::string &serial)
Construct this vote_id_type from a serial string in the form "type:instance".
Definition: vote.hpp:72
friend size_t hash_value(vote_id_type v)
Definition: vote.hpp:57
An ID for some votable object.
Definition: vote.hpp:51
void set_instance(uint32_t instance)
Set the instance of this vote_id_type.
Definition: vote.hpp:93
std::string to_string(double)
Definition: string.cpp:73
Definition: api.hpp:15
void from_variant(const fc::variant &var, graphene::protocol::vote_id_type &vo, uint32_t max_depth=1)
Definition: vote.cpp:37
vote_type type() const
Get the type of this vote_id_type.
Definition: vote.hpp:87
uint32_t instance() const
Get the instance of this vote_id_type.
Definition: vote.hpp:100