Skip to content

Commit

Permalink
Merge pull request EOSIO#133 from EOSIO/feature/ignored_and_contract_…
Browse files Browse the repository at this point in the history
…attr

Feature/ignored and contract attr
  • Loading branch information
larryk85 authored Oct 9, 2018
2 parents c7b7777 + 991c701 commit 8d3b644
Show file tree
Hide file tree
Showing 6 changed files with 117 additions and 3 deletions.
1 change: 1 addition & 0 deletions InstallClang.txt
Original file line number Diff line number Diff line change
Expand Up @@ -34,3 +34,4 @@ eosio_clang_install(eosio-cpp)
eosio_clang_install(eosio-ld)
eosio_clang_install(eosio-abigen)
eosio_clang_install(../lib/LLVMEosioApply${CMAKE_SHARED_LIBRARY_SUFFIX})
eosio_clang_install(../lib/eosio_plugin${CMAKE_SHARED_LIBRARY_SUFFIX})
2 changes: 1 addition & 1 deletion eosio_llvm
Submodule eosio_llvm updated 1 files
+1 −1 tools/clang
2 changes: 2 additions & 0 deletions libraries/boost/include/boost/pfr/detail/config.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@
# define BOOST_PFR_USE_LOOPHOLE 1
#endif

#define BOOST_PFR_USE_CPP17 0

#ifndef BOOST_PFR_USE_CPP17
# ifdef __cpp_structured_bindings
# define BOOST_PFR_USE_CPP17 1
Expand Down
2 changes: 0 additions & 2 deletions libraries/eosiolib/action.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -296,7 +296,6 @@ namespace eosio {
action( perms, code, act, std::move(args) ).send();
}


template<typename, name::raw>
struct inline_dispatcher;

Expand All @@ -311,7 +310,6 @@ namespace eosio {
}
};


} // namespace eosio

#define INLINE_ACTION_SENDER3( CONTRACT_CLASS, FUNCTION_NAME, ACTION_NAME )\
Expand Down
84 changes: 84 additions & 0 deletions libraries/eosiolib/datastream.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
#include <eosiolib/system.h>
#include <eosiolib/memory.h>
#include <eosiolib/symbol.hpp>
#include <eosiolib/ignore.hpp>
#include <boost/container/flat_set.hpp>
#include <boost/container/flat_map.hpp>
#include <eosiolib/varint.hpp>
Expand All @@ -14,6 +15,7 @@
#include <set>
#include <map>
#include <string>
#include <optional>

#include <boost/fusion/algorithm/iteration/for_each.hpp>
#include <boost/fusion/include/for_each.hpp>
Expand Down Expand Up @@ -262,6 +264,45 @@ class datastream<size_t> {
size_t _size;
};

/**
* Serialize an optional into a stream
*
* @brief Serialize an optional
* @param ds - The stream to write
* @param opt - The value to serialize
* @tparam Stream - Type of datastream buffer
* @return datastream<Stream>& - Reference to the datastream
*/
template<typename Stream, typename T>
inline datastream<Stream>& operator<<(datastream<Stream>& ds, const std::optional<T>& opt) {
char valid = opt.has_value();
ds << valid;
if (valid)
ds << *opt;
return ds;
}

/**
* Deserialize an optional from a stream
*
* @brief Deserialize an optional
* @param ds - The stream to read
* @param opt - The destination for deserialized value
* @tparam Stream - Type of datastream buffer
* @return datastream<Stream>& - Reference to the datastream
*/
template<typename Stream, typename T>
inline datastream<Stream>& operator>>(datastream<Stream>& ds, std::optional<T>& opt) {
char valid = 0;
ds >> valid;
if (valid) {
T val;
ds >> val;
opt = val;
}
return ds;
}

/**
* Serialize a symbol_code into a stream
*
Expand Down Expand Up @@ -328,6 +369,49 @@ inline datastream<Stream>& operator>>(datastream<Stream>& ds, eosio::symbol& sym
return ds;
}

/**
* Serialize an ignored_wrapper type into a stream
*
* @brief Serialize ignored_wrapper<T>'s T value
* @param ds - The stream to write
* @param ignore - The value to serialize
* @tparam Stream - Type of datastream buffer
* @return datastream<Stream>& - Reference to the datastream
*/
template<typename Stream, typename T>
inline datastream<Stream>& operator<<(datastream<Stream>& ds, const ::eosio::ignore_wrapper<T>& val) {
ds << val.value;
return ds;
}

/**
* Serialize an ignored type into a stream
*
* @brief Serialize an ignored type
* @param ds - The stream to write
* @param ignore - The value to serialize
* @tparam Stream - Type of datastream buffer
* @return datastream<Stream>& - Reference to the datastream
*/
template<typename Stream, typename T>
inline datastream<Stream>& operator<<(datastream<Stream>& ds, const ::eosio::ignore<T>& val) {
return ds;
}

/**
* Deserialize an ignored type from a stream
*
* @brief Deserialize an ignored type
* @param ds - The stream to read
* @param ignored - The destination for deserialized value
* @tparam Stream - Type of datastream buffer
* @return datastream<Stream>& - Reference to the datastream
*/
template<typename Stream, typename T>
inline datastream<Stream>& operator>>(datastream<Stream>& ds, ::eosio::ignore<T>) {
return ds;
}

/**
* Serialize a public_key into a stream
*
Expand Down
29 changes: 29 additions & 0 deletions libraries/eosiolib/ignore.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
#pragma once

namespace eosio {
/**
* Tells the datastream to ignore this type, but allows the abi generator to add the correct type.
* Currently non-ignore types can not succeed an ignore type in a method definition, i.e. void foo(float, ignore<int>) is allowed and void foo(float, ignore<int>, int) is not allowed.
* This restriction will be relaxed in a later release.
* @brief Tells the datastream to ignore this type, but allows the abi generator to add the correct type.
* Currently non-ignore types can not succeed an ignore type in a method definition, i.e. void foo(float, ignore<int>) is allowed and void foo(float, ignore<int>, int) is not allowed.
* This restriction will be relaxed in a later release.
*/
template <typename T>
struct [[eosio::ignore]] ignore {};

/**
* Wrapper class to allow sending inline actions with the correct payload
* @brief Wrapper class to allow sending inline actions with the correct payload
*/
template <typename T>
struct ignore_wrapper {
constexpr ignore_wrapper() {}
constexpr ignore_wrapper(T val) : value(val) {}
constexpr ignore_wrapper(ignore<T> val) {}
constexpr inline T get() { return value; }
constexpr operator T() { return value; }
constexpr operator ignore<T>() { return {}; }
T value;
};
} //ns eosio

0 comments on commit 8d3b644

Please sign in to comment.