BitShares-Core  4.0.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 {
54  uint32_t content;
55 
56  friend size_t hash_value( vote_id_type v ) { return std::hash<uint32_t>()(v.content); }
57  enum vote_type
58  {
63  };
64 
66  vote_id_type():content(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))), std::stoul(serial.substr(colon+1)));
77  } FC_CAPTURE_AND_RETHROW( (serial) ) }
78 
81  {
82  content &= 0xffffff00;
83  content |= type & 0xff;
84  }
86  vote_type type()const
87  {
88  return vote_type(content & 0xff);
89  }
90 
92  void set_instance(uint32_t instance)
93  {
94  assert(instance < 0x01000000);
95  content &= 0xff;
96  content |= instance << 8;
97  }
99  uint32_t instance()const
100  {
101  return content >> 8;
102  }
103 
105  {
106  content = other.content;
107  return *this;
108  }
111  {
112  set_instance(instance);
113  return *this;
114  }
116  operator uint32_t()const
117  {
118  return instance();
119  }
120 
122  explicit operator std::string()const
123  {
124  return std::to_string(type()) + ":" + std::to_string(instance());
125  }
126 };
127 
128 } } // graphene::protocol
129 
130 namespace fc
131 {
132 
133 class variant;
134 
135 void to_variant( const graphene::protocol::vote_id_type& var, fc::variant& vo, uint32_t max_depth = 1 );
136 void from_variant( const fc::variant& var, graphene::protocol::vote_id_type& vo, uint32_t max_depth = 1 );
137 
138 } // fc
139 
140 FC_REFLECT_TYPENAME( fc::flat_set<graphene::protocol::vote_id_type> )
141 
144 
uint32_t instance() const
Get the instance of this vote_id_type.
Definition: vote.hpp:99
#define FC_REFLECT(TYPE, MEMBERS)
Specializes fc::reflector for TYPE.
Definition: reflect.hpp:386
vote_type type() const
Get the type of this vote_id_type.
Definition: vote.hpp:86
Definition: api.cpp:56
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()
Default constructor. Sets type and instance to 0.
Definition: vote.hpp:66
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:73
vote_id_type & operator=(vote_id_type other)
Definition: vote.hpp:104
void set_type(vote_type type)
Set the type of this vote_id_type.
Definition: vote.hpp:80
#define FC_CAPTURE_AND_RETHROW(...)
Definition: exception.hpp:478
#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:56
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:92
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
uint32_t content
Lower 8 bits are type; upper 24 bits are instance.
Definition: vote.hpp:54