提交 a4258b74 编写于 作者: P Pravin Bezwada 提交者: Andrianto Lie

Documented class API with examples at class level.`

上级 eff9ce47
此差异已折叠。
......@@ -37,14 +37,23 @@ extern "C" {
* @param msg - a pointer where up to @ref len bytes of the current message will be copied
* @param len - len of the current message to be copied
* @return the number of bytes copied to msg
* Example
* @code
* char buffer[128];
* uint32_t total = readMessage(buffer, 64);
* @endcode
*/
uint32_t readMessage( void* msg, uint32_t len );
/**
* Get the length of the current message's data field
* This method is useful for dynamicly sized messages
* @brief Get the lenght of current message's data field
* This method is useful for dynamically sized messages
* @brief Get the length of current message's data field
* @return the length of the current message's data field
* Example
* @code
* uint32_t msgsize = messageSize();
* @endcode
*/
uint32_t messageSize();
......@@ -52,6 +61,10 @@ extern "C" {
* Verifies that @ref name exists in the set of notified accounts on a message. Throws if not found
* @brief Verify specified account exists in the set of notified accounts
* @param name - name of the account to be verified
* Example
* @code
* requireNotice(N(MyAccount)); // throws exception if MyAccount is not found in recipients list.
* @endcode
*/
void requireNotice( AccountName name );
......@@ -59,6 +72,10 @@ extern "C" {
* Verifies that @ref name exists in the set of provided auths on a message. Throws if not found
* @brief Verify specified account exists in the set of provided auths
* @param name - name of the account to be verified
* Example
* @code
* requireAuth(N(MyAccount)); // throws exception if MyAccount is not found in authentication list.
* @endcode
*/
void requireAuth( AccountName name );
......@@ -75,6 +92,7 @@ extern "C" {
* @brief Aborts processing of this message and unwinds all pending changes
* @param test - 0 to abort, 1 to ignore
* @param cstr - a null terminated message to explain the reason for failure
*/
void assert( uint32_t test, const char* cstr );
......
......@@ -18,6 +18,15 @@ namespace eos {
* This method attempts to reinterpret the message body as type T. This will only work
* if the message has no dynamic fields and the struct packing on type T is properly defined.
* @brief Interpret the message body as type T
* Example
* @code
*
* struct MyMessage {
* uint32_t time;
* };
*
* MyMessage msg = currentMessage<MyMessage>();
* @endcode
*/
template<typename T>
T currentMessage() {
......@@ -40,6 +49,10 @@ namespace eos {
* @note message.code is also considered as part of the set of notified accounts
*
* @brief Verify specified accounts exist in the set of notified accounts
* Example
* @code
* requireNotice(N(Account1), N(Account2), N(Account3)); // throws exception if any of them not in set.
* @endcode
*/
template<typename... Accounts>
void requireNotice( AccountName name, Accounts... accounts ){
......
......@@ -26,6 +26,30 @@ namespace eos {
* @tparam NumberType - numeric type of the token
* @tparam CurrencyType - type of the currency (e.g. eos) represented as an unsigned 64 bit integer
* @ingroup tokens
* @code
* typedef eos::token<uint32_t, N(MyToken)> MyToken;
* MyToken a(128);
* a.print(); // Output: 128 MyToken
* MyToken b(64);
* a += b;
* a.print(); // Output: 192 MyToken
* b.print(); // Output: 64 MyToken
* a -= b;
* a.print(); // Output: 128 MyToken
* b.print(); // Output: 64 MyToken
* b -= a; // Throws integer underflow exception
* MyToken c = a + b;
* c.print(); // Output: 192 MyToken
* MyToken d = a - b;
* d.print(); // Output: 64 MyToken
* MyToken maxToken(std::numeric_limits<uint32_t>::max());
* maxToken += b; // Throws integer overflow exception
* std::cout << (maxToken > b); // Output: true
* std::cout << (b > maxToken); // Output: false
* std::cout << (bool)maxToken; // Output: true
* std::cout << (a == b); // Output: false
* std::cout << (a != b); // Output: true
* @endcode
*/
template<typename NumberType, uint64_t CurrencyType = N(eos) >
struct token {
......@@ -179,12 +203,35 @@ namespace eos {
/**
* Defines a fixed precision price between two tokens.
* A price is written as X Base/Quote.
* A price is written as X Base/Quote. Where X is a power of 10 which makes it simpler to just shift the decimal.
* It supports the following operator: /, \, <=, <, ==, !=, >=, > and also print functionality
* @brief Defines a fixed precision price between two tokens.
* @tparam BaseToken - represents the type of the base token
* @tparam QuoteToken - represents the type of the quote token
* @ingroup tokens
* @code
* typedef eos::token<uint64_t, N(MyBaseToken)> MyBaseToken;
* typedef eos::token<uint64_t, N(MyQuoteToken)> MyQuoteToken;
* typedef price<MyBaseToken, MyQuoteToken> MyBaseToQuotePrice;
* MyBaseToken zeroBaseToken;
* MyQuoteToken zeroQuoteToken;
* MyBaseToQuotePrice zeroBaseToQuote(zeroBaseToken, zeroQuoteToken); // throws invalid price exception
* MyBaseToken baseToken(128);
* MyQuoteToken quoteToken(128);
* MyBaseToQuotePrice aPrice(baseToken, quoteToken);
* aPrice.print(); // Output: 1e+15. MyBaseToken / MyQuoteToken
* MyQuoteToken anotherQuote = baseToken / price;
* std::cout << (anotherQuote == quoteToken); // Output: true
* MyBaseToken anotherBase = quoteToken * price;
* std::cout << (anotherBase == baseToken); // Output: true
* MyBaseToQuotePrice anotherPrice(baseToken, quoteToken);
* std::cout << (aPrice == anotherPrice); // Output: true
* std::cout << (aPrice != anotherPrice); // Output: false
* MyBaseToken base256(256);
* MyBaseToQuotePrice price2(base256, quoteToken);
* std::cout << (price2 > aPrice); // Output: true
* std::cout << (aPrice < price2); // Output: true
* @endcode
*/
template<typename BaseToken, typename QuoteToken>
struct price
......@@ -327,6 +374,12 @@ namespace eos {
* The binary structure of the `transfer` message type for the `eos` contract.
* @brief The binary structure of the `transfer` message type for the `eos` contract.
* @ingroup tokens
* @code
* Transfer MeToYou;
* MeToYou.from = N(Me);
* MeToYou.to = N(You);
* MeToYou.quantity = Tokens(100);
* @endcode
*/
struct Transfer {
/**
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册