diff options
Diffstat (limited to 'src/components/rpc_base')
12 files changed, 839 insertions, 818 deletions
diff --git a/src/components/rpc_base/include/rpc_base/gtest_support.h b/src/components/rpc_base/include/rpc_base/gtest_support.h index daea5d3884..04ad1219b5 100644 --- a/src/components/rpc_base/include/rpc_base/gtest_support.h +++ b/src/components/rpc_base/include/rpc_base/gtest_support.h @@ -39,9 +39,9 @@ // A predicate-formatter for asserting that intergen generated // object is valid -template<typename T> +template <typename T> ::testing::AssertionResult AssertRpcObjValid(const char* obj_expr, - const T& obj) { + const T& obj) { if (obj.is_valid()) return ::testing::AssertionSuccess(); @@ -49,8 +49,8 @@ template<typename T> obj.ReportErrors(&report); return ::testing::AssertionFailure() - << obj_expr << " failed validation. Violations are:\n" - << rpc::PrettyFormat(report); + << obj_expr << " failed validation. Violations are:\n" + << rpc::PrettyFormat(report); } #define ASSERT_RPCTYPE_VALID(object) \ diff --git a/src/components/rpc_base/include/rpc_base/rpc_base.h b/src/components/rpc_base/include/rpc_base/rpc_base.h index da0a7f2388..883c2ec4bf 100644 --- a/src/components/rpc_base/include/rpc_base/rpc_base.h +++ b/src/components/rpc_base/include/rpc_base/rpc_base.h @@ -52,47 +52,58 @@ class ValidationReport; namespace policy_table_interface_base { - enum PolicyTableType { - INVALID_PT_TYPE = -1, - PT_PRELOADED, - PT_UPDATE, - PT_SNAPSHOT - }; - const std::string ommited_validation_info = "should be ommited in "; - const std::string required_validation_info = "is required in "; - - std::string PolicyTableTypeToString(const PolicyTableType pt_type); - +enum PolicyTableType { + INVALID_PT_TYPE = -1, + PT_PRELOADED, + PT_UPDATE, + PT_SNAPSHOT +}; +const std::string ommited_validation_info = "should be ommited in "; +const std::string required_validation_info = "is required in "; +std::string PolicyTableTypeToString(const PolicyTableType pt_type); } -template<typename T> class Range; +template <typename T> +class Range; class PrimitiveType; class CompositeType; class Boolean; -template<typename T, T minval, T maxval> class Integer; -template<int64_t minnum, int64_t maxnum, - int64_t minden = 1, int64_t maxden = 1> class Float; -template<size_t minlen, size_t maxlen> class String; -template<typename T> class Enum; -template<typename T, size_t minsize, size_t maxsize> class Array; -template<typename T, size_t minsize, size_t maxsize> class Map; -template<typename T> class Nullable; -template<typename T> class Optional; -template<typename T> class Stringifyable; - -template<typename T> +template <typename T, T minval, T maxval> +class Integer; +template <int64_t minnum, + int64_t maxnum, + int64_t minden = 1, + int64_t maxden = 1> +class Float; +template <size_t minlen, size_t maxlen> +class String; +template <typename T> +class Enum; +template <typename T, size_t minsize, size_t maxsize> +class Array; +template <typename T, size_t minsize, size_t maxsize> +class Map; +template <typename T> +class Nullable; +template <typename T> +class Optional; +template <typename T> +class Stringifyable; + +template <typename T> class Range { - public: - // Methods - Range(const T min, const T max); - T min() const; - T max() const; - template<typename U> - bool Includes(U val) const; - private: - T min_; - T max_; + public: + // Methods + Range(const T min, const T max); + T min() const; + T max() const; + template <typename U> + bool Includes(U val) const; + + private: + T min_; + T max_; }; /* @@ -100,316 +111,326 @@ class Range { * tell whether descendant object was initialized */ class PrimitiveType { - public: - bool is_initialized() const; - bool is_valid() const; - void ReportErrors(ValidationReport* report) const; - policy_table_interface_base::PolicyTableType GetPolicyTableType() const; - virtual void SetPolicyTableType(policy_table_interface_base::PolicyTableType pt_type); - - protected: - enum ValueState { - kUninitialized, - kInvalid, - kValid - }; - explicit PrimitiveType(ValueState value_state); - static ValueState InitHelper(bool is_next); - static ValueState InitHelper(const Json::Value* value, - bool (Json::Value::*type_check)() const); - - protected: - ValueState value_state_; - policy_table_interface_base::PolicyTableType policy_table_type_; + public: + bool is_initialized() const; + bool is_valid() const; + void ReportErrors(ValidationReport* report) const; + policy_table_interface_base::PolicyTableType GetPolicyTableType() const; + virtual void SetPolicyTableType( + policy_table_interface_base::PolicyTableType pt_type); + + protected: + enum ValueState { kUninitialized, kInvalid, kValid }; + explicit PrimitiveType(ValueState value_state); + static ValueState InitHelper(bool is_next); + static ValueState InitHelper(const Json::Value* value, + bool (Json::Value::*type_check)() const); + + protected: + ValueState value_state_; + policy_table_interface_base::PolicyTableType policy_table_type_; }; /* * Base class for all composite types (arrays and all user-defined types) */ class CompositeType { - public: - void mark_initialized(); - void ReportErrors(ValidationReport* report) const; - policy_table_interface_base::PolicyTableType GetPolicyTableType() const; - virtual void SetPolicyTableType(policy_table_interface_base::PolicyTableType pt_type); - - protected: - enum InitializationState { - kUninitialized, - kInitialized, - kInvalidInitialized - }; - explicit CompositeType(InitializationState init_state); - virtual ~CompositeType(){} - static InitializationState InitHelper(bool is_next); - static InitializationState InitHelper(const Json::Value* value, - bool (Json::Value::*type_check)() const); - protected: - mutable InitializationState initialization_state__; - policy_table_interface_base::PolicyTableType policy_table_type_; - + public: + void mark_initialized(); + void ReportErrors(ValidationReport* report) const; + policy_table_interface_base::PolicyTableType GetPolicyTableType() const; + virtual void SetPolicyTableType( + policy_table_interface_base::PolicyTableType pt_type); + + protected: + enum InitializationState { + kUninitialized, + kInitialized, + kInvalidInitialized + }; + explicit CompositeType(InitializationState init_state); + virtual ~CompositeType() {} + static InitializationState InitHelper(bool is_next); + static InitializationState InitHelper(const Json::Value* value, + bool (Json::Value::*type_check)() + const); + + protected: + mutable InitializationState initialization_state__; + policy_table_interface_base::PolicyTableType policy_table_type_; }; /* * Class that holds primitive boolean value. It is always valid. */ class Boolean : public PrimitiveType { - public: - // Types - typedef bool ValueType; - public: - // Methods - Boolean(); - explicit Boolean(bool value); - explicit Boolean(const Json::Value* value); - explicit Boolean(dbus::MessageReader* reader); - Boolean(const Json::Value* value, bool def_value); - Boolean& operator=(bool new_val); - operator bool() const; - Json::Value ToJsonValue() const; - void ToDbusWriter(dbus::MessageWriter* writer) const; - - private: - // Fields - ValueType value_; + public: + // Types + typedef bool ValueType; + + public: + // Methods + Boolean(); + explicit Boolean(bool value); + explicit Boolean(const Json::Value* value); + explicit Boolean(dbus::MessageReader* reader); + Boolean(const Json::Value* value, bool def_value); + Boolean& operator=(bool new_val); + operator bool() const; + Json::Value ToJsonValue() const; + void ToDbusWriter(dbus::MessageWriter* writer) const; + + private: + // Fields + ValueType value_; }; -template<typename T, T minval, T maxval> +template <typename T, T minval, T maxval> class Integer : public PrimitiveType { - public: - // Types - typedef T IntType; - public: - // Methods - Integer(); - explicit Integer(IntType value); - Integer(const Integer& value); - explicit Integer(const Json::Value* value); - explicit Integer(dbus::MessageReader* reader); - Integer(const Json::Value* value, IntType def_value); - Integer& operator=(IntType new_val); - Integer& operator=(const Integer& new_val); - Integer& operator++(); - Integer& operator+=(int value); - operator IntType() const; - Json::Value ToJsonValue() const; - void ToDbusWriter(dbus::MessageWriter* writer) const; - - private: - IntType value_; - static const Range<T> range_; + public: + // Types + typedef T IntType; + + public: + // Methods + Integer(); + explicit Integer(IntType value); + Integer(const Integer& value); + explicit Integer(const Json::Value* value); + explicit Integer(dbus::MessageReader* reader); + Integer(const Json::Value* value, IntType def_value); + Integer& operator=(IntType new_val); + Integer& operator=(const Integer& new_val); + Integer& operator++(); + Integer& operator+=(int value); + operator IntType() const; + Json::Value ToJsonValue() const; + void ToDbusWriter(dbus::MessageWriter* writer) const; + + private: + IntType value_; + static const Range<T> range_; }; -template<int64_t minnum, int64_t maxnum, int64_t minden, int64_t maxden> +template <int64_t minnum, int64_t maxnum, int64_t minden, int64_t maxden> class Float : public PrimitiveType { - public: - // Methods - Float(); - explicit Float(double value); - explicit Float(const Json::Value* value); - explicit Float(dbus::MessageReader* reader); - Float(const Json::Value* value, double def_value); - Float& operator=(double new_val); - operator double() const; - Json::Value ToJsonValue() const; - void ToDbusWriter(dbus::MessageWriter* writer) const; - - private: - double value_; - static const Range<double> range_; + public: + // Methods + Float(); + explicit Float(double value); + explicit Float(const Json::Value* value); + explicit Float(dbus::MessageReader* reader); + Float(const Json::Value* value, double def_value); + Float& operator=(double new_val); + operator double() const; + Json::Value ToJsonValue() const; + void ToDbusWriter(dbus::MessageWriter* writer) const; + + private: + double value_; + static const Range<double> range_; }; -template<size_t minlen, size_t maxlen> +template <size_t minlen, size_t maxlen> class String : public PrimitiveType { - public: - // Methods - String(); - explicit String(const std::string& value); - explicit String(const char* value); - explicit String(const Json::Value* value); - explicit String(dbus::MessageReader* reader); - String(const Json::Value* value, const std::string& def_value); - bool operator<(const String& new_val) const; - String& operator=(const std::string& new_val); - String& operator=(const String& new_val); - bool operator==(const String& rhs) const; - operator const std::string& () const; - Json::Value ToJsonValue() const; - void ToDbusWriter(dbus::MessageWriter* writer) const; - - private: - std::string value_; - static const Range<size_t> length_range_; + public: + // Methods + String(); + explicit String(const std::string& value); + explicit String(const char* value); + explicit String(const Json::Value* value); + explicit String(dbus::MessageReader* reader); + String(const Json::Value* value, const std::string& def_value); + bool operator<(const String& new_val) const; + String& operator=(const std::string& new_val); + String& operator=(const String& new_val); + bool operator==(const String& rhs) const; + operator const std::string&() const; + Json::Value ToJsonValue() const; + void ToDbusWriter(dbus::MessageWriter* writer) const; + + private: + std::string value_; + static const Range<size_t> length_range_; }; -template<typename T> +template <typename T> class Enum : public PrimitiveType { - public: - // Types - typedef T EnumType; - public: - // Methods - Enum(); - explicit Enum(EnumType value); - explicit Enum(const Json::Value* value); - explicit Enum(dbus::MessageReader* reader); - Enum(const Json::Value* value, EnumType def_value); - Enum& operator=(const EnumType& new_val); - operator EnumType() const; - Json::Value ToJsonValue() const; - void ToDbusWriter(dbus::MessageWriter* writer) const; - - private: - // Fields - EnumType value_; + public: + // Types + typedef T EnumType; + + public: + // Methods + Enum(); + explicit Enum(EnumType value); + explicit Enum(const Json::Value* value); + explicit Enum(dbus::MessageReader* reader); + Enum(const Json::Value* value, EnumType def_value); + Enum& operator=(const EnumType& new_val); + operator EnumType() const; + Json::Value ToJsonValue() const; + void ToDbusWriter(dbus::MessageWriter* writer) const; + + private: + // Fields + EnumType value_; }; -template<typename T, size_t minsize, size_t maxsize> +template <typename T, size_t minsize, size_t maxsize> class Array : public std::vector<T>, public CompositeType { - public: - // Types - typedef std::vector<T> ArrayType; - public: - // Methods - Array(); - // Need const and non-const versions to beat all-type accepting constructor - explicit Array(Json::Value* value); - explicit Array(const Json::Value* value); - explicit Array(dbus::MessageReader* reader); - template<typename U> - explicit Array(const U& value); - template<typename U> - Array& operator=(const U& that); - using ArrayType::push_back; - template<typename U> - void push_back(const U& value); - Json::Value ToJsonValue() const; - void ToDbusWriter(dbus::MessageWriter* writer) const; - - bool is_valid() const; - bool is_initialized() const; - void ReportErrors(ValidationReport* report) const; - virtual void SetPolicyTableType(policy_table_interface_base::PolicyTableType pt_type); + public: + // Types + typedef std::vector<T> ArrayType; + + public: + // Methods + Array(); + // Need const and non-const versions to beat all-type accepting constructor + explicit Array(Json::Value* value); + explicit Array(const Json::Value* value); + explicit Array(dbus::MessageReader* reader); + template <typename U> + explicit Array(const U& value); + template <typename U> + Array& operator=(const U& that); + using ArrayType::push_back; + template <typename U> + void push_back(const U& value); + Json::Value ToJsonValue() const; + void ToDbusWriter(dbus::MessageWriter* writer) const; + + bool is_valid() const; + bool is_initialized() const; + void ReportErrors(ValidationReport* report) const; + virtual void SetPolicyTableType( + policy_table_interface_base::PolicyTableType pt_type); }; -template<typename T, size_t minsize, size_t maxsize> -class Map : public std::map<std::string, T>, public CompositeType { - public: - // Types - typedef Map<T, minsize, maxsize> Frankenbase; - typedef std::map<std::string, T> MapType; - public: - // Methods - Map(); - // Need const and non-const versions to beat all-type accepting constructor - explicit Map(Json::Value* value); - explicit Map(const Json::Value* value); - explicit Map(dbus::MessageReader* reader); - template<typename U> - explicit Map(const U& value); - template<typename U> - Map& operator=(const U& that); - using MapType::insert; - template<typename U> - void insert(const std::pair<std::string, U>& value); - Json::Value ToJsonValue() const; - void ToDbusWriter(dbus::MessageWriter* writer) const; - - bool is_valid() const; - bool is_initialized() const; - void ReportErrors(ValidationReport* report) const; - virtual void SetPolicyTableType(policy_table_interface_base::PolicyTableType pt_type); +template <typename T, size_t minsize, size_t maxsize> +class Map : public std::map<std::string, T>, public CompositeType { + public: + // Types + typedef Map<T, minsize, maxsize> Frankenbase; + typedef std::map<std::string, T> MapType; + + public: + // Methods + Map(); + // Need const and non-const versions to beat all-type accepting constructor + explicit Map(Json::Value* value); + explicit Map(const Json::Value* value); + explicit Map(dbus::MessageReader* reader); + template <typename U> + explicit Map(const U& value); + template <typename U> + Map& operator=(const U& that); + using MapType::insert; + template <typename U> + void insert(const std::pair<std::string, U>& value); + Json::Value ToJsonValue() const; + void ToDbusWriter(dbus::MessageWriter* writer) const; + + bool is_valid() const; + bool is_initialized() const; + void ReportErrors(ValidationReport* report) const; + virtual void SetPolicyTableType( + policy_table_interface_base::PolicyTableType pt_type); }; -template<typename T> +template <typename T> class Nullable : public T { - public: - // Methods - Nullable(); - explicit Nullable(dbus::MessageReader* reader); - // Need const and non-const versions to beat all-type accepting constructor - explicit Nullable(Json::Value* value); - explicit Nullable(const Json::Value* value); - template<typename U> - explicit Nullable(const U& value); - template<typename U> - Nullable(const Json::Value* value, const U& def_value); - template<typename U> - Nullable& operator=(const U& new_val); - Json::Value ToJsonValue() const; - - bool is_valid() const; - bool is_initialized() const; - bool is_null() const; - void set_to_null(); - void ReportErrors(ValidationReport* report) const; - private: - bool marked_null_; + public: + // Methods + Nullable(); + explicit Nullable(dbus::MessageReader* reader); + // Need const and non-const versions to beat all-type accepting constructor + explicit Nullable(Json::Value* value); + explicit Nullable(const Json::Value* value); + template <typename U> + explicit Nullable(const U& value); + template <typename U> + Nullable(const Json::Value* value, const U& def_value); + template <typename U> + Nullable& operator=(const U& new_val); + Json::Value ToJsonValue() const; + + bool is_valid() const; + bool is_initialized() const; + bool is_null() const; + void set_to_null(); + void ReportErrors(ValidationReport* report) const; + + private: + bool marked_null_; }; -template<typename T> +template <typename T> class Stringifyable : public T { - public: - // Methods - Stringifyable(); - explicit Stringifyable(dbus::MessageReader* reader); - // Need const and non-const versions to beat all-type accepting constructor - explicit Stringifyable(Json::Value* value); - explicit Stringifyable(const Json::Value* value); - template<typename U> - explicit Stringifyable(const U& value); - template<typename U> - Stringifyable(const Json::Value* value, const U& def_value); - template<typename U> - Stringifyable& operator=(const U& new_val); - Json::Value ToJsonValue() const; - - bool is_valid() const; - bool is_initialized() const; - bool is_string() const; - std::string get_string() const; - void set_to_string(const std::string& input); - void ReportErrors(ValidationReport* report) const; - private: - std::string predefined_string_; + public: + // Methods + Stringifyable(); + explicit Stringifyable(dbus::MessageReader* reader); + // Need const and non-const versions to beat all-type accepting constructor + explicit Stringifyable(Json::Value* value); + explicit Stringifyable(const Json::Value* value); + template <typename U> + explicit Stringifyable(const U& value); + template <typename U> + Stringifyable(const Json::Value* value, const U& def_value); + template <typename U> + Stringifyable& operator=(const U& new_val); + Json::Value ToJsonValue() const; + + bool is_valid() const; + bool is_initialized() const; + bool is_string() const; + std::string get_string() const; + void set_to_string(const std::string& input); + void ReportErrors(ValidationReport* report) const; + + private: + std::string predefined_string_; }; -template<typename T> +template <typename T> class Optional { - public: - // Methods - Optional(); - explicit Optional(dbus::MessageReader* reader); - template<typename U> - explicit Optional(const U& value); - template<typename U> - Optional(const Json::Value* value, const U& def_value); - Json::Value ToJsonValue() const; - - void ToDbusWriter(dbus::MessageWriter* writer) const; - - // Pointer semantics - T& operator*(); - const T& operator*() const; - T* operator->(); - const T* operator->() const; - - void assign_if_valid(const Optional<T>& value); - // For pointer-like 'if (optional_value)' tests - // Better than operator bool because bool can be implicitly - // casted to integral types - operator const void* () const; - - bool is_valid() const; - bool is_initialized() const; - void ReportErrors(ValidationReport* report) const; - policy_table_interface_base::PolicyTableType GetPolicyTableType() const; - virtual void SetPolicyTableType(policy_table_interface_base::PolicyTableType pt_type); - - protected: - policy_table_interface_base::PolicyTableType policy_table_type_; - private: - T value_; + public: + // Methods + Optional(); + explicit Optional(dbus::MessageReader* reader); + template <typename U> + explicit Optional(const U& value); + template <typename U> + Optional(const Json::Value* value, const U& def_value); + Json::Value ToJsonValue() const; + + void ToDbusWriter(dbus::MessageWriter* writer) const; + + // Pointer semantics + T& operator*(); + const T& operator*() const; + T* operator->(); + const T* operator->() const; + + void assign_if_valid(const Optional<T>& value); + // For pointer-like 'if (optional_value)' tests + // Better than operator bool because bool can be implicitly + // casted to integral types + operator const void*() const; + + bool is_valid() const; + bool is_initialized() const; + void ReportErrors(ValidationReport* report) const; + policy_table_interface_base::PolicyTableType GetPolicyTableType() const; + virtual void SetPolicyTableType( + policy_table_interface_base::PolicyTableType pt_type); + + protected: + policy_table_interface_base::PolicyTableType policy_table_type_; + + private: + T value_; }; } // namespace rpc diff --git a/src/components/rpc_base/include/rpc_base/rpc_base_dbus_inl.h b/src/components/rpc_base/include/rpc_base/rpc_base_dbus_inl.h index 5f9c45a060..2b968dd034 100644 --- a/src/components/rpc_base/include/rpc_base/rpc_base_dbus_inl.h +++ b/src/components/rpc_base/include/rpc_base/rpc_base_dbus_inl.h @@ -45,28 +45,32 @@ inline PrimitiveType::ValueState PrimitiveType::InitHelper(bool is_next) { } // static -inline CompositeType::InitializationState CompositeType::InitHelper(bool is_next) { +inline CompositeType::InitializationState CompositeType::InitHelper( + bool is_next) { return is_next ? kInitialized : kUninitialized; } namespace impl { - // Helper functions to statically map int types to appropriate // MessageReader functions // Non-specialized versions doesn't have implementation // Tells if next element of reader is of type T -template<typename T> inline bool NextIs(const dbus::MessageReader& reader); +template <typename T> +inline bool NextIs(const dbus::MessageReader& reader); // Takes next element of type T from reader -template<typename T> inline T Take(dbus::MessageReader* reader); +template <typename T> +inline T Take(dbus::MessageReader* reader); -template<> inline bool NextIs<int8_t>(const dbus::MessageReader& reader) { +template <> +inline bool NextIs<int8_t>(const dbus::MessageReader& reader) { return reader.NextIsByte(); } -template<> inline int8_t Take<int8_t>(dbus::MessageReader* reader) { +template <> +inline int8_t Take<int8_t>(dbus::MessageReader* reader) { return static_cast<int8_t>(reader->TakeByte()); } @@ -74,11 +78,13 @@ inline void Put(int8_t val, dbus::MessageWriter* writer) { writer->PutByte(static_cast<uint8_t>(val)); } -template<> inline bool NextIs<uint8_t>(const dbus::MessageReader& reader) { +template <> +inline bool NextIs<uint8_t>(const dbus::MessageReader& reader) { return reader.NextIsByte(); } -template<> inline uint8_t Take<uint8_t>(dbus::MessageReader* reader) { +template <> +inline uint8_t Take<uint8_t>(dbus::MessageReader* reader) { return reader->TakeByte(); } @@ -86,11 +92,13 @@ inline void Put(uint8_t val, dbus::MessageWriter* writer) { writer->PutByte(val); } -template<> inline bool NextIs<int16_t>(const dbus::MessageReader& reader) { +template <> +inline bool NextIs<int16_t>(const dbus::MessageReader& reader) { return reader.NextIsInt16(); } -template<> inline int16_t Take<int16_t>(dbus::MessageReader* reader) { +template <> +inline int16_t Take<int16_t>(dbus::MessageReader* reader) { return reader->TakeInt16(); } @@ -98,11 +106,13 @@ inline void Put(int16_t val, dbus::MessageWriter* writer) { writer->PutInt16(val); } -template<> inline bool NextIs<uint16_t>(const dbus::MessageReader& reader) { +template <> +inline bool NextIs<uint16_t>(const dbus::MessageReader& reader) { return reader.NextIsUint16(); } -template<> inline uint16_t Take<uint16_t>(dbus::MessageReader* reader) { +template <> +inline uint16_t Take<uint16_t>(dbus::MessageReader* reader) { return reader->TakeUint16(); } @@ -110,11 +120,13 @@ inline void Put(uint16_t val, dbus::MessageWriter* writer) { writer->PutUint16(val); } -template<> inline bool NextIs<int32_t>(const dbus::MessageReader& reader) { +template <> +inline bool NextIs<int32_t>(const dbus::MessageReader& reader) { return reader.NextIsInt32(); } -template<> inline int32_t Take<int32_t>(dbus::MessageReader* reader) { +template <> +inline int32_t Take<int32_t>(dbus::MessageReader* reader) { return reader->TakeInt32(); } @@ -122,11 +134,13 @@ inline void Put(int32_t val, dbus::MessageWriter* writer) { writer->PutInt32(val); } -template<> inline bool NextIs<uint32_t>(const dbus::MessageReader& reader) { +template <> +inline bool NextIs<uint32_t>(const dbus::MessageReader& reader) { return reader.NextIsUint32(); } -template<> inline uint32_t Take<uint32_t>(dbus::MessageReader* reader) { +template <> +inline uint32_t Take<uint32_t>(dbus::MessageReader* reader) { return reader->TakeUint32(); } @@ -134,11 +148,13 @@ inline void Put(uint32_t val, dbus::MessageWriter* writer) { writer->PutUint32(val); } -template<> inline bool NextIs<int64_t>(const dbus::MessageReader& reader) { +template <> +inline bool NextIs<int64_t>(const dbus::MessageReader& reader) { return reader.NextIsInt64(); } -template<> inline int64_t Take<int64_t>(dbus::MessageReader* reader) { +template <> +inline int64_t Take<int64_t>(dbus::MessageReader* reader) { return reader->TakeInt64(); } @@ -146,11 +162,13 @@ inline void Put(int64_t val, dbus::MessageWriter* writer) { writer->PutInt64(val); } -template<> inline bool NextIs<uint64_t>(const dbus::MessageReader& reader) { +template <> +inline bool NextIs<uint64_t>(const dbus::MessageReader& reader) { return reader.NextIsUint64(); } -template<> inline uint64_t Take<uint64_t>(dbus::MessageReader* reader) { +template <> +inline uint64_t Take<uint64_t>(dbus::MessageReader* reader) { return reader->TakeUint64(); } @@ -158,7 +176,8 @@ inline void Put(uint64_t val, dbus::MessageWriter* writer) { writer->PutUint64(val); } -template<> inline std::string Take<std::string>(dbus::MessageReader* reader) { +template <> +inline std::string Take<std::string>(dbus::MessageReader* reader) { return reader->TakeString(); } @@ -167,66 +186,103 @@ inline void Put(const std::string val, dbus::MessageWriter* writer) { } // Type to DBus type id mappers -template<typename T> char DbusTypeCode(); -template<> inline char DbusTypeCode<bool>() { return DBUS_TYPE_BOOLEAN; } +template <typename T> +char DbusTypeCode(); +template <> +inline char DbusTypeCode<bool>() { + return DBUS_TYPE_BOOLEAN; +} // There is no dbus type for signed byte, map to unsigned -template<> inline char DbusTypeCode<int8_t>() { return DBUS_TYPE_BYTE; } -template<> inline char DbusTypeCode<uint8_t>() { return DBUS_TYPE_BYTE; } -template<> inline char DbusTypeCode<int16_t>() { return DBUS_TYPE_INT16; } -template<> inline char DbusTypeCode<uint16_t>() { return DBUS_TYPE_UINT16; } -template<> inline char DbusTypeCode<int32_t>() { return DBUS_TYPE_INT32; } -template<> inline char DbusTypeCode<uint32_t>() { return DBUS_TYPE_UINT32; } -template<> inline char DbusTypeCode<int64_t>() { return DBUS_TYPE_INT64; } -template<> inline char DbusTypeCode<uint64_t>() { return DBUS_TYPE_UINT64; } -template<> inline char DbusTypeCode<double>() { return DBUS_TYPE_DOUBLE; } -template<> inline char DbusTypeCode<std::string>() { return DBUS_TYPE_STRING; } -template<> inline char DbusTypeCode<const std::string>() { return DBUS_TYPE_STRING; } +template <> +inline char DbusTypeCode<int8_t>() { + return DBUS_TYPE_BYTE; +} +template <> +inline char DbusTypeCode<uint8_t>() { + return DBUS_TYPE_BYTE; +} +template <> +inline char DbusTypeCode<int16_t>() { + return DBUS_TYPE_INT16; +} +template <> +inline char DbusTypeCode<uint16_t>() { + return DBUS_TYPE_UINT16; +} +template <> +inline char DbusTypeCode<int32_t>() { + return DBUS_TYPE_INT32; +} +template <> +inline char DbusTypeCode<uint32_t>() { + return DBUS_TYPE_UINT32; +} +template <> +inline char DbusTypeCode<int64_t>() { + return DBUS_TYPE_INT64; +} +template <> +inline char DbusTypeCode<uint64_t>() { + return DBUS_TYPE_UINT64; +} +template <> +inline char DbusTypeCode<double>() { + return DBUS_TYPE_DOUBLE; +} +template <> +inline char DbusTypeCode<std::string>() { + return DBUS_TYPE_STRING; +} +template <> +inline char DbusTypeCode<const std::string>() { + return DBUS_TYPE_STRING; +} // Non-specialized template supposes there is static // void GetDbusSignature(std::string*) method in T -template<typename T> +template <typename T> struct DbusSignatureHelper { static void DbusSignature(std::string* signature) { T::GetDbusSignature(signature); } }; -template<> +template <> struct DbusSignatureHelper<Boolean> { static void DbusSignature(std::string* signature) { (*signature) += rpc::impl::DbusTypeCode<bool>(); } }; -template<typename T, T minval, T maxval> +template <typename T, T minval, T maxval> struct DbusSignatureHelper<Integer<T, minval, maxval> > { static void DbusSignature(std::string* signature) { (*signature) += rpc::impl::DbusTypeCode<T>(); } }; -template<int64_t minnum, int64_t maxnum, int64_t minden, int64_t maxden> +template <int64_t minnum, int64_t maxnum, int64_t minden, int64_t maxden> struct DbusSignatureHelper<Float<minnum, maxnum, minden, maxden> > { static void DbusSignature(std::string* signature) { (*signature) += rpc::impl::DbusTypeCode<double>(); } }; -template<typename T> +template <typename T> struct DbusSignatureHelper<Enum<T> > { static void DbusSignature(std::string* signature) { (*signature) += rpc::impl::DbusTypeCode<int32_t>(); } }; -template<size_t minlen, size_t maxlen> +template <size_t minlen, size_t maxlen> struct DbusSignatureHelper<String<minlen, maxlen> > { static void DbusSignature(std::string* signature) { (*signature) += rpc::impl::DbusTypeCode<std::string>(); } }; -template<typename K, typename V> +template <typename K, typename V> struct DbusSignatureHelper<std::pair<K, V> > { static void DbusSignature(std::string* signature) { (*signature) += DBUS_DICT_ENTRY_BEGIN_CHAR; @@ -236,7 +292,7 @@ struct DbusSignatureHelper<std::pair<K, V> > { } }; -template<typename T, size_t minsize, size_t maxsize> +template <typename T, size_t minsize, size_t maxsize> struct DbusSignatureHelper<Array<T, minsize, maxsize> > { static void DbusSignature(std::string* signature) { (*signature) += DBUS_TYPE_ARRAY; @@ -244,16 +300,16 @@ struct DbusSignatureHelper<Array<T, minsize, maxsize> > { } }; -template<typename T, size_t minsize, size_t maxsize> +template <typename T, size_t minsize, size_t maxsize> struct DbusSignatureHelper<Map<T, minsize, maxsize> > { static void DbusSignature(std::string* signature) { (*signature) += DBUS_TYPE_ARRAY; - rpc::impl::DbusSignatureHelper< - typename Map<T, minsize, maxsize>::value_type>::DbusSignature(signature); + rpc::impl::DbusSignatureHelper<typename Map<T, minsize, maxsize>:: + value_type>::DbusSignature(signature); } }; -template<typename T> +template <typename T> struct DbusSignatureHelper<Optional<T> > { static void DbusSignature(std::string* signature) { (*signature) += DBUS_STRUCT_BEGIN_CHAR; @@ -263,7 +319,7 @@ struct DbusSignatureHelper<Optional<T> > { } }; -template<typename T> +template <typename T> struct DbusSignatureHelper<Nullable<T> > { static void DbusSignature(std::string* signature) { (*signature) += DBUS_STRUCT_BEGIN_CHAR; @@ -274,7 +330,7 @@ struct DbusSignatureHelper<Nullable<T> > { }; // Helper Optional type initialization functipon -template<typename T> +template <typename T> T TakeOptional(dbus::MessageReader* reader) { dbus::MessageReader struct_reader = reader->TakeStructReader(); bool available = struct_reader.TakeBool(); @@ -283,7 +339,7 @@ T TakeOptional(dbus::MessageReader* reader) { } // Helper Nullable type initialization functipon -template<typename T> +template <typename T> bool TakeNullable(dbus::MessageReader* reader) { dbus::MessageReader struct_reader = reader->TakeStructReader(); bool is_null = struct_reader.TakeBool(); @@ -292,69 +348,67 @@ bool TakeNullable(dbus::MessageReader* reader) { } // namespace impl - // Helper function that outputs dbus signature for type T -template<typename T> +template <typename T> void DbusSignature(std::string* signature) { impl::DbusSignatureHelper<T>::DbusSignature(signature); } // Type constructors inline Boolean::Boolean(dbus::MessageReader* reader) - : PrimitiveType(InitHelper(reader->NextIsBool())), - value_(reader->TakeBool()) { -} + : PrimitiveType(InitHelper(reader->NextIsBool())) + , value_(reader->TakeBool()) {} -template<typename T, T minval, T maxval> +template <typename T, T minval, T maxval> inline Integer<T, minval, maxval>::Integer(dbus::MessageReader* reader) - : PrimitiveType(InitHelper(impl::NextIs<IntType>(*reader))), - value_(impl::Take<IntType>(reader)) { + : PrimitiveType(InitHelper(impl::NextIs<IntType>(*reader))) + , value_(impl::Take<IntType>(reader)) { if (is_valid()) { value_state_ = range_.Includes(value_) ? kValid : kInvalid; } } -template<int64_t minnum, int64_t maxnum, int64_t minden, int64_t maxden> +template <int64_t minnum, int64_t maxnum, int64_t minden, int64_t maxden> inline Float<minnum, maxnum, minden, maxden>::Float(dbus::MessageReader* reader) - : PrimitiveType(InitHelper(reader->NextIsDouble())), - value_(reader->TakeDouble()) { + : PrimitiveType(InitHelper(reader->NextIsDouble())) + , value_(reader->TakeDouble()) { if (is_valid()) { value_state_ = range_.Includes(value_) ? kValid : kInvalid; } } -template<size_t minlen, size_t maxlen> +template <size_t minlen, size_t maxlen> inline String<minlen, maxlen>::String(dbus::MessageReader* reader) - : PrimitiveType(InitHelper(reader->NextIsString())), - value_(reader->TakeString()) { + : PrimitiveType(InitHelper(reader->NextIsString())) + , value_(reader->TakeString()) { if (is_valid()) { value_state_ = length_range_.Includes(value_.length()) ? kValid : kInvalid; } } -template<typename T> +template <typename T> inline Enum<T>::Enum(dbus::MessageReader* reader) - : PrimitiveType(InitHelper(reader->NextIsInt32())), - value_(EnumType(reader->TakeInt32())) { + : PrimitiveType(InitHelper(reader->NextIsInt32())) + , value_(EnumType(reader->TakeInt32())) { if (is_valid()) { value_state_ = IsValidEnum(value_) ? kValid : kInvalid; } } -template<typename T, size_t minsize, size_t maxsize> +template <typename T, size_t minsize, size_t maxsize> inline Array<T, minsize, maxsize>::Array(dbus::MessageReader* reader) : CompositeType(InitHelper(reader->NextIsArray())) { dbus::MessageReader array_reader = reader->TakeArrayReader(); if (array_reader.has_failed()) { push_back(T()); } else { - while(array_reader.HasNext()) { + while (array_reader.HasNext()) { push_back(T(&array_reader)); } } } -template<typename T, size_t minsize, size_t maxsize> +template <typename T, size_t minsize, size_t maxsize> inline Map<T, minsize, maxsize>::Map(dbus::MessageReader* reader) : CompositeType(InitHelper(reader->NextIsStruct())) { // Map key-value pairs are serialized into array @@ -362,7 +416,7 @@ inline Map<T, minsize, maxsize>::Map(dbus::MessageReader* reader) if (array_reader.has_failed()) { this->insert(typename MapType::value_type("", T())); } else { - while(array_reader.HasNext()) { + while (array_reader.HasNext()) { dbus::MessageReader dictvalue_reader = array_reader.TakeDictEntryReader(); typename MapType::key_type key = impl::Take<typename MapType::key_type>(&dictvalue_reader); @@ -371,64 +425,62 @@ inline Map<T, minsize, maxsize>::Map(dbus::MessageReader* reader) } } -template<typename T> +template <typename T> inline Nullable<T>::Nullable(dbus::MessageReader* reader) - : T(reader), - marked_null_(impl::TakeNullable<T>(reader)){ -} + : T(reader), marked_null_(impl::TakeNullable<T>(reader)) {} -template<typename T> +template <typename T> inline Optional<T>::Optional(dbus::MessageReader* reader) - : value_(impl::TakeOptional<T>(reader)){ -} + : value_(impl::TakeOptional<T>(reader)) {} // MessageWriter serializers inline void Boolean::ToDbusWriter(dbus::MessageWriter* writer) const { writer->PutBool(value_); } -template<typename T, T minval, T maxval> +template <typename T, T minval, T maxval> inline void Integer<T, minval, maxval>::ToDbusWriter( dbus::MessageWriter* writer) const { impl::Put(value_, writer); } -template<int64_t minnum, int64_t maxnum, int64_t minden, int64_t maxden> +template <int64_t minnum, int64_t maxnum, int64_t minden, int64_t maxden> inline void Float<minnum, maxnum, minden, maxden>::ToDbusWriter( dbus::MessageWriter* writer) const { writer->PutDouble(value_); } -template<size_t minlen, size_t maxlen> +template <size_t minlen, size_t maxlen> inline void String<minlen, maxlen>::ToDbusWriter( dbus::MessageWriter* writer) const { writer->PutString(value_); } -template<typename T> +template <typename T> inline void Enum<T>::ToDbusWriter(dbus::MessageWriter* writer) const { writer->PutInt32(static_cast<int32_t>(value_)); } -template<typename T, size_t minsize, size_t maxsize> +template <typename T, size_t minsize, size_t maxsize> inline void Array<T, minsize, maxsize>::ToDbusWriter( dbus::MessageWriter* writer) const { std::string array_signature; DbusSignature<typename ArrayType::value_type>(&array_signature); - dbus::MessageWriter array_writer(writer, dbus::kArray, - array_signature.c_str()); - for (typename ArrayType::const_iterator i = this->begin(); i != this->end(); ++i) { + dbus::MessageWriter array_writer( + writer, dbus::kArray, array_signature.c_str()); + for (typename ArrayType::const_iterator i = this->begin(); i != this->end(); + ++i) { i->ToDbusWriter(&array_writer); } } -template<typename T, size_t minsize, size_t maxsize> +template <typename T, size_t minsize, size_t maxsize> inline void Map<T, minsize, maxsize>::ToDbusWriter( dbus::MessageWriter* writer) const { std::string array_signature; DbusSignature<typename MapType::value_type>(&array_signature); - dbus::MessageWriter array_writer(writer, dbus::kArray, - array_signature.c_str()); + dbus::MessageWriter array_writer( + writer, dbus::kArray, array_signature.c_str()); for (typename MapType::const_iterator i = this->begin(); i != this->end(); ++i) { dbus::MessageWriter dictentry_writer(&array_writer, dbus::kDictEntry, NULL); @@ -437,7 +489,7 @@ inline void Map<T, minsize, maxsize>::ToDbusWriter( } } -template<typename T> +template <typename T> inline void Optional<T>::ToDbusWriter(dbus::MessageWriter* writer) const { dbus::MessageWriter struct_writer(writer, dbus::kStruct, NULL); struct_writer.PutBool(value_.is_initialized()); @@ -446,4 +498,4 @@ inline void Optional<T>::ToDbusWriter(dbus::MessageWriter* writer) const { } // namespace rpc -#endif // RPC_BASE_DBUS_INL_H_ +#endif // RPC_BASE_DBUS_INL_H_ diff --git a/src/components/rpc_base/include/rpc_base/rpc_base_inl.h b/src/components/rpc_base/include/rpc_base/rpc_base_inl.h index eb374188c3..a9ff484eb0 100644 --- a/src/components/rpc_base/include/rpc_base/rpc_base_inl.h +++ b/src/components/rpc_base/include/rpc_base/rpc_base_inl.h @@ -47,9 +47,7 @@ namespace rpc { */ template <typename T> Range<T>::Range(T min, T max) - : min_(min), - max_(max) { -} + : min_(min), max_(max) {} template <typename T> T Range<T>::min() const { @@ -67,14 +65,12 @@ bool Range<T>::Includes(U val) const { return min() <= val && val <= max(); } - /* * PrimitiveType base class */ inline PrimitiveType::PrimitiveType(ValueState value_state) - : value_state_(value_state), - policy_table_type_(policy_table_interface_base::PT_PRELOADED) { -} + : value_state_(value_state) + , policy_table_type_(policy_table_interface_base::PT_PRELOADED) {} inline bool PrimitiveType::is_initialized() const { return value_state_ != kUninitialized; @@ -113,9 +109,8 @@ inline void CompositeType::mark_initialized() { } inline CompositeType::CompositeType(InitializationState init_state) - : initialization_state__(init_state), - policy_table_type_(policy_table_interface_base::PT_PRELOADED) { -} + : initialization_state__(init_state) + , policy_table_type_(policy_table_interface_base::PT_PRELOADED) {} inline void CompositeType::ReportErrors(ValidationReport* report) const { switch (initialization_state__) { @@ -140,14 +135,9 @@ inline void CompositeType::ReportErrors(ValidationReport* report) const { /* * Boolean class */ -inline Boolean::Boolean() - : PrimitiveType(kUninitialized), - value_(false) { -} +inline Boolean::Boolean() : PrimitiveType(kUninitialized), value_(false) {} -inline Boolean::Boolean(bool value) - : PrimitiveType(kValid), value_(value) { -} +inline Boolean::Boolean(bool value) : PrimitiveType(kValid), value_(value) {} inline Boolean& Boolean::operator=(bool new_val) { value_ = new_val; @@ -162,51 +152,50 @@ inline Boolean::operator bool() const { /* * Integer class */ -template<typename T, T minval, T maxval> +template <typename T, T minval, T maxval> const Range<T> Integer<T, minval, maxval>::range_(minval, maxval); -template<typename T, T minval, T maxval> +template <typename T, T minval, T maxval> Integer<T, minval, maxval>::Integer() - : PrimitiveType(kUninitialized), - value_(range_.min()) { -} + : PrimitiveType(kUninitialized), value_(range_.min()) {} -template<typename T, T minval, T maxval> +template <typename T, T minval, T maxval> Integer<T, minval, maxval>::Integer(IntType value) - : PrimitiveType(range_.Includes(value) ? kValid : kInvalid), - value_(value) { -} + : PrimitiveType(range_.Includes(value) ? kValid : kInvalid) + , value_(value) {} -template<typename T, T minval, T maxval> -Integer<T, minval, maxval>& Integer<T, minval, maxval>::operator=(IntType new_val) { +template <typename T, T minval, T maxval> +Integer<T, minval, maxval>& Integer<T, minval, maxval>::operator=( + IntType new_val) { value_ = new_val; value_state_ = range_.Includes(value_) ? kValid : kInvalid; return *this; } -template<typename T, T minval, T maxval> -Integer<T, minval, maxval>& Integer<T, minval, maxval>::operator=(const Integer& new_val) { +template <typename T, T minval, T maxval> +Integer<T, minval, maxval>& Integer<T, minval, maxval>::operator=( + const Integer& new_val) { this->value_ = new_val.value_; if (new_val.is_initialized()) { - this->value_state_= range_.Includes(new_val.value_) ? kValid : kInvalid; + this->value_state_ = range_.Includes(new_val.value_) ? kValid : kInvalid; } return *this; } -template<typename T, T minval, T maxval> +template <typename T, T minval, T maxval> Integer<T, minval, maxval>& Integer<T, minval, maxval>::operator++() { ++value_; return *this; } -template<typename T, T minval, T maxval> +template <typename T, T minval, T maxval> Integer<T, minval, maxval>& Integer<T, minval, maxval>::operator+=(int value) { value_ += value; return *this; } -template<typename T, T minval, T maxval> +template <typename T, T minval, T maxval> Integer<T, minval, maxval>::operator IntType() const { return value_; } @@ -214,32 +203,28 @@ Integer<T, minval, maxval>::operator IntType() const { /* * Float class */ -template<int64_t minnum, int64_t maxnum, int64_t minden, int64_t maxden> +template <int64_t minnum, int64_t maxnum, int64_t minden, int64_t maxden> const Range<double> Float<minnum, maxnum, minden, maxden>::range_( - (double(minnum)/minden), (double(maxnum)/maxden)); + (double(minnum) / minden), (double(maxnum) / maxden)); - -template<int64_t minnum, int64_t maxnum, int64_t minden, int64_t maxden> +template <int64_t minnum, int64_t maxnum, int64_t minden, int64_t maxden> Float<minnum, maxnum, minden, maxden>::Float() - : PrimitiveType(kUninitialized), - value_(range_.min()) { -} + : PrimitiveType(kUninitialized), value_(range_.min()) {} -template<int64_t minnum, int64_t maxnum, int64_t minden, int64_t maxden> +template <int64_t minnum, int64_t maxnum, int64_t minden, int64_t maxden> Float<minnum, maxnum, minden, maxden>::Float(double value) - : PrimitiveType(range_.Includes(value) ? kValid : kInvalid), - value_(value) { -} + : PrimitiveType(range_.Includes(value) ? kValid : kInvalid) + , value_(value) {} -template<int64_t minnum, int64_t maxnum, int64_t minden, int64_t maxden> -Float<minnum, maxnum, minden, maxden>& -Float<minnum, maxnum, minden, maxden>::operator=(double new_val) { +template <int64_t minnum, int64_t maxnum, int64_t minden, int64_t maxden> +Float<minnum, maxnum, minden, maxden>& Float<minnum, maxnum, minden, maxden>:: +operator=(double new_val) { value_ = new_val; value_state_ = range_.Includes(new_val) ? kValid : kInvalid; return *this; } -template<int64_t minnum, int64_t maxnum, int64_t minden, int64_t maxden> +template <int64_t minnum, int64_t maxnum, int64_t minden, int64_t maxden> Float<minnum, maxnum, minden, maxden>::operator double() const { return value_; } @@ -247,42 +232,41 @@ Float<minnum, maxnum, minden, maxden>::operator double() const { /* * String class */ -template<size_t minlen, size_t maxlen> +template <size_t minlen, size_t maxlen> const Range<size_t> String<minlen, maxlen>::length_range_(minlen, maxlen); -template<size_t minlen, size_t maxlen> +template <size_t minlen, size_t maxlen> String<minlen, maxlen>::String() - : PrimitiveType(kUninitialized) { -} + : PrimitiveType(kUninitialized) {} -template<size_t minlen, size_t maxlen> +template <size_t minlen, size_t maxlen> String<minlen, maxlen>::String(const std::string& value) - : PrimitiveType(length_range_.Includes(value.length()) ? kValid : kInvalid), - value_(value) { -} + : PrimitiveType(length_range_.Includes(value.length()) ? kValid : kInvalid) + , value_(value) {} -template<size_t minlen, size_t maxlen> +template <size_t minlen, size_t maxlen> String<minlen, maxlen>::String(const char* value) - : PrimitiveType(kUninitialized), - value_(value) { + : PrimitiveType(kUninitialized), value_(value) { value_state_ = length_range_.Includes(value_.length()) ? kValid : kInvalid; } -template<size_t minlen, size_t maxlen> +template <size_t minlen, size_t maxlen> bool String<minlen, maxlen>::operator<(const String& new_val) const { return value_ < new_val.value_; } -template<size_t minlen, size_t maxlen> -String<minlen, maxlen>& String<minlen, maxlen>::operator=(const std::string& new_val) { +template <size_t minlen, size_t maxlen> +String<minlen, maxlen>& String<minlen, maxlen>::operator=( + const std::string& new_val) { value_ = new_val; value_state_ = length_range_.Includes(new_val.length()) ? kValid : kInvalid; return *this; } -template<size_t minlen, size_t maxlen> -String<minlen, maxlen>& String<minlen, maxlen>::operator=(const String& new_val) { - if(*this == new_val) { +template <size_t minlen, size_t maxlen> +String<minlen, maxlen>& String<minlen, maxlen>::operator=( + const String& new_val) { + if (*this == new_val) { return *this; } value_.assign(new_val.value_); @@ -290,12 +274,12 @@ String<minlen, maxlen>& String<minlen, maxlen>::operator=(const String& new_val) return *this; } -template<size_t minlen, size_t maxlen> +template <size_t minlen, size_t maxlen> bool String<minlen, maxlen>::operator==(const String& rhs) const { return value_ == rhs.value_; } -template<size_t minlen, size_t maxlen> +template <size_t minlen, size_t maxlen> String<minlen, maxlen>::operator const std::string&() const { return value_; } @@ -303,26 +287,22 @@ String<minlen, maxlen>::operator const std::string&() const { /* * Enum class */ -template<typename T> +template <typename T> Enum<T>::Enum() - : PrimitiveType(kUninitialized), - value_(EnumType()) { -} + : PrimitiveType(kUninitialized), value_(EnumType()) {} -template<typename T> +template <typename T> Enum<T>::Enum(EnumType value) - : PrimitiveType(IsValidEnum(value) ? kValid : kInvalid), - value_(value) { -} + : PrimitiveType(IsValidEnum(value) ? kValid : kInvalid), value_(value) {} -template<typename T> +template <typename T> Enum<T>& Enum<T>::operator=(const EnumType& new_val) { value_ = new_val; value_state_ = IsValidEnum(value_) ? kValid : kInvalid; return *this; } -template<typename T> +template <typename T> Enum<T>::operator EnumType() const { return value_; } @@ -330,33 +310,30 @@ Enum<T>::operator EnumType() const { /* * Array class */ -template<typename T, size_t minsize, size_t maxsize> +template <typename T, size_t minsize, size_t maxsize> Array<T, minsize, maxsize>::Array() - : CompositeType(kUninitialized) { -} + : CompositeType(kUninitialized) {} -template<typename T, size_t minsize, size_t maxsize> -template<typename U> +template <typename T, size_t minsize, size_t maxsize> +template <typename U> Array<T, minsize, maxsize>::Array(const U& value) - : ArrayType(value.begin(), value.end()), - CompositeType(kUninitialized) { -} + : ArrayType(value.begin(), value.end()), CompositeType(kUninitialized) {} -template<typename T, size_t minsize, size_t maxsize> -template<typename U> -Array<T, minsize, maxsize>& -Array<T, minsize, maxsize>::operator=(const U& that) { +template <typename T, size_t minsize, size_t maxsize> +template <typename U> +Array<T, minsize, maxsize>& Array<T, minsize, maxsize>::operator=( + const U& that) { this->assign(that.begin(), that.end()); return *this; } -template<typename T, size_t minsize, size_t maxsize> -template<typename U> +template <typename T, size_t minsize, size_t maxsize> +template <typename U> void Array<T, minsize, maxsize>::push_back(const U& value) { ArrayType::push_back(T(value)); } -template<typename T, size_t minsize, size_t maxsize> +template <typename T, size_t minsize, size_t maxsize> bool Array<T, minsize, maxsize>::is_valid() const { // Empty array might be valid only if marked initialized if (this->empty() && (initialization_state__ != kInitialized)) { @@ -367,8 +344,8 @@ bool Array<T, minsize, maxsize>::is_valid() const { return false; } // All array elements must be valid - for (typename ArrayType::const_iterator i = this->begin(); - i != this->end(); ++i) { + for (typename ArrayType::const_iterator i = this->begin(); i != this->end(); + ++i) { if (!i->is_valid()) { return false; } @@ -376,7 +353,7 @@ bool Array<T, minsize, maxsize>::is_valid() const { return true; } -template<typename T, size_t minsize, size_t maxsize> +template <typename T, size_t minsize, size_t maxsize> bool Array<T, minsize, maxsize>::is_initialized() const { // Array that is not empty is initialized for sure if (!this->empty()) { @@ -389,7 +366,7 @@ bool Array<T, minsize, maxsize>::is_initialized() const { return false; } -template<typename T, size_t minsize, size_t maxsize> +template <typename T, size_t minsize, size_t maxsize> void Array<T, minsize, maxsize>::ReportErrors(ValidationReport* report) const { if (this->empty()) { CompositeType::ReportErrors(report); @@ -401,54 +378,50 @@ void Array<T, minsize, maxsize>::ReportErrors(ValidationReport* report) const { } } for (size_t i = 0; i != this->size(); ++i) { - const T& elem = this->operator [](i); + const T& elem = this->operator[](i); if (!elem.is_valid()) { char elem_idx[32] = {}; snprintf(elem_idx, 32, "[%zu]", i); - ValidationReport& elem_report = - report->ReportSubobject(elem_idx); + ValidationReport& elem_report = report->ReportSubobject(elem_idx); elem.ReportErrors(&elem_report); } } } -template<typename T, size_t minsize, size_t maxsize> +template <typename T, size_t minsize, size_t maxsize> void Array<T, minsize, maxsize>::SetPolicyTableType( rpc::policy_table_interface_base::PolicyTableType pt_type) { - - for (typename ArrayType::iterator it = this->begin(); - it != this->end(); ++it) { - it->SetPolicyTableType(pt_type); + for (typename ArrayType::iterator it = this->begin(); it != this->end(); + ++it) { + it->SetPolicyTableType(pt_type); } } /* * Map class */ -template<typename T, size_t minsize, size_t maxsize> +template <typename T, size_t minsize, size_t maxsize> Map<T, minsize, maxsize>::Map() - : CompositeType(kUninitialized) { -} + : CompositeType(kUninitialized) {} -template<typename T, size_t minsize, size_t maxsize> -template<typename U> +template <typename T, size_t minsize, size_t maxsize> +template <typename U> Map<T, minsize, maxsize>::Map(const U& value) : CompositeType(kUninitialized) { for (typename U::const_iterator i = value.begin(), e = value.end(); i != e; - ++i) { + ++i) { // Explicitly convert that value to T because all rpc_types have explicit // constructors insert(typename MapType::value_type(i->first, T(i->second))); } } -template<typename T, size_t minsize, size_t maxsize> -template<typename U> -Map<T, minsize, maxsize>& -Map<T, minsize, maxsize>::operator=(const U& that) { +template <typename T, size_t minsize, size_t maxsize> +template <typename U> +Map<T, minsize, maxsize>& Map<T, minsize, maxsize>::operator=(const U& that) { this->clear(); for (typename U::const_iterator i = that.begin(), e = that.end(); i != e; - ++i) { + ++i) { // Explicitly convert that value to T because all rpc_types have explicit // constructors insert(typename MapType::value_type(i->first, T(i->second))); @@ -456,13 +429,13 @@ Map<T, minsize, maxsize>::operator=(const U& that) { return *this; } -template<typename T, size_t minsize, size_t maxsize> -template<typename U> +template <typename T, size_t minsize, size_t maxsize> +template <typename U> void Map<T, minsize, maxsize>::insert(const std::pair<std::string, U>& value) { MapType::insert(typename MapType::value_type(value.first, T(value.second))); } -template<typename T, size_t minsize, size_t maxsize> +template <typename T, size_t minsize, size_t maxsize> bool Map<T, minsize, maxsize>::is_valid() const { // Empty map might be valid only if marked initialized if (this->empty() && (initialization_state__ != kInitialized)) { @@ -473,8 +446,7 @@ bool Map<T, minsize, maxsize>::is_valid() const { return false; } // All map elements must be valid - for (typename Map::const_iterator i = this->begin(); - i != this->end(); ++i) { + for (typename Map::const_iterator i = this->begin(); i != this->end(); ++i) { if (!i->second.is_valid()) { return false; } @@ -482,7 +454,7 @@ bool Map<T, minsize, maxsize>::is_valid() const { return true; } -template<typename T, size_t minsize, size_t maxsize> +template <typename T, size_t minsize, size_t maxsize> bool Map<T, minsize, maxsize>::is_initialized() const { // Map that is not empty is initialized for sure if (!this->empty()) { @@ -495,7 +467,7 @@ bool Map<T, minsize, maxsize>::is_initialized() const { return false; } -template<typename T, size_t minsize, size_t maxsize> +template <typename T, size_t minsize, size_t maxsize> void Map<T, minsize, maxsize>::ReportErrors(ValidationReport* report) const { if (this->empty()) { CompositeType::ReportErrors(report); @@ -506,8 +478,7 @@ void Map<T, minsize, maxsize>::ReportErrors(ValidationReport* report) const { // No error } } - for (typename Map::const_iterator i = this->begin(); - i != this->end(); ++i) { + for (typename Map::const_iterator i = this->begin(); i != this->end(); ++i) { if (!i->second.is_valid()) { std::string elem_name = "[\"" + i->first + "\"]"; ValidationReport& elem_report = report->ReportSubobject(elem_name); @@ -516,11 +487,10 @@ void Map<T, minsize, maxsize>::ReportErrors(ValidationReport* report) const { } } -template<typename T, size_t minsize, size_t maxsize> +template <typename T, size_t minsize, size_t maxsize> void Map<T, minsize, maxsize>::SetPolicyTableType( rpc::policy_table_interface_base::PolicyTableType pt_type) { - for (typename Map::iterator it = this->begin(); - it != this->end(); ++it) { + for (typename Map::iterator it = this->begin(); it != this->end(); ++it) { it->second.SetPolicyTableType(pt_type); } } @@ -528,46 +498,43 @@ void Map<T, minsize, maxsize>::SetPolicyTableType( /* * Nullable class */ -template<typename T> +template <typename T> Nullable<T>::Nullable() - : marked_null_(false) { -} + : marked_null_(false) {} -template<typename T> -template<typename U> +template <typename T> +template <typename U> Nullable<T>::Nullable(const U& value) - : T(value), - marked_null_(false) { -} + : T(value), marked_null_(false) {} -template<typename T> -template<typename U> +template <typename T> +template <typename U> Nullable<T>& Nullable<T>::operator=(const U& new_val) { this->T::operator=(new_val); return *this; } -template<typename T> +template <typename T> bool Nullable<T>::is_valid() const { return is_null() || T::is_valid(); } -template<typename T> +template <typename T> bool Nullable<T>::is_initialized() const { return is_null() || T::is_initialized(); } -template<typename T> +template <typename T> bool Nullable<T>::is_null() const { return marked_null_; } -template<typename T> +template <typename T> void Nullable<T>::set_to_null() { marked_null_ = true; } -template<typename T> +template <typename T> void Nullable<T>::ReportErrors(ValidationReport* report) const { if (marked_null_) { // No error @@ -579,59 +546,57 @@ void Nullable<T>::ReportErrors(ValidationReport* report) const { /* * Optional class */ -template<typename T> -Optional<T>::Optional() { -} +template <typename T> +Optional<T>::Optional() {} -template<typename T> -template<typename U> +template <typename T> +template <typename U> Optional<T>::Optional(const U& value) - : value_(value) { -} + : value_(value) {} -template<typename T> +template <typename T> T& Optional<T>::operator*() { return value_; } -template<typename T> +template <typename T> const T& Optional<T>::operator*() const { return value_; } -template<typename T> +template <typename T> T* Optional<T>::operator->() { return &value_; } -template<typename T> +template <typename T> const T* Optional<T>::operator->() const { return &value_; } -template<typename T> +template <typename T> void Optional<T>::assign_if_valid(const Optional<T>& value) { if (value.is_initialized()) { value_ = value.value_; } } -template<typename T> +template <typename T> Optional<T>::operator const void*() const { return is_initialized() ? &value_ : NULL; } -template<typename T> +template <typename T> bool Optional<T>::is_valid() const { return !value_.is_initialized() || value_.is_valid(); } -template<typename T> +template <typename T> bool Optional<T>::is_initialized() const { return value_.is_initialized(); } -template<typename T> +template <typename T> void Optional<T>::ReportErrors(ValidationReport* report) const { if (!is_initialized()) { // No error @@ -639,13 +604,15 @@ void Optional<T>::ReportErrors(ValidationReport* report) const { value_.ReportErrors(report); } } -template<typename T> -inline rpc::policy_table_interface_base::PolicyTableType Optional<T>::GetPolicyTableType() const { +template <typename T> +inline rpc::policy_table_interface_base::PolicyTableType +Optional<T>::GetPolicyTableType() const { return policy_table_type_; } -template<typename T> -void rpc::Optional<T>::SetPolicyTableType(rpc::policy_table_interface_base::PolicyTableType pt_type) { +template <typename T> +void rpc::Optional<T>::SetPolicyTableType( + rpc::policy_table_interface_base::PolicyTableType pt_type) { policy_table_type_ = pt_type; value_.SetPolicyTableType(pt_type); } @@ -653,51 +620,48 @@ void rpc::Optional<T>::SetPolicyTableType(rpc::policy_table_interface_base::Poli /* * Stringifyable class */ -template<typename T> +template <typename T> Stringifyable<T>::Stringifyable() - : predefined_string_("") { -} + : predefined_string_("") {} -template<typename T> -template<typename U> +template <typename T> +template <typename U> Stringifyable<T>::Stringifyable(const U& value) - : T(value), - predefined_string_("") { -} + : T(value), predefined_string_("") {} -template<typename T> -template<typename U> +template <typename T> +template <typename U> Stringifyable<T>& Stringifyable<T>::operator=(const U& new_val) { this->T::operator=(new_val); return *this; } -template<typename T> +template <typename T> bool Stringifyable<T>::is_valid() const { return is_string() || T::is_valid(); } -template<typename T> +template <typename T> bool Stringifyable<T>::is_initialized() const { return is_string() || T::is_initialized(); } -template<typename T> +template <typename T> bool Stringifyable<T>::is_string() const { return !predefined_string_.empty(); } -template<typename T> +template <typename T> std::string Stringifyable<T>::get_string() const { return predefined_string_; } -template<typename T> +template <typename T> void Stringifyable<T>::set_to_string(const std::string& input) { predefined_string_ = input; } -template<typename T> +template <typename T> void Stringifyable<T>::ReportErrors(ValidationReport* report) const { if (is_string()) { // No error @@ -708,6 +672,4 @@ void Stringifyable<T>::ReportErrors(ValidationReport* report) const { } // namespace rpc - - #endif /* VALIDATED_TYPES_INL_H_ */ diff --git a/src/components/rpc_base/include/rpc_base/rpc_base_json_inl.h b/src/components/rpc_base/include/rpc_base/rpc_base_json_inl.h index b5fd9a567a..b9fcac4b6a 100644 --- a/src/components/rpc_base/include/rpc_base/rpc_base_json_inl.h +++ b/src/components/rpc_base/include/rpc_base/rpc_base_json_inl.h @@ -40,8 +40,7 @@ namespace rpc { // static inline PrimitiveType::ValueState PrimitiveType::InitHelper( - const Json::Value* value, - bool (Json::Value::*type_check)() const) { + const Json::Value* value, bool (Json::Value::*type_check)() const) { if (!value) { return kUninitialized; } else if ((value->*type_check)()) { @@ -51,18 +50,19 @@ inline PrimitiveType::ValueState PrimitiveType::InitHelper( } } -inline policy_table_interface_base::PolicyTableType PrimitiveType::GetPolicyTableType() const { +inline policy_table_interface_base::PolicyTableType +PrimitiveType::GetPolicyTableType() const { return policy_table_type_; } -inline void PrimitiveType::SetPolicyTableType(policy_table_interface_base::PolicyTableType pt_type) { +inline void PrimitiveType::SetPolicyTableType( + policy_table_interface_base::PolicyTableType pt_type) { policy_table_type_ = pt_type; } // static inline CompositeType::InitializationState CompositeType::InitHelper( - const Json::Value* value, - bool (Json::Value::*type_check)() const) { + const Json::Value* value, bool (Json::Value::*type_check)() const) { if (!value) { return kUninitialized; } else if ((value->*type_check)()) { @@ -77,11 +77,13 @@ inline CompositeType::InitializationState CompositeType::InitHelper( } } -inline policy_table_interface_base::PolicyTableType CompositeType::GetPolicyTableType() const { +inline policy_table_interface_base::PolicyTableType +CompositeType::GetPolicyTableType() const { return policy_table_type_; } -inline void CompositeType::SetPolicyTableType(policy_table_interface_base::PolicyTableType pt_type) { +inline void CompositeType::SetPolicyTableType( + policy_table_interface_base::PolicyTableType pt_type) { policy_table_type_ = pt_type; } @@ -95,7 +97,7 @@ inline const Json::Value* ValueMember(const Json::Value* value, return NULL; } -template<class T> +template <class T> inline void WriteJsonField(const char* field_name, const T& field, Json::Value* json_value) { @@ -107,13 +109,12 @@ inline void WriteJsonField(const char* field_name, } // namespace impl inline Boolean::Boolean(const Json::Value* value) - : PrimitiveType(InitHelper(value, &Json::Value::isBool)), - value_(is_valid() ? value->asBool() : bool()) { -} + : PrimitiveType(InitHelper(value, &Json::Value::isBool)) + , value_(is_valid() ? value->asBool() : bool()) {} inline Boolean::Boolean(const Json::Value* value, bool def_value) - : PrimitiveType(InitHelper(value, &Json::Value::isBool)), - value_(is_valid() ? value->asBool() : def_value) { + : PrimitiveType(InitHelper(value, &Json::Value::isBool)) + , value_(is_valid() ? value->asBool() : def_value) { // If there is no value, mark it as valid and use def_value if (!is_initialized()) { value_state_ = kValid; @@ -124,10 +125,9 @@ inline Json::Value Boolean::ToJsonValue() const { return Json::Value(value_); } -template<typename T, T minval, T maxval> +template <typename T, T minval, T maxval> Integer<T, minval, maxval>::Integer(const Json::Value* value) - : PrimitiveType(InitHelper(value, &Json::Value::isInt)), - value_() { + : PrimitiveType(InitHelper(value, &Json::Value::isInt)), value_() { if (is_valid()) { Json::Value::Int64 intval = value->asInt64(); if (range_.Includes(intval)) { @@ -138,16 +138,14 @@ Integer<T, minval, maxval>::Integer(const Json::Value* value) } } -template<typename T, T minval, T maxval> +template <typename T, T minval, T maxval> Integer<T, minval, maxval>::Integer(const Integer& val) - : PrimitiveType(range_.Includes(val.value_) ? kValid : kInvalid), - value_(val.value_) { -} + : PrimitiveType(range_.Includes(val.value_) ? kValid : kInvalid) + , value_(val.value_) {} -template<typename T, T minval, T maxval> +template <typename T, T minval, T maxval> Integer<T, minval, maxval>::Integer(const Json::Value* value, IntType def_value) - : PrimitiveType(InitHelper(value, &Json::Value::isInt)), - value_(def_value) { + : PrimitiveType(InitHelper(value, &Json::Value::isInt)), value_(def_value) { if (!is_initialized()) { value_state_ = kValid; } else if (is_valid()) { @@ -160,26 +158,25 @@ Integer<T, minval, maxval>::Integer(const Json::Value* value, IntType def_value) } } -template<typename T, T minval, T maxval> +template <typename T, T minval, T maxval> Json::Value Integer<T, minval, maxval>::ToJsonValue() const { return Json::Value(Json::Int64(value_)); } -template<int64_t minnum, int64_t maxnum, int64_t minden, int64_t maxden> +template <int64_t minnum, int64_t maxnum, int64_t minden, int64_t maxden> Float<minnum, maxnum, minden, maxden>::Float(const Json::Value* value) - : PrimitiveType(InitHelper(value, &Json::Value::isDouble)), - value_() { + : PrimitiveType(InitHelper(value, &Json::Value::isDouble)), value_() { if (is_valid()) { value_ = value->asDouble(); value_state_ = range_.Includes(value_) ? kValid : kInvalid; } } -template<int64_t minnum, int64_t maxnum, int64_t minden, int64_t maxden> +template <int64_t minnum, int64_t maxnum, int64_t minden, int64_t maxden> Float<minnum, maxnum, minden, maxden>::Float(const Json::Value* value, - double def_value) - : PrimitiveType(InitHelper(value, &Json::Value::isDouble)), - value_(def_value) { + double def_value) + : PrimitiveType(InitHelper(value, &Json::Value::isDouble)) + , value_(def_value) { if (!is_initialized()) { value_state_ = kValid; } else if (is_valid()) { @@ -188,24 +185,25 @@ Float<minnum, maxnum, minden, maxden>::Float(const Json::Value* value, } } -template<int64_t minnum, int64_t maxnum, int64_t minden, int64_t maxden> +template <int64_t minnum, int64_t maxnum, int64_t minden, int64_t maxden> Json::Value Float<minnum, maxnum, minden, maxden>::ToJsonValue() const { return Json::Value(value_); } -template<size_t minlen, size_t maxlen> +template <size_t minlen, size_t maxlen> String<minlen, maxlen>::String(const Json::Value* value) - : PrimitiveType(InitHelper(value, &Json::Value::isString)), - value_(is_valid() ? value->asString() : std::string()) { + : PrimitiveType(InitHelper(value, &Json::Value::isString)) + , value_(is_valid() ? value->asString() : std::string()) { if (is_valid()) { value_state_ = length_range_.Includes(value_.length()) ? kValid : kInvalid; } } -template<size_t minlen, size_t maxlen> -String<minlen, maxlen>::String(const Json::Value* value, const std::string& def_value) - : PrimitiveType(InitHelper(value, &Json::Value::isString)), - value_(def_value) { +template <size_t minlen, size_t maxlen> +String<minlen, maxlen>::String(const Json::Value* value, + const std::string& def_value) + : PrimitiveType(InitHelper(value, &Json::Value::isString)) + , value_(def_value) { if (!is_initialized()) { value_state_ = kValid; } else if (is_valid()) { @@ -213,42 +211,42 @@ String<minlen, maxlen>::String(const Json::Value* value, const std::string& def_ } } -template<size_t minlen, size_t maxlen> +template <size_t minlen, size_t maxlen> Json::Value String<minlen, maxlen>::ToJsonValue() const { return Json::Value(value_); } -template<typename T> +template <typename T> Enum<T>::Enum(const Json::Value* value) - : PrimitiveType(InitHelper(value, &Json::Value::isString)), - value_(EnumType()) { + : PrimitiveType(InitHelper(value, &Json::Value::isString)) + , value_(EnumType()) { if (is_valid()) { value_state_ = - EnumFromJsonString(value->asString(), &value_) ? kValid : kInvalid; + EnumFromJsonString(value->asString(), &value_) ? kValid : kInvalid; } } -template<typename T> +template <typename T> Enum<T>::Enum(const Json::Value* value, EnumType def_value) - : PrimitiveType(InitHelper(value, &Json::Value::isString)), - value_(def_value) { + : PrimitiveType(InitHelper(value, &Json::Value::isString)) + , value_(def_value) { if (!is_initialized()) { value_state_ = kValid; } else if (is_valid()) { value_state_ = - EnumFromJsonString(value->asString(), &value_) ? kValid : kInvalid; + EnumFromJsonString(value->asString(), &value_) ? kValid : kInvalid; } } -template<typename T> +template <typename T> Json::Value Enum<T>::ToJsonValue() const { return Json::Value(Json::StaticString(EnumToJsonString(value_))); } // Non-const version -template<typename T, size_t minsize, size_t maxsize> +template <typename T, size_t minsize, size_t maxsize> Array<T, minsize, maxsize>::Array(Json::Value* value) - : CompositeType(InitHelper(value, &Json::Value::isArray)) { + : CompositeType(InitHelper(value, &Json::Value::isArray)) { if (value) { if (value->isArray()) { this->reserve(value->size()); @@ -263,13 +261,14 @@ Array<T, minsize, maxsize>::Array(Json::Value* value) } // Const version, must be identical to the non-const version -template<typename T, size_t minsize, size_t maxsize> +template <typename T, size_t minsize, size_t maxsize> Array<T, minsize, maxsize>::Array(const Json::Value* value) - : CompositeType(InitHelper(value, &Json::Value::isArray)) { + : CompositeType(InitHelper(value, &Json::Value::isArray)) { if (value) { if (value->isArray()) { this->reserve(value->size()); - for (Json::Value::const_iterator i = value->begin(); i != value->end(); ++i) { + for (Json::Value::const_iterator i = value->begin(); i != value->end(); + ++i) { push_back(&*i); } } else { @@ -279,20 +278,20 @@ Array<T, minsize, maxsize>::Array(const Json::Value* value) } } -template<typename T, size_t minsize, size_t maxsize> +template <typename T, size_t minsize, size_t maxsize> Json::Value Array<T, minsize, maxsize>::ToJsonValue() const { Json::Value array(Json::arrayValue); array.resize(this->size()); for (size_t i = 0; i != this->size(); ++i) { - array[Json::ArrayIndex(i)] = (this->operator [](i)).ToJsonValue(); + array[Json::ArrayIndex(i)] = (this->operator[](i)).ToJsonValue(); } return array; } // Non-const version -template<typename T, size_t minsize, size_t maxsize> +template <typename T, size_t minsize, size_t maxsize> Map<T, minsize, maxsize>::Map(Json::Value* value) - : CompositeType(InitHelper(value, &Json::Value::isObject)) { + : CompositeType(InitHelper(value, &Json::Value::isObject)) { if (value) { if (value->isObject()) { for (Json::Value::iterator i = value->begin(); i != value->end(); ++i) { @@ -305,12 +304,13 @@ Map<T, minsize, maxsize>::Map(Json::Value* value) } } -template<typename T, size_t minsize, size_t maxsize> +template <typename T, size_t minsize, size_t maxsize> Map<T, minsize, maxsize>::Map(const Json::Value* value) - : CompositeType(InitHelper(value, &Json::Value::isObject)) { + : CompositeType(InitHelper(value, &Json::Value::isObject)) { if (value) { if (value->isObject()) { - for (Json::Value::const_iterator i = value->begin(); i != value->end(); ++i) { + for (Json::Value::const_iterator i = value->begin(); i != value->end(); + ++i) { this->insert(typename MapType::value_type(i.key().asString(), T(&*i))); } } else { @@ -320,70 +320,64 @@ Map<T, minsize, maxsize>::Map(const Json::Value* value) } } -template<typename T, size_t minsize, size_t maxsize> +template <typename T, size_t minsize, size_t maxsize> Json::Value Map<T, minsize, maxsize>::ToJsonValue() const { Json::Value map(Json::objectValue); - for (typename MapType::const_iterator i = this->begin(); i != this->end(); ++i) { + for (typename MapType::const_iterator i = this->begin(); i != this->end(); + ++i) { map[i->first] = i->second.ToJsonValue(); } return map; } -template<typename T> +template <typename T> Nullable<T>::Nullable(const Json::Value* value) - : T(value), - marked_null_(value != NULL&& value->isNull()) { -} + : T(value), marked_null_(value != NULL && value->isNull()) {} -template<typename T> +template <typename T> Nullable<T>::Nullable(Json::Value* value) - : T(value), - marked_null_(value != NULL&& value->isNull()) { -} + : T(value), marked_null_(value != NULL && value->isNull()) {} -template<typename T> -template<typename U> +template <typename T> +template <typename U> Nullable<T>::Nullable(const Json::Value* value, const U& def_value) - : T(value, def_value), - marked_null_(value != NULL&& value->isNull()) { -} + : T(value, def_value), marked_null_(value != NULL && value->isNull()) {} -template<typename T> +template <typename T> inline Json::Value Nullable<T>::ToJsonValue() const { return marked_null_ ? Json::Value::null : T::ToJsonValue(); } -template<typename T> -template<typename U> +template <typename T> +template <typename U> Optional<T>::Optional(const Json::Value* value, const U& def_value) - : value_(value, def_value) { -} + : value_(value, def_value) {} -template<typename T> +template <typename T> inline Json::Value Optional<T>::ToJsonValue() const { return value_.ToJsonValue(); } -template<typename T> +template <typename T> Stringifyable<T>::Stringifyable(const Json::Value* value) - : T(NULL != value&& !value->isString() ? value : NULL), - predefined_string_(NULL != value&& value->isString() ? value->asString() : "") { -} + : T(NULL != value && !value->isString() ? value : NULL) + , predefined_string_(NULL != value && value->isString() ? value->asString() + : "") {} -template<typename T> +template <typename T> Stringifyable<T>::Stringifyable(Json::Value* value) - : T(NULL != value&& !value->isString() ? value : NULL), - predefined_string_(NULL != value&& value->isString() ? value->asString() : "") { -} + : T(NULL != value && !value->isString() ? value : NULL) + , predefined_string_(NULL != value && value->isString() ? value->asString() + : "") {} -template<typename T> -template<typename U> +template <typename T> +template <typename U> Stringifyable<T>::Stringifyable(const Json::Value* value, const U& def_value) - : T(NULL != value&& !value->isString() ? (value, def_value) : NULL), - predefined_string_(NULL != value&& value->isString() ? value->asString() : "") { -} + : T(NULL != value && !value->isString() ? (value, def_value) : NULL) + , predefined_string_(NULL != value && value->isString() ? value->asString() + : "") {} -template<typename T> +template <typename T> inline Json::Value Stringifyable<T>::ToJsonValue() const { return predefined_string_.empty() ? T::ToJsonValue() : predefined_string_; } diff --git a/src/components/rpc_base/include/rpc_base/rpc_message.h b/src/components/rpc_base/include/rpc_base/rpc_message.h index 18ace4552a..7b5ed2e375 100644 --- a/src/components/rpc_base/include/rpc_base/rpc_message.h +++ b/src/components/rpc_base/include/rpc_base/rpc_message.h @@ -41,17 +41,13 @@ class Value; namespace rpc { -enum MessageType { - kRequest = 0, - kResponse = 1, - kNotification = 2 -}; +enum MessageType { kRequest = 0, kResponse = 1, kNotification = 2 }; // Base class for all RPC messages // Has methods to identify interface this message belongs to // And message ID class Message { -public: + public: // Type of message virtual MessageType message_type() const = 0; // Numerical function identifier, unique to the interface @@ -69,26 +65,34 @@ public: // Base class for all interface-specific requests class RequestBase : public Message, public CompositeType { public: - explicit RequestBase(InitializationState init_state): CompositeType(init_state) {} + explicit RequestBase(InitializationState init_state) + : CompositeType(init_state) {} // Message interface - MessageType message_type() const { return kRequest; } + MessageType message_type() const { + return kRequest; + } virtual ~RequestBase() {} }; // Base class for all interface-specific responses class ResponseBase : public Message, public CompositeType { public: - ResponseBase(InitializationState init_state): CompositeType(init_state) {} + ResponseBase(InitializationState init_state) : CompositeType(init_state) {} // Message interface - MessageType message_type() const { return kResponse; } + MessageType message_type() const { + return kResponse; + } virtual ~ResponseBase() {} }; // Base class for all interface-specific notifications class NotificationBase : public Message, public CompositeType { public: - explicit NotificationBase(InitializationState init_state): CompositeType(init_state) {} - MessageType message_type() const { return kNotification; } + explicit NotificationBase(InitializationState init_state) + : CompositeType(init_state) {} + MessageType message_type() const { + return kNotification; + } // Message interface virtual ~NotificationBase() {} }; diff --git a/src/components/rpc_base/include/rpc_base/validation_report.h b/src/components/rpc_base/include/rpc_base/validation_report.h index b8a9c4d1cd..941c8f61cc 100644 --- a/src/components/rpc_base/include/rpc_base/validation_report.h +++ b/src/components/rpc_base/include/rpc_base/validation_report.h @@ -49,7 +49,8 @@ class ValidationReport { void set_validation_info(const std::string& info); const ValidationReports& subobject_reports() const; ValidationReport& ReportSubobject(const std::string& object_name); -private: + + private: std::string object_name_; std::string validation_info_; ValidationReports subobject_reports_; @@ -61,8 +62,8 @@ std::string PrettyFormat(const ValidationReport& report); namespace impl { inline void PrettyFormat(const ValidationReport& report, - const std::string& parent_path, - std::string* result) { + const std::string& parent_path, + std::string* result) { std::string object_path = parent_path; if (!object_path.empty() && report.object_name()[0] != '[') { object_path.append("."); @@ -76,15 +77,16 @@ inline void PrettyFormat(const ValidationReport& report, } const ValidationReports& subreports = report.subobject_reports(); for (ValidationReports::const_iterator i = subreports.begin(), - end = subreports.end(); i != end; ++i) { + end = subreports.end(); + i != end; + ++i) { PrettyFormat(*i, object_path, result); } } } // namespace impl inline ValidationReport::ValidationReport(const std::string& object_name) - : object_name_(object_name) { -} + : object_name_(object_name) {} inline const std::string& ValidationReport::object_name() const { return object_name_; @@ -98,7 +100,8 @@ inline void ValidationReport::set_validation_info(const std::string& info) { validation_info_ = info; } -inline const std::list<ValidationReport>& ValidationReport::subobject_reports() const { +inline const std::list<ValidationReport>& ValidationReport::subobject_reports() + const { return subobject_reports_; } diff --git a/src/components/rpc_base/src/rpc_base/rpc_base.cc b/src/components/rpc_base/src/rpc_base/rpc_base.cc index f2290780ed..d506bea377 100644 --- a/src/components/rpc_base/src/rpc_base/rpc_base.cc +++ b/src/components/rpc_base/src/rpc_base/rpc_base.cc @@ -32,6 +32,4 @@ #include "rpc_base/rpc_base.h" -namespace rpc { - -} // namespace rpc +namespace rpc {} // namespace rpc diff --git a/src/components/rpc_base/test/rpc_base_dbus_test.cc b/src/components/rpc_base/test/rpc_base_dbus_test.cc index e217eff476..f26ce25c5d 100644 --- a/src/components/rpc_base/test/rpc_base_dbus_test.cc +++ b/src/components/rpc_base/test/rpc_base_dbus_test.cc @@ -38,11 +38,7 @@ namespace test { using namespace rpc; using namespace dbus; -enum TestEnum { - kValue0, - kValue1, - kInvalidValue -}; +enum TestEnum { kValue0, kValue1, kInvalidValue }; bool IsValidEnum(TestEnum val) { return val == kValue0 || val == kValue1; @@ -74,8 +70,7 @@ const char* EnumToJsonString(TestEnum enm) { struct DbusDeserialization : public testing::Test { dbus::MessageRef msgref; DbusDeserialization() - : msgref(dbus_message_new(DBUS_MESSAGE_TYPE_METHOD_CALL)) { - } + : msgref(dbus_message_new(DBUS_MESSAGE_TYPE_METHOD_CALL)) {} }; TEST_F(DbusDeserialization, DeserializeBool) { @@ -97,7 +92,7 @@ TEST_F(DbusDeserialization, DeserializeByte) { } { dbus::MessageReader reader(msgref); - Integer < uint8_t, 1, 220 > byte(&reader); + Integer<uint8_t, 1, 220> byte(&reader); ASSERT_TRUE(byte.is_initialized()); ASSERT_TRUE(byte.is_valid()); ASSERT_EQ(byte, 200); @@ -113,7 +108,7 @@ TEST_F(DbusDeserialization, DeserializeInt64) { } { dbus::MessageReader reader(msgref); - Integer < int64_t, -5, 220 > int64(&reader); + Integer<int64_t, -5, 220> int64(&reader); ASSERT_TRUE(int64.is_initialized()); ASSERT_TRUE(int64.is_valid()); ASSERT_EQ(int64, -1); @@ -129,7 +124,7 @@ TEST_F(DbusDeserialization, DeserializeFloat) { } { dbus::MessageReader reader(msgref); - Float < 3, 4 > pi(&reader); + Float<3, 4> pi(&reader); ASSERT_TRUE(pi.is_initialized()); ASSERT_TRUE(pi.is_valid()); ASSERT_DOUBLE_EQ(pi, 3.14); @@ -145,7 +140,7 @@ TEST_F(DbusDeserialization, DeserializeString) { } { dbus::MessageReader reader(msgref); - String < 3, 10 > hello(&reader); + String<3, 10> hello(&reader); ASSERT_TRUE(hello.is_initialized()); ASSERT_TRUE(hello.is_valid()); ASSERT_EQ(std::string(hello), "Hello"); @@ -174,9 +169,9 @@ TEST_F(DbusDeserialization, DeserializeArray) { { dbus::MessageWriter writer(msgref); std::string array_signature; - rpc::DbusSignature<Integer<int32_t, 1, 50> >(&array_signature); - dbus::MessageWriter array_writer(&writer, dbus::kArray, - array_signature.c_str()); + rpc::DbusSignature<Integer<int32_t, 1, 50>>(&array_signature); + dbus::MessageWriter array_writer( + &writer, dbus::kArray, array_signature.c_str()); array_writer.PutInt32(5); array_writer.PutInt32(33); } @@ -190,7 +185,6 @@ TEST_F(DbusDeserialization, DeserializeArray) { ASSERT_EQ(array.size(), 2u); ASSERT_EQ(array[0], 5); ASSERT_EQ(array[1], 33); - } } @@ -198,15 +192,15 @@ TEST_F(DbusDeserialization, DeserializeArrayOfArrays) { { dbus::MessageWriter writer(msgref); std::string array_signature; - rpc::DbusSignature<Array<Integer<int32_t, 1, 50>, 1, 5> >(&array_signature); - dbus::MessageWriter array_writer(&writer, dbus::kArray, - array_signature.c_str()); + rpc::DbusSignature<Array<Integer<int32_t, 1, 50>, 1, 5>>(&array_signature); + dbus::MessageWriter array_writer( + &writer, dbus::kArray, array_signature.c_str()); int val = 5; for (int i = 0; i < 2; ++i) { std::string subarray_signature; - rpc::DbusSignature<Integer<int32_t, 1, 50> >(&subarray_signature); - dbus::MessageWriter subarray_wirter(&array_writer, dbus::kArray, - subarray_signature.c_str()); + rpc::DbusSignature<Integer<int32_t, 1, 50>>(&subarray_signature); + dbus::MessageWriter subarray_wirter( + &array_writer, dbus::kArray, subarray_signature.c_str()); subarray_wirter.PutInt32(val++); subarray_wirter.PutInt32(val++); @@ -226,7 +220,6 @@ TEST_F(DbusDeserialization, DeserializeArrayOfArrays) { ASSERT_EQ(array[0][1], 6); ASSERT_EQ(array[1][0], 7); ASSERT_EQ(array[1][1], 8); - } } @@ -235,9 +228,9 @@ TEST_F(DbusDeserialization, DeserializeMap) { dbus::MessageWriter writer(msgref); std::string dict_signature; rpc::DbusSignature<Map<Enum<TestEnum>, 1, 5>::value_type>(&dict_signature); - dbus::MessageWriter array_writer(&writer, dbus::kArray, - dict_signature.c_str()); - const char* keys[] = { "Hello", "World" }; + dbus::MessageWriter array_writer( + &writer, dbus::kArray, dict_signature.c_str()); + const char* keys[] = {"Hello", "World"}; int val = 0; for (int i = 0; i < 2; ++i) { dbus::MessageWriter dictval_wirter(&array_writer, dbus::kDictEntry, NULL); @@ -255,7 +248,6 @@ TEST_F(DbusDeserialization, DeserializeMap) { ASSERT_EQ(amap.size(), 2u); ASSERT_EQ(amap["Hello"], kValue0); ASSERT_EQ(amap["World"], kValue1); - } } @@ -283,7 +275,7 @@ TEST_F(DbusDeserialization, DeserializeOptionalString) { } { dbus::MessageReader reader(msgref); - Optional < String<1, 100> > readback(&reader); + Optional<String<1, 100>> readback(&reader); ASSERT_TRUE(readback.is_initialized()); ASSERT_TRUE(readback.is_valid()); ASSERT_EQ(std::string(*readback), "Hello dear"); @@ -301,16 +293,14 @@ TEST_F(DbusDeserialization, DeserializeOptionalInt) { } { dbus::MessageReader reader(msgref); - Optional < Integer<int32_t, 1, 90>> readback(&reader); + Optional<Integer<int32_t, 1, 90>> readback(&reader); ASSERT_FALSE(readback.is_initialized()); ASSERT_TRUE(readback.is_valid()); ASSERT_FALSE(reader.has_failed()); ASSERT_FALSE(reader.HasNext()); - } } - TEST_F(DbusDeserialization, SerializeDeserializeBool) { { Boolean true_bool(true); @@ -330,13 +320,13 @@ TEST_F(DbusDeserialization, SerializeDeserializeBool) { TEST_F(DbusDeserialization, SerializeDeserializeInt8t) { { - Integer < int8_t, 1, 100 > int8(42); + Integer<int8_t, 1, 100> int8(42); dbus::MessageWriter writer(msgref); int8.ToDbusWriter(&writer); } { dbus::MessageReader reader(msgref); - Integer < int8_t, 1, 100 > readback(&reader); + Integer<int8_t, 1, 100> readback(&reader); ASSERT_TRUE(readback.is_initialized()); ASSERT_TRUE(readback.is_valid()); ASSERT_EQ(readback, 42); @@ -347,13 +337,13 @@ TEST_F(DbusDeserialization, SerializeDeserializeInt8t) { TEST_F(DbusDeserialization, BadSerializeDeserializeInt8t) { { - Integer < int8_t, 1, 12 > int8(42); + Integer<int8_t, 1, 12> int8(42); dbus::MessageWriter writer(msgref); int8.ToDbusWriter(&writer); } { dbus::MessageReader reader(msgref); - Integer < int8_t, 1, 12 > readback(&reader); + Integer<int8_t, 1, 12> readback(&reader); ASSERT_TRUE(readback.is_initialized()); ASSERT_FALSE(readback.is_valid()); ASSERT_FALSE(reader.has_failed()); @@ -363,13 +353,13 @@ TEST_F(DbusDeserialization, BadSerializeDeserializeInt8t) { TEST_F(DbusDeserialization, SerializeDeserializeInt64t) { { - Integer < int64_t, 1, 0xFFFFFFFFFF > int64(0xFFFFFFFFF1); + Integer<int64_t, 1, 0xFFFFFFFFFF> int64(0xFFFFFFFFF1); dbus::MessageWriter writer(msgref); int64.ToDbusWriter(&writer); } { dbus::MessageReader reader(msgref); - Integer < int64_t, 1, 0xFFFFFFFFFF > readback(&reader); + Integer<int64_t, 1, 0xFFFFFFFFFF> readback(&reader); ASSERT_TRUE(readback.is_initialized()); ASSERT_TRUE(readback.is_valid()); ASSERT_EQ(readback, 0xFFFFFFFFF1); @@ -378,16 +368,15 @@ TEST_F(DbusDeserialization, SerializeDeserializeInt64t) { } } - TEST_F(DbusDeserialization, SerializeDeserializeDouble) { { - Float < 1, 5 > flt(3.14); + Float<1, 5> flt(3.14); dbus::MessageWriter writer(msgref); flt.ToDbusWriter(&writer); } { dbus::MessageReader reader(msgref); - Float < 1, 5 > readback(&reader); + Float<1, 5> readback(&reader); ASSERT_TRUE(readback.is_initialized()); ASSERT_TRUE(readback.is_valid()); ASSERT_DOUBLE_EQ(readback, 3.14); @@ -398,13 +387,13 @@ TEST_F(DbusDeserialization, SerializeDeserializeDouble) { TEST_F(DbusDeserialization, SerializeDeserializeString) { { - String < 1, 12 > hello("Hello"); + String<1, 12> hello("Hello"); dbus::MessageWriter writer(msgref); hello.ToDbusWriter(&writer); } { dbus::MessageReader reader(msgref); - String < 1, 12 > readback(&reader); + String<1, 12> readback(&reader); ASSERT_TRUE(readback.is_initialized()); ASSERT_TRUE(readback.is_valid()); ASSERT_EQ(std::string(readback), "Hello"); @@ -505,61 +494,61 @@ TEST(ValidatedTypes, TestBooleanDbusSignature) { TEST(ValidatedTypes, TestIntDbusSignature) { std::string sign; - DbusSignature<Integer<int32_t, 1, 2> >(&sign); + DbusSignature<Integer<int32_t, 1, 2>>(&sign); ASSERT_EQ(sign, "i"); } TEST(ValidatedTypes, TestFloatDbusSignature) { std::string sign; - DbusSignature<Float<1, 2> >(&sign); + DbusSignature<Float<1, 2>>(&sign); ASSERT_EQ(sign, "d"); } TEST(ValidatedTypes, TestStringDbusSignature) { std::string sign; - DbusSignature<String<1, 2> >(&sign); + DbusSignature<String<1, 2>>(&sign); ASSERT_EQ(sign, "s"); } TEST(ValidatedTypes, TestEnumDbusSignature) { std::string sign; - DbusSignature<Enum<TestEnum> >(&sign); + DbusSignature<Enum<TestEnum>>(&sign); ASSERT_EQ(sign, "i"); } TEST(ValidatedTypes, TestIntArrayDbusSignature) { std::string sign; - DbusSignature<Array<Integer<int32_t, 1, 2>, 1, 3> >(&sign); + DbusSignature<Array<Integer<int32_t, 1, 2>, 1, 3>>(&sign); ASSERT_EQ(sign, "ai"); } TEST(ValidatedTypes, TestIntArrayArrayDbusSignature) { std::string sign; - DbusSignature<Array<Array<Integer<int32_t, 1, 2>, 1, 3>, 4, 5> >(&sign); + DbusSignature<Array<Array<Integer<int32_t, 1, 2>, 1, 3>, 4, 5>>(&sign); ASSERT_EQ(sign, "aai"); } TEST(ValidatedTypes, TestMapDbusSignature) { std::string sign; - DbusSignature<Map<Integer<int32_t, 1, 2>, 3, 4> >(&sign); + DbusSignature<Map<Integer<int32_t, 1, 2>, 3, 4>>(&sign); ASSERT_EQ(sign, "a{si}"); } TEST(ValidatedTypes, TestMandatoryEnumDbusSignature) { std::string sign; - DbusSignature<Enum<TestEnum> >(&sign); + DbusSignature<Enum<TestEnum>>(&sign); ASSERT_EQ(sign, "i"); } TEST(ValidatedTypes, TestOptionalEnumDbusSignature) { std::string sign; - DbusSignature<Optional<Enum<TestEnum> > >(&sign); + DbusSignature<Optional<Enum<TestEnum>>>(&sign); ASSERT_EQ(sign, "(bi)"); } TEST(ValidatedTypes, TestOptionalFloatArrayDbusSignature) { std::string sign; - DbusSignature<Optional<Array<Float<1, 2>, 3, 4> > >(&sign); + DbusSignature<Optional<Array<Float<1, 2>, 3, 4>>>(&sign); ASSERT_EQ(sign, "(bad)"); } @@ -571,9 +560,7 @@ TEST(DbusMessageConstructionTest, DbusMessageConstruction) { class DbusTest : public testing::Test { public: dbus::MessageRef msgref; - DbusTest() - : msgref(dbus_message_new(DBUS_MESSAGE_TYPE_METHOD_CALL)) { - } + DbusTest() : msgref(dbus_message_new(DBUS_MESSAGE_TYPE_METHOD_CALL)) {} }; TEST_F(DbusTest, DbusWriterConstructionTest) { @@ -637,8 +624,8 @@ TEST_F(DbusTest, DbusMultipleParamsReadWrite) { TEST_F(DbusTest, DbusArrayTest) { { dbus::MessageWriter writer(msgref); - dbus::MessageWriter array_writer(&writer, dbus::kArray, - DBUS_TYPE_INT16_AS_STRING); + dbus::MessageWriter array_writer( + &writer, dbus::kArray, DBUS_TYPE_INT16_AS_STRING); array_writer.PutInt16(3); array_writer.PutInt16(4); array_writer.PutInt16(5); diff --git a/src/components/rpc_base/test/rpc_base_json_test.cc b/src/components/rpc_base/test/rpc_base_json_test.cc index 3a536937ba..07ac0418e0 100644 --- a/src/components/rpc_base/test/rpc_base_json_test.cc +++ b/src/components/rpc_base/test/rpc_base_json_test.cc @@ -39,11 +39,7 @@ using namespace rpc; using Json::Value; namespace { -enum TestEnum { - kValue0, - kValue1, - kInvalidValue -}; +enum TestEnum { kValue0, kValue1, kInvalidValue }; bool EnumFromJsonString(const std::string& value, TestEnum* enm) { if (value == "kValue0") { @@ -58,10 +54,13 @@ bool EnumFromJsonString(const std::string& value, TestEnum* enm) { } const char* EnumToJsonString(TestEnum enm) { - switch(enm) { - case kValue0: return "kValue0"; - case kValue1: return "kValue1"; - default: return "UNKNOWN"; + switch (enm) { + case kValue0: + return "kValue0"; + case kValue1: + return "kValue1"; + default: + return "UNKNOWN"; } } @@ -272,7 +271,7 @@ TEST(ValidatedTypesJson, MandatoryMapNullTest) { TEST(ValidatedTypesJson, OptionalMapAbsentValueTest) { Value* novalue = NULL; - Optional< Map<String<1, 32>, 0, 5> > map(novalue); + Optional<Map<String<1, 32>, 0, 5> > map(novalue); ASSERT_FALSE(map.is_initialized()); ASSERT_TRUE(map.is_valid()); } @@ -305,7 +304,7 @@ TEST(ValidatedTypesJson, MapFromNonArrayJsonTest) { TEST(ValidatedTypesJson, OptionalBoolFromJsonTest) { Value bool_value(true); - Optional< Boolean > optional_bool; + Optional<Boolean> optional_bool; *optional_bool = Boolean(&bool_value); ASSERT_TRUE(optional_bool.is_initialized()); ASSERT_TRUE(optional_bool.is_valid()); @@ -316,7 +315,7 @@ TEST(ValidatedTypesJson, OptionalBoolFromJsonTest) { TEST(ValidatedTypesJson, OptionalBoolFromAbsentValueTest) { Value* none = NULL; - Optional< Boolean > optional_bool; + Optional<Boolean> optional_bool; *optional_bool = Boolean(none); ASSERT_FALSE(optional_bool.is_initialized()); // It is ok for Optional value to be absent @@ -324,7 +323,7 @@ TEST(ValidatedTypesJson, OptionalBoolFromAbsentValueTest) { } TEST(ValidatedTypesJson, OptionalBoolFromNullValueTest) { - Optional< Boolean > optional_bool; + Optional<Boolean> optional_bool; *optional_bool = Boolean(&Value::null); ASSERT_TRUE(optional_bool.is_initialized()); // Optional values should not be absent @@ -332,7 +331,7 @@ TEST(ValidatedTypesJson, OptionalBoolFromNullValueTest) { } TEST(ValidatedTypesJson, NullableIntFromNullValueTest) { - Nullable< Integer<int8_t, 1, 15> > nullable_int(&Value::null); + Nullable<Integer<int8_t, 1, 15> > nullable_int(&Value::null); ASSERT_TRUE(nullable_int.is_initialized()); ASSERT_TRUE(nullable_int.is_valid()); ASSERT_TRUE(nullable_int.is_null()); @@ -340,7 +339,7 @@ TEST(ValidatedTypesJson, NullableIntFromNullValueTest) { TEST(ValidatedTypesJson, NullableIntFromNonNullValueTest) { Value json(3); - Nullable< Integer<int8_t, 1, 15> > nullable_int(&json); + Nullable<Integer<int8_t, 1, 15> > nullable_int(&json); ASSERT_TRUE(nullable_int.is_initialized()); ASSERT_TRUE(nullable_int.is_valid()); ASSERT_FALSE(nullable_int.is_null()); @@ -349,7 +348,7 @@ TEST(ValidatedTypesJson, NullableIntFromNonNullValueTest) { TEST(ValidatedTypesJson, NullableIntFromAbsentValueTest) { Value* noval = NULL; - Nullable< Integer<int8_t, 1, 15> > nullable_int(noval); + Nullable<Integer<int8_t, 1, 15> > nullable_int(noval); ASSERT_FALSE(nullable_int.is_initialized()); ASSERT_FALSE(nullable_int.is_valid()); ASSERT_FALSE(nullable_int.is_null()); @@ -357,8 +356,8 @@ TEST(ValidatedTypesJson, NullableIntFromAbsentValueTest) { TEST(ValidatedTypesJson, OptionalIntFromJsonTest) { Value int_value(42); - Optional< Integer<int64_t, 42, 43> > optional_int; - *optional_int = Integer<int64_t, 42, 43> (&int_value); + Optional<Integer<int64_t, 42, 43> > optional_int; + *optional_int = Integer<int64_t, 42, 43>(&int_value); ASSERT_TRUE(optional_int.is_initialized()); ASSERT_TRUE(optional_int.is_valid()); Value readback = optional_int->ToJsonValue(); @@ -366,8 +365,4 @@ TEST(ValidatedTypesJson, OptionalIntFromJsonTest) { ASSERT_EQ(readback.asInt(), 42); } - } // namespace test - - - diff --git a/src/components/rpc_base/test/rpc_base_test.cc b/src/components/rpc_base/test/rpc_base_test.cc index 553dacb85d..37a64b319e 100644 --- a/src/components/rpc_base/test/rpc_base_test.cc +++ b/src/components/rpc_base/test/rpc_base_test.cc @@ -40,11 +40,7 @@ using namespace rpc; namespace { -enum TestEnum { - kValue0, - kValue1, - kInvalidValue -}; +enum TestEnum { kValue0, kValue1, kInvalidValue }; bool IsValidEnum(TestEnum val) { return val == kValue0 || val == kValue1; @@ -190,7 +186,7 @@ TEST(ValidatedTypes, TestArrayInitializingConstructor) { } TEST(ValidatedTypes, TestOptionalEmptyArray) { - Optional< Array<Integer<int8_t, 0, 10>, 0, 5> > ai; + Optional<Array<Integer<int8_t, 0, 10>, 0, 5> > ai; ASSERT_RPCTYPE_VALID(ai); ASSERT_FALSE(ai.is_initialized()); Json::FastWriter fw; @@ -220,10 +216,10 @@ TEST(ValidatedTypes, TestMap) { } TEST(ValidatedTypes, TestMapInitializingConstructor) { - std::map< std::string, std::string > init_map; + std::map<std::string, std::string> init_map; init_map["a"] = "Hello"; init_map["b"] = "World"; - Map<String<1, 6>, 2, 10 > map(init_map); + Map<String<1, 6>, 2, 10> map(init_map); ASSERT_TRUE(map.is_initialized()); ASSERT_RPCTYPE_VALID(map); } @@ -251,7 +247,7 @@ TEST(ValidatedTypes, TestEnumConstructor) { } TEST(ValidatedTypes, TestNullableConstructor) { - Nullable< Integer<int8_t, 2, 10> >nullable_int; + Nullable<Integer<int8_t, 2, 10> > nullable_int; ASSERT_FALSE(nullable_int.is_initialized()); ASSERT_FALSE(nullable_int.is_null()); ASSERT_FALSE(nullable_int.is_valid()); @@ -266,7 +262,7 @@ TEST(ValidatedTypes, TestNullableConstructor) { } TEST(ValidatedTypes, TestOptionalNullableConstructor) { - Optional< Nullable< Integer<int8_t, 2, 10> > > optional_nullable_int; + Optional<Nullable<Integer<int8_t, 2, 10> > > optional_nullable_int; ASSERT_FALSE(optional_nullable_int.is_initialized()); ASSERT_FALSE(optional_nullable_int->is_null()); ASSERT_RPCTYPE_VALID(optional_nullable_int); @@ -286,7 +282,7 @@ TEST(ValidatedTypes, TestOptionalNullableConstructor) { } TEST(ValidatedTypes, TestOptionalConstructor) { - Optional< Integer<int16_t, 3, 15> > optional_int; + Optional<Integer<int16_t, 3, 15> > optional_int; ASSERT_FALSE(optional_int.is_initialized()); ASSERT_RPCTYPE_VALID(optional_int); *optional_int = 42; @@ -300,7 +296,7 @@ TEST(ValidatedTypes, TestOptionalConstructor) { } TEST(ValidatedTypes, TestOptionalInitializingConstructor) { - Optional< String<1, 12> > optional_string("Hello world"); + Optional<String<1, 12> > optional_string("Hello world"); ASSERT_TRUE(optional_string.is_initialized()); ASSERT_RPCTYPE_VALID(optional_string); std::string value = *optional_string; @@ -334,7 +330,7 @@ TEST(ValidatedTypes, ReportIncorrectInitializedIntType) { } TEST(ValidatedTypes, ReportUninitializedOptionalType) { - Optional< Integer<int8_t, 1, 3> > val; + Optional<Integer<int8_t, 1, 3> > val; ASSERT_RPCTYPE_VALID(val); ValidationReport report("val"); val.ReportErrors(&report); @@ -342,7 +338,7 @@ TEST(ValidatedTypes, ReportUninitializedOptionalType) { } TEST(ValidatedTypes, ReportIncorrectInitializedOptionalType) { - Optional< Integer<int8_t, 1, 3> > val(5); + Optional<Integer<int8_t, 1, 3> > val(5); ASSERT_FALSE(val.is_valid()); ValidationReport report("val"); val.ReportErrors(&report); @@ -350,7 +346,7 @@ TEST(ValidatedTypes, ReportIncorrectInitializedOptionalType) { } TEST(ValidatedTypes, ReportUninitializedNullableIntType) { - Nullable< Integer<int8_t, 1, 3> > val; + Nullable<Integer<int8_t, 1, 3> > val; ASSERT_FALSE(val.is_valid()); ValidationReport report("val"); val.ReportErrors(&report); @@ -358,7 +354,7 @@ TEST(ValidatedTypes, ReportUninitializedNullableIntType) { } TEST(ValidatedTypes, ReportNullInitializedNullableIntType) { - Nullable< Integer<int8_t, 1, 3> > val; + Nullable<Integer<int8_t, 1, 3> > val; val.set_to_null(); ASSERT_RPCTYPE_VALID(val); ValidationReport report("val"); @@ -367,7 +363,7 @@ TEST(ValidatedTypes, ReportNullInitializedNullableIntType) { } TEST(ValidatedTypes, ReportNoninitializedIntArray) { - Array< Enum<TestEnum>, 1, 3 > array; + Array<Enum<TestEnum>, 1, 3> array; ASSERT_FALSE(array.is_valid()); ValidationReport report("array"); array.ReportErrors(&report); @@ -375,7 +371,7 @@ TEST(ValidatedTypes, ReportNoninitializedIntArray) { } TEST(ValidatedTypes, ReportIncorrectlyInitializedIntArray1) { - Array< Integer<int8_t, 1, 10>, 1, 3 > array; + Array<Integer<int8_t, 1, 10>, 1, 3> array; array.push_back(11); ASSERT_FALSE(array.is_valid()); ValidationReport report("array"); @@ -384,7 +380,7 @@ TEST(ValidatedTypes, ReportIncorrectlyInitializedIntArray1) { } TEST(ValidatedTypes, ReportIncorrectlyInitializedIntArray2) { - Array< Integer<int8_t, 1, 10>, 1, 3 > array; + Array<Integer<int8_t, 1, 10>, 1, 3> array; array.push_back(1); array.push_back(2); array.push_back(3); @@ -396,42 +392,47 @@ TEST(ValidatedTypes, ReportIncorrectlyInitializedIntArray2) { } TEST(ValidatedTypes, ReportIncorrectlyInitializedArray3) { - Array< Integer<int8_t, 1, 10>, 1, 3 > array; + Array<Integer<int8_t, 1, 10>, 1, 3> array; array.push_back(1); array.push_back(2); array.push_back(42); array.push_back(4); ValidationReport report("array"); array.ReportErrors(&report); - ASSERT_EQ("array: array has invalid size\n" - "array[2]: value initialized incorrectly\n", PrettyFormat(report)); + ASSERT_EQ( + "array: array has invalid size\n" + "array[2]: value initialized incorrectly\n", + PrettyFormat(report)); } TEST(ValidatedTypes, ReportUninitializedMap) { - Map< Integer<int8_t, 1, 10>, 1, 3 > map; + Map<Integer<int8_t, 1, 10>, 1, 3> map; ValidationReport report("map"); map.ReportErrors(&report); ASSERT_EQ("map: object is not initialized\n", PrettyFormat(report)); } TEST(ValidatedTypes, ReportIncorrectlyInitializedMap1) { - Map< Integer<int8_t, 1, 10>, 1, 3 > map; + Map<Integer<int8_t, 1, 10>, 1, 3> map; map["aha"] = 42; ValidationReport report("map"); map.ReportErrors(&report); - ASSERT_EQ("map[\"aha\"]: value initialized incorrectly\n", PrettyFormat(report)); + ASSERT_EQ("map[\"aha\"]: value initialized incorrectly\n", + PrettyFormat(report)); } TEST(ValidatedTypes, ReportIncorrectlyInitializedMap2) { - Map< Integer<int8_t, 1, 10>, 1, 3 > map; + Map<Integer<int8_t, 1, 10>, 1, 3> map; map["aha"] = 3; map["haha"] = 12; map["muhahaha"] = 17; map["muhahaha"] = 22; ValidationReport report("map"); map.ReportErrors(&report); - ASSERT_EQ("map[\"haha\"]: value initialized incorrectly\n" - "map[\"muhahaha\"]: value initialized incorrectly\n", PrettyFormat(report)); + ASSERT_EQ( + "map[\"haha\"]: value initialized incorrectly\n" + "map[\"muhahaha\"]: value initialized incorrectly\n", + PrettyFormat(report)); } } // namespace codegen diff --git a/src/components/rpc_base/test/validation_report_test.cc b/src/components/rpc_base/test/validation_report_test.cc index 1493de3957..e7dded342c 100644 --- a/src/components/rpc_base/test/validation_report_test.cc +++ b/src/components/rpc_base/test/validation_report_test.cc @@ -50,10 +50,12 @@ class ValidationReportTest : public testing::Test { static const std::string parent_object_name_; static void SetUpTestCase() { - report_ = new ValidationReport(object_name_); - report_2 = new ValidationReport(object_name_2); + report_ = new ValidationReport(object_name_); + report_2 = new ValidationReport(object_name_2); + } + virtual void TearDown() { + ClearReports(); } - virtual void TearDown() { ClearReports(); } void ClearReports() { ValidationReports& temp = @@ -61,16 +63,17 @@ class ValidationReportTest : public testing::Test { temp.clear(); } - void GeneratePrettyFormatResult(std::string& result, const std::string& parent_name, - const std::string& obj_name, const std::string& val_info) { + void GeneratePrettyFormatResult(std::string& result, + const std::string& parent_name, + const std::string& obj_name, + const std::string& val_info) { std::string temp; if (obj_name[0] != '[') { - temp = "."; + temp = "."; } else { - temp = ""; + temp = ""; } - result = parent_name + temp + obj_name + ":" + " " + - val_info + "\n"; + result = parent_name + temp + obj_name + ":" + " " + val_info + "\n"; } void ClearValidationInfo() { @@ -101,7 +104,6 @@ const std::string ValidationReportTest::test_validation_info_ = "test_validation_info"; const std::string ValidationReportTest::parent_object_name_ = "test_parent"; - TEST_F(ValidationReportTest, Ctor_and_object_name_test_ExpectDataCorrect) { EXPECT_EQ(object_name_, report_->object_name()); } @@ -145,9 +147,11 @@ TEST_F(ValidationReportTest, PrettyFormat_ExpectDataCorrect) { impl::PrettyFormat(*report_, parent_object_name_, &result1); impl::PrettyFormat(*report_2, parent_object_name_, &result2); std::string temp1; - GeneratePrettyFormatResult(temp1, parent_object_name_, object_name_, test_validation_info_); + GeneratePrettyFormatResult( + temp1, parent_object_name_, object_name_, test_validation_info_); std::string temp2; - GeneratePrettyFormatResult(temp2, parent_object_name_, object_name_2, test_validation_info_); + GeneratePrettyFormatResult( + temp2, parent_object_name_, object_name_2, test_validation_info_); // Checks EXPECT_EQ(temp1, result1); EXPECT_EQ(temp2, result2); |