diff options
author | Alexander Kutsan <akutsan@luxoft.com> | 2018-02-06 16:18:29 +0200 |
---|---|---|
committer | Ira Lytvynenko (GitHub) <ILytvynenko@luxoft.com> | 2018-06-26 12:01:42 +0300 |
commit | 210c3fa42d65f59c295816b23d8c33fdab005acb (patch) | |
tree | 31790010166e81a1129f99213f97610ff0ae50ad /src/components/utils | |
parent | adcca686d6374d5fdd2e24414516a61847ea8b9f (diff) | |
download | sdl_core-210c3fa42d65f59c295816b23d8c33fdab005acb.tar.gz |
Plugin manager and plugin interface creation
add Optional type
Fix compile warnings and use optional for returning plugin
Add descriptions to optional
Fix review issues
Fix header guards
Fix build with unit tests after commands factory refactoring
- Change enum name from command origin to command source
- Create Mock for command factory class
- Fix mock_app_manager after refactoring
- Fix failed unit test
Diffstat (limited to 'src/components/utils')
-rw-r--r-- | src/components/utils/include/utils/optional.h | 78 |
1 files changed, 78 insertions, 0 deletions
diff --git a/src/components/utils/include/utils/optional.h b/src/components/utils/include/utils/optional.h new file mode 100644 index 0000000000..5fd0b5fcc3 --- /dev/null +++ b/src/components/utils/include/utils/optional.h @@ -0,0 +1,78 @@ +#ifndef ERROR_OR_H +#define ERROR_OR_H +#include <string> +#include "utils/macro.h" + +namespace utils { + +/** + * @brief The Optional class is able to keep value, manage it it is empty and + * specify error code. + * Can be used as return value of function that is not guarantee that vaue will + * be returned + * + */ +template <typename ObjectType, typename ErrorType = std::string> +class Optional { + public: + /** + * @brief The OptionalEmpty enum enum with one value to specify that Optional + * is not initialized + */ + enum OptionalEmpty { EMPTY }; + + /** + * @brief Optional constructor with object initialization + * @param object object to initialize Optional + */ + Optional(ObjectType& object) + : object_(&object), error_(), is_initialized_(true) {} + + /** + * @brief Optional constructor with object and error initialization + * @param object object to initialize Optional + * @param error error code initialization + */ + Optional(ObjectType& object, ErrorType error) + : object_(&object), error_(error), is_initialized_(true) {} + + /** + * @brief Optional constructir without object initialization + * @param empty manadatory parameter for explicit specifying that Optional is + * empty + * @param error error code initialization + */ + Optional(OptionalEmpty empty, ErrorType error) + : object_(nullptr), error_(error), is_initialized_(false) {} + + /** + * @brief Optional empty optional initialization without specifying error code + * @param empty manadatory parameter for explicit specifying that Optional is + * empty + */ + Optional(OptionalEmpty empty) + : object_(nullptr), error_(), is_initialized_(false) {} + + /** + * @brief operator bool operator for checking if optional is initialized + */ + operator bool() const { + return is_initialized_; + } + + /** + * @brief operator * access to object + * @return + */ + ObjectType& operator*() const { + DCHECK(is_initialized_); + return *object_; + } + + private: + ObjectType* object_; + ErrorType error_; + bool is_initialized_; +}; +} // utils utils +#endif // ERROR_OR_H |