#ifndef __JLANG_JSTATIC__ #define __JLANG_JSTATIC__ #include #include #include "JLang/JClass.hh" #include "JLang/JEquals.hh" namespace JLANG {} namespace JPP { using namespace JLANG; } namespace JLANG { /** * Template data structure for static member declaration. */ template struct JStatic : public JEquals, T> { typedef typename JClass::argument_type argument_type; /** * Constructor. * * \param value value */ JStatic(argument_type value) { this->value = value; } /** * Assignment operator * * \param value value * \return this value */ JStatic& operator=(argument_type value) { this->value = value; return *this; } /** * Type conversion operator. * * \return value */ operator const T& () const { return value; } /** * Type conversion operator. * * \return value */ operator T& () { return value; } /** * Smart pointer. * * \return value */ const T* operator->() const { return &value; } /** * Smart pointer. * * \return value */ T* operator->() { return &value; } /** * Equals method. * * \param object object * \return true if this object equals given object; else false */ bool equals(const JStatic& object) const { return this->value == object.value; } /** * Equals method. * * \param value value * \return true if this value equals given value; else false */ bool equals(argument_type value) const { return this->value == value; } /** * Read static object from input stream. * * \param in input stream * \param object object * \return input stream */ friend inline std::istream& operator>>(std::istream& in, JStatic& object) { return in >> object.value; } /** * Write static object to output stream. * * \param out output stream * \param object object * \return output stream */ friend inline std::ostream& operator<<(std::ostream& out, const JStatic& object) { return out << object.value; } protected: static T value; }; /** * Declaration of static data member. */ template T JStatic::value; /** * Template specialisation of JStatic for static member declaration of pointer. */ template struct JStatic : public JEquals, T*> { typedef typename JClass::argument_type argument_type; /** * Assignment operator * * \param value value * \return this value */ JStatic& operator=(argument_type value) { this->value = value; return *this; } /** * Smart pointer. * * \return value */ const T* operator->() const { return value; } /** * Smart pointer. * * \return value */ T* operator->() { return value; } /** * Equals method. * * \param object object * \return true if this object equals given object; else false */ bool equals(const JStatic& object) const { return this->value == object.value; } /** * Equals method. * * \param value value * \return true if this value equals given value; else false */ bool equals(argument_type value) const { return this->value == value; } protected: static T* value; }; /** * Declaration of static data member. */ template T* JStatic::value; } /** * Static data member declaration. * * \param TYPE data type */ #define STATIC_DATA_MEMBER(TYPE) static JLANG::JStatic #endif