diff --git a/alib2data/src/common/wrapper.hpp b/alib2data/src/common/wrapper.hpp index a6874ac07e87541228dcb475c7417db1ce8be0ea..f4de62a881330ec923e6c5f71841220a2a4596bd 100644 --- a/alib2data/src/common/wrapper.hpp +++ b/alib2data/src/common/wrapper.hpp @@ -13,85 +13,96 @@ namespace alib { -template<typename T> +template < typename T > class wrapper { protected: - std::cow_shared_ptr<T> data; + std::cow_shared_ptr < T > data; public: - explicit wrapper(T* data) : data(data) { + explicit wrapper ( T * data ) : data ( data ) { } - explicit wrapper(const T& data) : data(data.clone()) { + explicit wrapper ( const T & data ) : data ( data.clone ( ) ) { } - explicit wrapper(T&& data) : data(std::move(data).plunder()) { + explicit wrapper ( T && data ) : data ( std::move ( data ).plunder ( ) ) { } - virtual ~wrapper() noexcept { + virtual ~wrapper ( ) noexcept { } - const T& getData() const { - return *data; + const T & getData ( ) const { + return * data; } - T& getData() { - return *data; + T & getData ( ) { + return * data; } - void setData(T* data) { - this->data = std::cow_shared_ptr<T>(data); + void setData ( T * data ) { + this->data = std::cow_shared_ptr < T > ( data ); } - void setData(const T& data) { - this->data = std::cow_shared_ptr<T>(data.clone()); + void setData ( const T & data ) { + this->data = std::cow_shared_ptr < T > ( data.clone ( ) ); } - void setData(T&& data) { - this->data = std::cow_shared_ptr<T>(std::move(data).plunder()); + void setData ( T && data ) { + this->data = std::cow_shared_ptr < T > ( std::move ( data ).plunder ( ) ); } - bool operator>=(const wrapper& other) const { - if(this->data.get() == other.data.get()) return true; - return *(this->data) >= *(other.data); + bool operator >=( const wrapper & other ) const { + if ( this->data.get ( ) == other.data.get ( ) ) return true; + + return * ( this->data ) >= * ( other.data ); } - bool operator<=(const wrapper& other) const { - if(this->data.get() == other.data.get()) return true; - return *(this->data) <= *(other.data); + bool operator <=( const wrapper & other ) const { + if ( this->data.get ( ) == other.data.get ( ) ) return true; + + return * ( this->data ) <= * ( other.data ); + } + + bool operator >( const wrapper & other ) const { + if ( this->data.get ( ) == other.data.get ( ) ) return false; + + return * ( this->data ) > * ( other.data ); } - bool operator>(const wrapper& other) const { - if(this->data.get() == other.data.get()) return false; - return *(this->data) > *(other.data); + bool operator <( const wrapper & other ) const { + if ( this->data.get ( ) == other.data.get ( ) ) return false; + + return * ( this->data ) < * ( other.data ); } - bool operator<(const wrapper& other) const { - if(this->data.get() == other.data.get()) return false; - return *(this->data) < *(other.data); + bool operator !=( const wrapper & other ) const { + if ( this->data.get ( ) == other.data.get ( ) ) return false; + + return * ( this->data ) != * ( other.data ); } - bool operator!=(const wrapper& other) const { - if(this->data.get() == other.data.get()) return false; - return *(this->data) != *(other.data); + bool operator ==( const wrapper & other ) const { + if ( this->data.get ( ) == other.data.get ( ) ) return true; + + return * ( this->data ) == * ( other.data ); } - bool operator==(const wrapper& other) const { - if(this->data.get() == other.data.get()) return true; - return *(this->data) == *(other.data); + int compare ( const wrapper & other ) const { + if ( this->data.get ( ) == other.data.get ( ) ) return 0; + + return ( * this->data ).compare ( * other.data ); } - friend std::ostream& operator<<(std::ostream& os, const wrapper& instance) { - os << *(instance.data); + friend std::ostream & operator <<( std::ostream & os, const wrapper & instance ) { + os << * ( instance.data ); return os; } - explicit operator std::string () const { - return (std::string) *data; + explicit operator std::string ( ) const { + return ( std::string ) * data; } }; } /* namespace alib */ #endif /* WRAPPER_H_ */ -