Wire Sysio Wire Sysion 1.0.0
Loading...
Searching...
No Matches
sysio::chain::symbol Class Reference

#include <symbol.hpp>

Inheritance diagram for sysio::chain::symbol:
Collaboration diagram for sysio::chain::symbol:

Public Member Functions

 symbol (uint8_t p, const char *s)
 
 symbol (uint64_t v=CORE_SYMBOL)
 
uint64_t value () const
 
bool valid () const
 
uint8_t decimals () const
 
uint64_t precision () const
 
string name () const
 
symbol_code to_symbol_code () const
 
 operator string () const
 
string to_string () const
 
void reflector_init () const
 

Static Public Member Functions

static symbol from_string (const string &from)
 
static bool valid_name (const string &name)
 

Static Public Attributes

static constexpr uint8_t max_precision = 18
 

Friends

struct fc::reflector< symbol >
 
template<typename DataStream >
DataStream & operator<< (DataStream &ds, const symbol &s)
 

Detailed Description

Definition at line 57 of file symbol.hpp.

Constructor & Destructor Documentation

◆ symbol() [1/2]

sysio::chain::symbol::symbol ( uint8_t p,
const char * s )
inlineexplicit

Definition at line 62 of file symbol.hpp.

62 : m_value(string_to_symbol(p, s)) {
63 SYS_ASSERT(valid(), symbol_type_exception, "invalid symbol: ${s}", ("s",s));
64 }
const mie::Vuint & p
Definition bn.cpp:27
#define SYS_ASSERT(expr, exc_type, FORMAT,...)
Definition exceptions.hpp:7
bool valid() const
Definition symbol.hpp:83
char * s
Here is the call graph for this function:
Here is the caller graph for this function:

◆ symbol() [2/2]

sysio::chain::symbol::symbol ( uint64_t v = CORE_SYMBOL)
inlineexplicit

Definition at line 65 of file symbol.hpp.

65 : m_value(v) {
66 SYS_ASSERT(valid(), symbol_type_exception, "invalid symbol: ${name}", ("name",name()));
67 }
string name() const
Definition symbol.hpp:104
Here is the call graph for this function:

Member Function Documentation

◆ decimals()

uint8_t sysio::chain::symbol::decimals ( ) const
inline

Definition at line 93 of file symbol.hpp.

93{ return m_value & 0xFF; }
Here is the caller graph for this function:

◆ from_string()

static symbol sysio::chain::symbol::from_string ( const string & from)
inlinestatic

Definition at line 68 of file symbol.hpp.

69 {
70 try {
71 string s = fc::trim(from);
72 SYS_ASSERT(!s.empty(), symbol_type_exception, "creating symbol from empty string");
73 auto comma_pos = s.find(',');
74 SYS_ASSERT(comma_pos != string::npos, symbol_type_exception, "missing comma in symbol");
75 auto prec_part = s.substr(0, comma_pos);
76 uint8_t p = fc::to_int64(prec_part);
77 string name_part = s.substr(comma_pos + 1);
78 SYS_ASSERT( p <= max_precision, symbol_type_exception, "precision ${p} should be <= 18", ("p", p));
79 return symbol(string_to_symbol(p, name_part.c_str()));
81 }
static constexpr uint8_t max_precision
Definition symbol.hpp:60
symbol(uint8_t p, const char *s)
Definition symbol.hpp:62
#define FC_CAPTURE_LOG_AND_RETHROW(...)
fc::string trim(const fc::string &)
Definition string.cpp:152
int64_t to_int64(const fc::string &)
Definition string.cpp:92
unsigned char uint8_t
Definition stdint.h:124
Here is the call graph for this function:
Here is the caller graph for this function:

◆ name()

string sysio::chain::symbol::name ( ) const
inline

Definition at line 104 of file symbol.hpp.

105 {
106 uint64_t v = m_value;
107 v >>= 8;
108 string result;
109 while (v > 0) {
110 char c = v & 0xFF;
111 result += c;
112 v >>= 8;
113 }
114 return result;
115 }
unsigned __int64 uint64_t
Definition stdint.h:136
Here is the caller graph for this function:

◆ operator string()

sysio::chain::symbol::operator string ( ) const
inlineexplicit

Definition at line 119 of file symbol.hpp.

120 {
121 uint64_t v = m_value;
122 uint8_t p = v & 0xFF;
123 string ret = sysio::chain::to_string(p);
124 ret += ',';
125 ret += name();
126 return ret;
127 }
fc::string to_string(double)
Definition string.cpp:131
CK_RV ret
Here is the call graph for this function:

◆ precision()

uint64_t sysio::chain::symbol::precision ( ) const
inline

Definition at line 94 of file symbol.hpp.

95 {
96 SYS_ASSERT( decimals() <= max_precision, symbol_type_exception, "precision ${p} should be <= 18", ("p", decimals()) );
97 uint64_t p10 = 1;
99 while( p > 0 ) {
100 p10 *= 10; --p;
101 }
102 return p10;
103 }
uint8_t decimals() const
Definition symbol.hpp:93
Here is the call graph for this function:
Here is the caller graph for this function:

◆ reflector_init()

void sysio::chain::symbol::reflector_init ( ) const
inline

Definition at line 136 of file symbol.hpp.

136 {
137 SYS_ASSERT( decimals() <= max_precision, symbol_type_exception, "precision ${p} should be <= 18", ("p", decimals()) );
138 SYS_ASSERT( valid_name(name()), symbol_type_exception, "invalid symbol: ${name}", ("name",name()));
139 }
static bool valid_name(const string &name)
Definition symbol.hpp:88
Here is the call graph for this function:

◆ to_string()

string sysio::chain::symbol::to_string ( ) const
inline

Definition at line 129 of file symbol.hpp.

129{ return string(*this); }
std::string string
Definition string.hpp:10
Here is the caller graph for this function:

◆ to_symbol_code()

symbol_code sysio::chain::symbol::to_symbol_code ( ) const
inline

Definition at line 117 of file symbol.hpp.

117{ return {m_value >> 8}; }
Here is the caller graph for this function:

◆ valid()

bool sysio::chain::symbol::valid ( ) const
inline

Definition at line 83 of file symbol.hpp.

84 {
85 const auto& s = name();
86 return decimals() <= max_precision && valid_name(s);
87 }
Here is the call graph for this function:
Here is the caller graph for this function:

◆ valid_name()

static bool sysio::chain::symbol::valid_name ( const string & name)
inlinestatic

Definition at line 88 of file symbol.hpp.

89 {
90 return all_of(name.begin(), name.end(), [](char c)->bool { return (c >= 'A' && c <= 'Z'); });
91 }
Here is the caller graph for this function:

◆ value()

uint64_t sysio::chain::symbol::value ( ) const
inline

Definition at line 82 of file symbol.hpp.

82{ return m_value; }
Here is the caller graph for this function:

Friends And Related Symbol Documentation

◆ fc::reflector< symbol >

friend struct fc::reflector< symbol >
friend

Definition at line 142 of file symbol.hpp.

◆ operator<<

template<typename DataStream >
DataStream & operator<< ( DataStream & ds,
const symbol & s )
friend

Definition at line 131 of file symbol.hpp.

132 {
133 return ds << s.to_string();
134 }
static const Segment ds(Segment::ds)

Member Data Documentation

◆ max_precision

uint8_t sysio::chain::symbol::max_precision = 18
staticconstexpr

Definition at line 60 of file symbol.hpp.


The documentation for this class was generated from the following file: