📄 typeswrapper.h
字号:
#ifndef __Wrapper_H
#define __Wrapper_H
#include <string>
using namespace std;
class IReflection;
template <typename T>
class Type
{
public:
// Operator =
Type<T> operator= (const Type<T>& other)
{
object_ = other.object_;
return *this;
}
Type<T> operator= (const T value)
{
object_ = value;
if (parent_)
parent_->Distribution(this);
return *this;
}
//Type<T> operator= (const char* value)
//{
// object_ = value;
// if (parent_)
// parent_->Distribution(this);
// return *this;
//}
Type<T> operator= (const char* value)
{
bool
result = false
;
object_ptr ptr("dummy",typeid(Type<T>).name(),this)
;
if (!value
) return *this
;
if (parent_)
result = parent_->Get(this,ptr)
;
IConversion*
conversion = ConversionHelper::Instance()->Get(ptr.type());
if (!conversion
) return *this
;
string
value_ = value;
conversion->String2Object(value_,ptr);
if (parent_)
parent_->Distribution(this)
;
return *this;
}
const Type<T>& operator+(const Type<T> &other)
{
object_ += other.object_; // Use += to add other to the copy.
if (parent_)
parent_->Distribution(this);
return *this; // All done!
}
const Type<T>& operator-(const Type<T> &other)
{
object_ -= other.object_; // Use += to add other to the copy.
if (parent_)
parent_->Distribution(this);
return *this; // All done!
}
const Type<T>& operator*(const Type<T> &other)
{
object_ *= other.object_; // Use += to add other to the copy.
if (parent_)
parent_->Distribution(this);
return *this; // All done!
}
const Type<T>& operator/(const Type<T> &other)
{
object_ /= other.object_; // Use /= to add other to the copy.
if (parent_)
parent_->Distribution(this);
return *this; // All done!
}
const Type<T>& operator+=(const Type<T>& other)
{
object_ += other.object_;
if (parent_)
parent_->Distribution(this);
return *this;
}
const Type<T>& operator-=(const Type<T>& other)
{
object_ -= other.object_;
if (parent_)
parent_->Distribution(this);
return *this;
}
bool operator!=(const Type<T> &other) const
{
return !(object_ == other.object_);
}
// bool operator!=(const T other) const
// {
// return !(object_ == other);
// }
bool operator==(const Type<T> &other) const
{
return (object_ == other.object_);
}
// bool operator==(const T other) const
// {
// return (object_ == other);
// }
bool operator<(const Type<T> &other) const
{
return (object_ < other.object_);
}
bool operator>(const Type<T> &other) const
{
return (object_ > other.object_);
}
bool operator==(const T value) const
{
return (object_ == value);
}
bool operator!=(const T value) const
{
return (object_ == value);
}
bool operator<(const T value) const
{
return (object_ < value);
}
bool operator>(const T value) const
{
return (object_ > value);
}
// Constructor
Type () : parent_(null) {};
Type (const Type& other)
{
object_ = other.object_;
}
Type (T value) : object_(value), parent_(null) {}
// Methods
T& Object () { return object_; }
IReflection*& Parent () { return parent_; }
// Destructor
virtual ~Type() {}
private:
// Data
IReflection* parent_;
T object_;
};
typedef Type<int> Int;
typedef Type<long> Long;
typedef Type<double> Double;
typedef Type<bool> Bool;
typedef Type<string> String;
#endif
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -