I'm working on an cross-platform environment for wrapping other libraries, especially because that is helping me to understand C++ and its libraries/extensions, since i'm quite new to the programming language.
I'm creating wrappers for primitive types, so i can give them functions like, eventSerialize(...), eventRepresentate(...), etc. (And because some other reasons).
To save time, I thought of making a template class wrapper for primitives.
I have the following questions:
- Am I doing the references of the operators properly?
- How to make sure they can be casted to each other? (template operator Primitive();)?
- What about all the other operators, I mean, I can find them, but where I can find how I should write them properly with the right syntax (like const / &)?
I hope someone can give me those answers.
#ifndef swift_Int32
#define swift_Int32
#include <boost/cstdint.hpp>
namespace swift
{
template<class T> class Primitive : public Object
{
T data;
public:
Primitive();
Primitive(T&);
Primitive(Primitive<T>&);
Primitive<T>& operator = (const Primitive<T>&);
Primitive<T> operator * (const Primitive<T>& value);
Primitive<T> operator / (const Primitive<T>& value);
Primitive<T> operator + (const Primitive<T>& value);
Primitive<T> operator - (const Primitive<T>& value);
Primitive<T>& operator *= (const Primitive<T>& value);
Primitive<T>& operator /= (const Primitive<T>& value);
Primitive<T>& operator += (const Primitive<T>& value);
Primitive<T>& operator -= (const Primitive<T>& value);
bool operator == (const Primitive<T>&) const;
bool operator != (const Primitive<T>&) const;
bool operator < (const Primitive<T>&) const;
bool operator > (const Primitive<T>&) const;
bool operator <= (const Primitive<T>&) const;
bool operator >= (const Primitive<T>&) const;
};
typedef Primitive<bool> Bool;
typedef Bool Bit;
typedef Primitive<int8_t> Char;
typedef Primitive<uint8_t> Byte;
typedef Primitive<int16_t> Int16;
typedef Primitive<uint16_t> UInt16;
typedef Primitive<int32_t> Int32;
typedef Primitive<uint32_t> UInt32;
typedef Int16 Short;
typedef UInt16 UShort;
typedef Int32 Int;
typedef UInt32 UInt;
}
#endif //swift_Int32