Commit 4a354707 authored by neverlord's avatar neverlord

maintenance and documentation

parent a0de91c7
......@@ -57,7 +57,7 @@ class any_tuple
const cow_ptr<detail::abstract_tuple>& vals() const;
bool equal_to(const any_tuple& other) const;
bool equals(const any_tuple& other) const;
any_tuple tail(size_t offset = 1) const;
......@@ -76,7 +76,7 @@ class any_tuple
inline bool operator==(const any_tuple& lhs, const any_tuple& rhs)
{
return lhs.equal_to(rhs);
return lhs.equals(rhs);
}
inline bool operator!=(const any_tuple& lhs, const any_tuple& rhs)
......
......@@ -20,7 +20,7 @@ struct abstract_tuple : ref_counted
virtual const void* at(size_t pos) const = 0;
virtual const uniform_type_info& utype_info_at(size_t pos) const = 0;
virtual bool equal_to(const abstract_tuple& other) const;
virtual bool equals(const abstract_tuple& other) const;
};
......
......@@ -57,7 +57,7 @@ class decorated_tuple : public abstract_tuple
return m_decorated->utype_info_at(m_mappings[pos]);
}
virtual bool equal_to(const abstract_tuple&) const
virtual bool equals(const abstract_tuple&) const
{
return false;
}
......
......@@ -12,7 +12,7 @@ struct empty_tuple : cppa::detail::abstract_tuple
void* mutable_at(size_t);
abstract_tuple* copy() const;
const void* at(size_t) const;
bool equal_to(const abstract_tuple& other) const;
bool equals(const abstract_tuple& other) const;
const uniform_type_info& utype_info_at(size_t) const;
};
......
......@@ -36,7 +36,7 @@ class object_array : public detail::abstract_tuple
const void* at(size_t pos) const;
bool equal_to(const cppa::detail::abstract_tuple&) const;
bool equals(const cppa::detail::abstract_tuple&) const;
const uniform_type_info& utype_info_at(size_t pos) const;
......
......@@ -232,7 +232,7 @@ bool do_match(pattern_arg& pargs, tuple_iterator_arg<VectorType>& targs)
{
// compare values if needed
if ( pargs.has_value() == false
|| pargs.type()->equal(pargs.value(), targs.value()))
|| pargs.type()->equals(pargs.value(), targs.value()))
{
targs.push_mapping();
// ok, go to next iteration
......
......@@ -74,7 +74,7 @@ class tuple_vals : public abstract_tuple
return m_types.at(pos);
}
bool equal_to(const abstract_tuple& other) const
bool equals(const abstract_tuple& other) const
{
if (size() != other.size()) return false;
const tuple_vals* o = dynamic_cast<const tuple_vals*>(&other);
......@@ -82,7 +82,7 @@ class tuple_vals : public abstract_tuple
{
return m_data == (o->m_data);
}
return abstract_tuple::equal_to(other);
return abstract_tuple::equals(other);
}
};
......
......@@ -4,6 +4,7 @@
#include <string>
#include <cstdint>
#include <exception>
#include <stdexcept>
namespace cppa {
......@@ -13,7 +14,15 @@ namespace cppa {
class exception : public std::exception
{
std::string m_what;
public:
~exception() throw();
/**
* @brief Returns the error message.
* @returns The error message as C-string.
*/
const char* what() const throw();
protected:
......@@ -29,58 +38,70 @@ class exception : public std::exception
*/
exception(const std::string& what_str);
public:
private:
~exception() throw();
/**
* @brief Returns the error message.
* @returns The error message as C-string.
*/
const char* what() const throw();
std::string m_what;
};
/**
* @brief Thrown if an Actor finished execution.
* @brief Thrown if an actor finished execution.
*/
class actor_exited : public exception
{
std::uint32_t m_reason;
public:
actor_exited(std::uint32_t exit_reason);
/**
*
* @brief Gets the exit reason.
* @returns The exit reason of the terminating actor either set via
* {@link quit} or by a special (exit) message.
*/
inline std::uint32_t reason() const throw();
private:
std::uint32_t m_reason;
};
class network_exception : public exception
/**
* @brief Thrown to indicate that either an actor publishing failed or
* @p libcppa was unable to connect to a remote host.
*/
class network_error : public exception
{
public:
network_exception(std::string&& what_str);
network_exception(const std::string& what_str);
network_error(std::string&& what_str);
network_error(const std::string& what_str);
};
class bind_failure : public network_exception
/**
* @brief Thrown to indicate that an actor publishing failed because
* the requested port could not be used.
*/
class bind_failure : public network_error
{
int m_errno;
public:
bind_failure(int bind_errno);
/**
* @brief Gets the socket API error code.
* @returns The errno set by <tt>bind()</tt>.
*/
inline int error_code() const throw();
private:
int m_errno;
};
inline std::uint32_t actor_exited::reason() const throw()
......
......@@ -64,6 +64,7 @@ inline void local_actor::trap_exit(bool new_value)
/**
* @brief Get a pointer to the current active context.
* @returns A pointer that identifies the calling actor.
*/
local_actor* self();
......
......@@ -6,44 +6,53 @@
#include <stdexcept>
#include <type_traits>
#include "cppa/exception.hpp"
#include "cppa/util/rm_ref.hpp"
#include "cppa/util/disjunction.hpp"
#include "cppa/detail/implicit_conversions.hpp"
namespace cppa {
// forward declarations
class object;
bool operator==(const object& lhs, const object& rhs);
class uniform_type_info;
const uniform_type_info* uniform_typeid(const std::type_info&);
namespace detail { template<typename T> struct object_caster; }
bool operator==(const uniform_type_info& lhs, const std::type_info& rhs);
/**
* @brief A wrapper around a void pointer that stores type informations
* and provides copy, move and comparsion operations.
* @brief Grants mutable access to the stored value of @p obj.
* @param obj {@link object Object} with <tt>obj.type() == typeid(T)</tt>.
* @returns A mutable reference to the value stored in @p obj.
* @relates object
* @throws std::invalid_argument if <tt>obj.type() != typeid(T)</tt>
*/
class object
{
friend class uniform_type_info;
template<typename T>
friend struct detail::object_caster;
template<typename T>
T& get_ref(object& obj);
void* m_value;
const uniform_type_info* m_type;
/**
* @brief Grants const access to the stored value of @p obj.
* @param obj {@link object Object} with <tt>obj.type() == typeid(T)</tt>.
* @returns A const reference to the value stored in @p obj.
* @relates object
* @throws std::invalid_argument if <tt>obj.type() != typeid(T)</tt>
*/
template<typename T>
const T& get(const object& obj);
void swap(object& other);
/**
* @brief An abstraction class that stores an instance of
* an announced type.
*/
class object
{
/*
* @brief Copies this object.
* @returns A (deep) copy of this object.
*/
object copy() const;
friend bool operator==(const object& lhs, const object& rhs);
static void* new_instance(const uniform_type_info* type,
const void* from);
public:
public:
~object();
/**
* @brief Creates an object of type @p utinfo with value @p val.
......@@ -54,70 +63,81 @@ public:
/**
* @brief Creates an empty object.
* @post {@code empty() && type() == *uniform_typeid<util::void_type>()}
* @post {type() == *uniform_typeid<util::void_type>()}
*/
object();
/**
* @brief Creates an object with a copy of @p what.
* @post {@code empty() == false && type() == *uniform_typeid<T>()}
*/
template<typename T>
explicit object(const T& what);
~object();
/**
* @brief Creates an object and moves type and value
* from @p other to @c this.
* @post {@code other.empty() == true}
*/
object(object&& other);
/**
* @brief Creates a copy of @p other.
* @post {@code type() == other.type() && equal_to(other)}
* @brief Creates a (deep) copy of @p other.
* @post {*this == other}
*/
object(const object& other);
/**
* @brief Moves the content from @p other to this.
* @returns @p *this
* @post {@code other.empty() == true}
*/
object& operator=(object&& other);
/**
*
* @brief Creates a (deep) copy of @p other and assigns it to @p this.
* @return @p *this
*/
object& operator=(const object& other);
bool equal_to(const object& other) const;
/**
* @brief Gets the RTTI of this object.
* @returns A {@link uniform_type_info} describing the current
* type of @p this.
*/
const uniform_type_info& type() const;
/**
* @brief Gets the stored value.
* @returns A const pointer to the currently stored value.
* @see get(const object&)
*/
const void* value() const;
/**
* @brief Gets the stored value.
* @returns A mutable pointer to the currently stored value.
* @see get_ref(object&)
*/
void* mutable_value();
bool empty() const;
/**
* @brief Creates an object from @p what.
* @param what Value of an announced type.
* @returns An object whose value was initialized with @p what.
* @post {@code type() == *uniform_typeid<T>()}
* @throws std::runtime_error if @p T is not announced.
*/
template<typename T>
static object from(T&& what);
private:
void* m_value;
const uniform_type_info* m_type;
void swap(object& other);
};
template<typename T>
object::object(const T& what)
object object::from(T&& what)
{
m_type = uniform_typeid(typeid(T));
if (!m_type)
{
throw std::logic_error("unknown/unannounced type");
}
m_value = new_instance(m_type, &what);
}
inline bool operator==(const object& lhs, const object& rhs)
{
return lhs.equal_to(rhs);
typedef typename util::rm_ref<T>::type plain_type;
typedef typename detail::implicit_conversions<plain_type>::type value_type;
auto rtti = uniform_typeid(typeid(value_type)); // throws on error
return { new value_type(std::forward<T>(what)), rtti };
}
inline bool operator!=(const object& lhs, const object& rhs)
......@@ -125,25 +145,16 @@ inline bool operator!=(const object& lhs, const object& rhs)
return !(lhs == rhs);
}
namespace detail {
inline void assert_type(const object& obj, const std::type_info& tinfo)
{
if (!(obj.type() == tinfo))
{
throw std::logic_error("object type doesnt match T");
}
}
} // namespace detail
template<typename T>
T& get_ref(object& obj)
{
static_assert(util::disjunction<std::is_pointer<T>,
std::is_reference<T>>::value == false,
"T is a reference or a pointer type.");
detail::assert_type(obj, typeid(T));
if (!(obj.type() == typeid(T)))
{
throw std::invalid_argument("obj.type() != typeid(T)");
}
return *reinterpret_cast<T*>(obj.mutable_value());
}
......@@ -152,8 +163,11 @@ const T& get(const object& obj)
{
static_assert(util::disjunction<std::is_pointer<T>,
std::is_reference<T>>::value == false,
"T is a reference a pointer type.");
detail::assert_type(obj, typeid(T));
"T is a reference or a pointer type.");
if (!(obj.type() == typeid(T)))
{
throw std::invalid_argument("obj.type() != typeid(T)");
}
return *reinterpret_cast<const T*>(obj.value());
}
......
......@@ -82,14 +82,16 @@ class scheduler
};
/**
* @brief Sets the scheduler to @p sched;
* @brief Sets the scheduler to @p sched.
* @param sched A user-defined scheduler implementation.
* @pre <tt>sched != nullptr</tt>.
* @throws std::runtime_error if there's already a scheduler defined.
*/
void set_scheduler(scheduler* sched);
/**
* @brief Gets the actual used scheduler implementation.
* @returns The active scheduler (default constructed).
* @returns The active scheduler (usually default constructed).
*/
scheduler* get_scheduler();
......
......@@ -11,6 +11,11 @@ std::string to_string_impl(const void* what, const uniform_type_info* utype);
} // namespace detail
/**
* @brief Serializes a value to a string.
* @param what A value of an announced type.
* @returns A string representation of @p what.
*/
template<typename T>
std::string to_string(const T& what)
{
......
......@@ -43,7 +43,7 @@ const uniform_type_info* uniform_typeid(const std::type_info&);
*
* @code
* // creates a signed, 32 bit integer
* cppa::object i = cppa::uniform_type_info::by_uniform_name("@i32")->create();
* cppa::object i = cppa::uniform_type_info::by_name("@i32")->create();
* @endcode
*
* However, you should rarely if ever need to use {@link cppa::object object}
......@@ -116,48 +116,13 @@ const uniform_type_info* uniform_typeid(const std::type_info&);
* e.g.: <tt>namespace { class foo { }; }</tt> is mapped to
* @c \@_::foo
*/
class uniform_type_info : cppa::util::comparable<uniform_type_info>
class uniform_type_info
{
friend class object;
// needs access to by_type_info()
friend const uniform_type_info* uniform_typeid(const std::type_info&);
public:
class identifier : cppa::util::comparable<identifier>
{
friend class uniform_type_info;
int m_value;
identifier(int val) : m_value(val) { }
// disable assignment operators
identifier& operator=(const identifier&) = delete;
public:
// enable copy constructor (only)
identifier(const identifier&) = default;
// needed by cppa::detail::comparable<identifier>
inline int compare(const identifier& other) const
{
return m_value - other.m_value;
}
};
private:
// unique identifier
identifier m_id;
// uniform type name
std::string m_name;
friend bool operator==(const uniform_type_info& lhs,
const uniform_type_info& rhs);
// disable copy and move constructors
uniform_type_info(uniform_type_info&&) = delete;
......@@ -167,20 +132,25 @@ class uniform_type_info : cppa::util::comparable<uniform_type_info>
uniform_type_info& operator=(uniform_type_info&&) = delete;
uniform_type_info& operator=(const uniform_type_info&) = delete;
static const uniform_type_info* by_type_info(const std::type_info& tinfo);
protected:
uniform_type_info(const std::string& uniform_name);
public:
virtual ~uniform_type_info();
/**
* @brief Get instance by uniform name.
* @param uniform_name The @p libcppa internal name for a type.
* @returns The instance associated to @p uniform_name.
* @throws std::runtime_error if no type named @p uniform_name was found.
*/
static uniform_type_info* from(const std::string& uniform_name);
/**
* @brief Get instance by std::type_info.
* @param tinfo A STL RTTI object.
* @returns An instance describing the same type as @p tinfo.
* @throws std::runtime_error if @p tinfo is not an announced type.
*/
static uniform_type_info* by_uniform_name(const std::string& uniform_name);
static const uniform_type_info* from(const std::type_info& tinfo);
/**
* @brief Get all instances.
......@@ -188,26 +158,12 @@ class uniform_type_info : cppa::util::comparable<uniform_type_info>
*/
static std::vector<uniform_type_info*> instances();
virtual ~uniform_type_info();
/**
* @brief Get the internal @p libcppa name for this type.
* @returns A string describing the @p libcppa internal type name.
*/
inline const std::string& name() const { return m_name; }
/**
* @brief Get the unique identifier of this instance.
* @returns The unique identifier of this instance.
*/
inline const identifier& id() const { return m_id; }
// needed by cppa::detail::comparable<uniform_type_info>
inline int compare(const uniform_type_info& other) const
{
return id().compare(other.id());
}
/**
* @brief Creates an object of this type.
*/
......@@ -219,41 +175,62 @@ class uniform_type_info : cppa::util::comparable<uniform_type_info>
object deserialize(deserializer* source) const;
/**
* @brief Compares two instances of this type.
* @brief Determines if this uniform_type_info describes the same
* type than @p tinfo.
* @returns @p true if @p tinfo describes the same type as @p this.
*/
virtual bool equal(const void* instance1, const void* instance2) const = 0;
protected:
virtual bool equals(const std::type_info& tinfo) const = 0;
/**
* @brief Cast @p instance to the native type and delete it.
* @brief Compares two instances of this type.
* @param instance1 Left hand operand.
* @param instance2 Right hand operand.
* @returns @p true if <tt>*instance1 == *instance2</tt>.
* @pre @p instance1 and @p instance2 have the type of @p this.
*/
virtual void delete_instance(void* instance) const = 0;
virtual bool equals(const void* instance1, const void* instance2) const = 0;
/**
* @brief Creates an instance of this type, either as a copy of
* @p instance or initialized with the default constructor
* if @p instance @c == @c nullptr.
* @brief Serializes @p instance to @p sink.
* @param instance Instance of this type.
* @param sink Target data sink.
* @pre @p instance has the type of @p this.
*/
virtual void* new_instance(const void* instance = nullptr) const = 0;
public:
virtual void serialize(const void* instance, serializer* sink) const = 0;
/**
* @brief Determines if this uniform_type_info describes the same
* type than @p tinfo.
* @brief Deserializes @p instance from @p source.
* @param instance Instance of this type.
* @param sink Data source.
* @pre @p instance has the type of @p this.
*/
virtual bool equal(const std::type_info& tinfo) const = 0;
virtual void deserialize(void* instance, deserializer* source) const = 0;
protected:
uniform_type_info(const std::string& uniform_name);
/**
* @brief Serializes @p instance to @p sink.
* @brief Casts @p instance to the native type and deletes it.
* @param instance Instance of this type.
* @pre @p instance has the type of @p this.
*/
virtual void serialize(const void* instance, serializer* sink) const = 0;
virtual void delete_instance(void* instance) const = 0;
/**
* @brief Deserializes @p instance from @p source.
* @brief Creates an instance of this type, either as a copy of
* @p instance or initialized with the default constructor
* if <tt>instance == nullptr</tt>.
* @param instance Optional instance of this type.
* @returns Either a copy of @p instance or a new instance, initialized
* with the default constructor.
* @pre @p instance has the type of @p this or is set to @p nullptr.
*/
virtual void deserialize(void* instance, deserializer* source) const = 0;
virtual void* new_instance(const void* instance = nullptr) const = 0;
private:
std::string m_name;
};
......@@ -263,21 +240,38 @@ inline const uniform_type_info* uniform_typeid()
return uniform_typeid(typeid(T));
}
bool operator==(const uniform_type_info& lhs, const std::type_info& rhs);
inline bool operator==(const uniform_type_info& lhs,
const uniform_type_info& rhs)
{
// uniform_type_info instances are singletons,
// thus, equal == identical
return &lhs == &rhs;
}
inline bool operator!=(const uniform_type_info& lhs, const std::type_info& rhs)
inline bool operator!=(const uniform_type_info& lhs,
const uniform_type_info& rhs)
{
return !(lhs == rhs);
}
inline bool operator==(const uniform_type_info& lhs, const std::type_info& rhs)
{
return lhs.equals(rhs);
}
inline bool operator!=(const uniform_type_info& lhs, const std::type_info& rhs)
{
return !(lhs.equals(rhs));
}
inline bool operator==(const std::type_info& lhs, const uniform_type_info& rhs)
{
return rhs == lhs;
return rhs.equals(lhs);
}
inline bool operator!=(const std::type_info& lhs, const uniform_type_info& rhs)
{
return !(rhs == lhs);
return !(rhs.equals(lhs));
}
} // namespace cppa
......
......@@ -32,7 +32,7 @@ class abstract_uniform_type_info : public uniform_type_info
{
}
bool equal(const void* lhs, const void* rhs) const
bool equals(const void* lhs, const void* rhs) const
{
return deref(lhs) == deref(rhs);
}
......@@ -49,7 +49,7 @@ class abstract_uniform_type_info : public uniform_type_info
public:
bool equal(const std::type_info& tinfo) const
bool equals(const std::type_info& tinfo) const
{
return typeid(T) == tinfo;
}
......
......@@ -81,15 +81,7 @@ struct tree
// tree nodes are equals if values and all values of all children are equal
bool operator==(const tree_node& lhs, const tree_node& rhs)
{
if (lhs.value == rhs.value && lhs.children.size() == rhs.children.size())
{
for (std::uint32_t i = 0; i < lhs.children.size(); ++i)
{
if (!(lhs.children[i] == rhs.children[i])) return false;
}
return true;
}
return false;
return (lhs.value == rhs.value) && (lhs.children == rhs.children);
}
bool operator==(const tree& lhs, const tree& rhs)
......@@ -144,7 +136,7 @@ class tree_type_info : public util::abstract_uniform_type_info<tree>
void serialize_node(const tree_node& node, serializer* sink) const
{
// serialize { value, number of children } ... children ...
// value, ... children ...
sink->write_value(node.value);
sink->begin_sequence(node.children.size());
for (const tree_node& subnode : node.children)
......@@ -156,7 +148,7 @@ class tree_type_info : public util::abstract_uniform_type_info<tree>
void deserialize_node(tree_node& node, deserializer* source) const
{
// deserialize { value, number of children } ... children ...
// value, ... children ...
auto value = get<std::uint32_t>(source->read_value(pt_uint32));
node.value = value;
auto num_children = source->begin_sequence();
......
......@@ -2,7 +2,7 @@
namespace cppa { namespace detail {
bool abstract_tuple::equal_to(const abstract_tuple &other) const
bool abstract_tuple::equals(const abstract_tuple &other) const
{
if (this == &other) return true;
if (size() != other.size()) return false;
......@@ -13,7 +13,7 @@ bool abstract_tuple::equal_to(const abstract_tuple &other) const
auto lhs = at(i);
auto rhs = other.at(i);
// compare first addresses, then values
if (lhs != rhs && !(uti.equal(lhs, rhs))) return false;
if (lhs != rhs && !(uti.equals(lhs, rhs))) return false;
}
return true;
}
......
......@@ -111,9 +111,9 @@ const cow_ptr<detail::abstract_tuple>& any_tuple::vals() const
return m_vals;
}
bool any_tuple::equal_to(const any_tuple& other) const
bool any_tuple::equals(const any_tuple& other) const
{
return m_vals->equal_to(*other.vals());
return m_vals->equals(*other.vals());
}
} // namespace cppa
......@@ -14,7 +14,7 @@ deserializer::~deserializer()
deserializer& operator>>(deserializer& d, object& what)
{
std::string tname = d.peek_object();
auto mtype = uniform_type_info::by_uniform_name(tname);
auto mtype = uniform_type_info::from(tname);
if (mtype == nullptr)
{
throw std::logic_error("no uniform type info found for " + tname);
......
......@@ -28,7 +28,7 @@ const uniform_type_info& empty_tuple::utype_info_at(size_t) const
throw std::range_error("empty_tuple::type_at()");
}
bool empty_tuple::equal_to(const abstract_tuple& other) const
bool empty_tuple::equals(const abstract_tuple& other) const
{
return other.size() == 0;
}
......
......@@ -57,16 +57,16 @@ actor_exited::actor_exited(std::uint32_t reason) : exception(ae_what(reason))
m_reason = reason;
}
network_exception::network_exception(const std::string& str) : exception(str)
network_error::network_error(const std::string& str) : exception(str)
{
}
network_exception::network_exception(std::string&& str)
network_error::network_error(std::string&& str)
: exception(std::move(str))
{
}
bind_failure::bind_failure(int err_code) : network_exception(be_what(err_code))
bind_failure::bind_failure(int err_code) : network_error(be_what(err_code))
{
m_errno = err_code;
}
......
......@@ -19,17 +19,6 @@ void object::swap(object& other)
std::swap(m_type, other.m_type);
}
void* object::new_instance(const uniform_type_info* type, const void* from)
{
return type->new_instance(from);
}
object object::copy() const
{
return (m_value != &s_void) ? object(m_type->new_instance(m_value), m_type)
: object();
}
object::object(void* val, const uniform_type_info* utype)
: m_value(val), m_type(utype)
{
......@@ -51,8 +40,11 @@ object::~object()
object::object(const object& other) : m_value(&s_void), m_type(uniform_typeid<util::void_type>())
{
object tmp = other.copy();
swap(tmp);
if (other.value() != &s_void)
{
m_value = other.m_type->new_instance(other.m_value);
m_type = other.m_type;
}
}
object::object(object&& other) : m_value(&s_void), m_type(uniform_typeid<util::void_type>())
......@@ -69,17 +61,19 @@ object& object::operator=(object&& other)
object& object::operator=(const object& other)
{
object tmp = other.copy();
// use copy ctor and then swap
object tmp(other);
swap(tmp);
return *this;
}
bool object::equal_to(const object& other) const
bool operator==(const object& lhs, const object& rhs)
{
if (m_type == other.m_type)
if (lhs.type() == rhs.type())
{
return (m_value != &s_void) ? m_type->equal(m_value, other.m_value)
: true;
// values might both point to s_void if lhs and rhs are "empty"
return lhs.value() == rhs.value()
|| lhs.type().equals(lhs.value(), rhs.value());
}
return false;
}
......@@ -89,11 +83,6 @@ const uniform_type_info& object::type() const
return *m_type;
}
bool object::empty() const
{
return m_value == &s_void;
}
const void* object::value() const
{
return m_value;
......
......@@ -46,7 +46,7 @@ const void* object_array::at(size_t pos) const
return m_elements[pos].value();
}
bool object_array::equal_to(const cppa::detail::abstract_tuple& ut) const
bool object_array::equals(const cppa::detail::abstract_tuple& ut) const
{
if (size() == ut.size())
{
......@@ -55,7 +55,7 @@ bool object_array::equal_to(const cppa::detail::abstract_tuple& ut) const
const uniform_type_info& utype = utype_info_at(i);
if (utype == ut.utype_info_at(i))
{
if (!utype.equal(at(i), ut.at(i))) return false;
if (!utype.equals(at(i), ut.at(i))) return false;
}
else
{
......
......@@ -462,7 +462,7 @@ object from_string(const std::string& what)
{
string_deserializer strd(what);
std::string uname = strd.peek_object();
auto utype = uniform_type_info::by_uniform_name(uname);
auto utype = uniform_type_info::from(uname);
if (utype == nullptr)
{
throw std::logic_error(uname + " is not announced");
......
......@@ -86,7 +86,7 @@ void publish(actor_ptr& whom, std::uint16_t port)
sockfd = socket(AF_INET, SOCK_STREAM, 0);
if (sockfd < 0)
{
throw network_exception("could not create server socket");
throw network_error("could not create server socket");
}
// sguard closes the socket if an exception occurs
socket_guard sguard(sockfd);
......@@ -97,11 +97,11 @@ void publish(actor_ptr& whom, std::uint16_t port)
int flags = fcntl(sockfd, F_GETFL, 0);
if (flags == -1)
{
throw network_exception("unable to get socket flags");
throw network_error("unable to get socket flags");
}
if (fcntl(sockfd, F_SETFL, flags | O_NONBLOCK) == -1)
{
throw network_exception("unable to set socket to nonblocking");
throw network_error("unable to set socket to nonblocking");
}
if (bind(sockfd, (struct sockaddr*) &serv_addr, sizeof(serv_addr)) < 0)
{
......@@ -109,7 +109,7 @@ void publish(actor_ptr& whom, std::uint16_t port)
}
if (listen(sockfd, 10) != 0)
{
throw network_exception("listen() failed");
throw network_error("listen() failed");
}
// ok, no exceptions
sguard.release();
......@@ -129,14 +129,14 @@ actor_ptr remote_actor(const char* host, std::uint16_t port)
sockfd = socket(AF_INET, SOCK_STREAM, 0);
if (sockfd < 0)
{
throw network_exception("socket creation failed");
throw network_error("socket creation failed");
}
server = gethostbyname(host);
if (!server)
{
std::string errstr = "no such host: ";
errstr += host;
throw network_exception(std::move(errstr));
throw network_error(std::move(errstr));
}
memset(&serv_addr, 0, sizeof(serv_addr));
serv_addr.sin_family = AF_INET;
......@@ -144,7 +144,7 @@ actor_ptr remote_actor(const char* host, std::uint16_t port)
serv_addr.sin_port = htons(port);
if (connect(sockfd, (const sockaddr*) &serv_addr, sizeof(serv_addr)) < 0)
{
throw network_exception("could not connect to host");
throw network_error("could not connect to host");
}
auto pinf = process_information::get();
std::uint32_t process_id = pinf->process_id();
......
......@@ -51,10 +51,6 @@ istream& operator>>(istream& i, cppa::util::void_type&) { return i; }
namespace {
std::atomic<int> s_ids;
inline int next_id() { return s_ids.fetch_add(1); }
inline cppa::detail::uniform_type_info_map& uti_map()
{
return *(cppa::detail::singleton_manager::get_uniform_type_info_map());
......@@ -416,7 +412,7 @@ class any_tuple_tinfo : public util::abstract_uniform_type_info<any_tuple>
for (size_t i = 0; i < tuple_size; ++i)
{
auto tname = source->peek_object();
auto utype = uniform_type_info::by_uniform_name(tname);
auto utype = uniform_type_info::from(tname);
result->push_back(utype->deserialize(source));
}
source->end_sequence();
......@@ -570,7 +566,7 @@ class int_tinfo : public detail::default_uniform_type_info_impl<T>
public:
bool equal(const std::type_info& tinfo) const
bool equals(const std::type_info& tinfo) const
{
// TODO: string comparsion sucks & is slow; find a nicer solution
auto map_iter = uti_map().int_names().find(sizeof(T));
......@@ -778,8 +774,7 @@ bool announce(const std::type_info& tinfo, uniform_type_info* utype)
return uti_map().insert({ raw_name(tinfo) }, utype);
}
uniform_type_info::uniform_type_info(const std::string& uname)
: m_id(next_id()), m_name(uname)
uniform_type_info::uniform_type_info(const std::string& uname) : m_name(uname)
{
}
......@@ -793,7 +788,7 @@ object uniform_type_info::create() const
}
const uniform_type_info*
uniform_type_info::by_type_info(const std::type_info& tinf)
uniform_type_info::from(const std::type_info& tinf)
{
auto result = uti_map().by_raw_name(raw_name(tinf));
if (!result)
......@@ -806,7 +801,7 @@ uniform_type_info::by_type_info(const std::type_info& tinf)
return result;
}
uniform_type_info* uniform_type_info::by_uniform_name(const std::string& name)
uniform_type_info* uniform_type_info::from(const std::string& name)
{
auto result = uti_map().by_uniform_name(name);
if (!result)
......@@ -830,12 +825,7 @@ std::vector<uniform_type_info*> uniform_type_info::instances()
const uniform_type_info* uniform_typeid(const std::type_info& tinfo)
{
return uniform_type_info::by_type_info(tinfo);
}
bool operator==(const uniform_type_info& lhs, const std::type_info& rhs)
{
return lhs.equal(rhs);
return uniform_type_info::from(tinfo);
}
} // namespace cppa
......@@ -118,8 +118,8 @@ size_t test__serialization()
CPPA_TEST(test__serialization);
auto oarr = new detail::object_array;
oarr->push_back(object(static_cast<std::uint32_t>(42)));
oarr->push_back(object(std::string("foo")));
oarr->push_back(object::from(static_cast<std::uint32_t>(42)));
oarr->push_back(object::from("foo" ));
any_tuple atuple1(oarr);
try
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment