aboutsummaryrefslogtreecommitdiff
path: root/src/libjin/Common
diff options
context:
space:
mode:
Diffstat (limited to 'src/libjin/Common')
-rw-r--r--src/libjin/Common/je_array.hpp77
-rw-r--r--src/libjin/Common/je_object.cpp32
-rw-r--r--src/libjin/Common/je_object.h49
-rw-r--r--src/libjin/Common/je_singleton.hpp49
-rw-r--r--src/libjin/Common/je_subsystem.hpp44
-rw-r--r--src/libjin/Common/je_types.h24
-rw-r--r--src/libjin/Common/je_utf8.cpp2
-rw-r--r--src/libjin/Common/je_utf8.h27
8 files changed, 170 insertions, 134 deletions
diff --git a/src/libjin/Common/je_array.hpp b/src/libjin/Common/je_array.hpp
index 473bae8..361f1f0 100644
--- a/src/libjin/Common/je_array.hpp
+++ b/src/libjin/Common/je_array.hpp
@@ -3,77 +3,114 @@
namespace JinEngine
{
- /* ԶͷŶڴջϴĶ̬ */
+
+ ///
+ /// A array created on heap.
+ ///
template<typename T>
class Array
{
public:
- Array() : length(0), data(nullptr) {}
+ ///
+ /// Array constructor.
+ ///
+ Array()
+ : length(0)
+ , data(nullptr)
+ {
+ }
+ ///
+ /// Array constructor.
+ ///
+ /// @param l Length of array.
+ ///
Array(int l)
{
length = l;
data = new T[l];
}
+ ///
+ /// Array destructor.
+ ///
~Array()
{
delete[] data;
length = 0;
}
+ ///
+ /// Get address of data.
+ ///
+ /// @return Address of data.
+ ///
T* operator &()
{
return data;
}
+ ///
+ /// Get specific element of array.
+ ///
+ /// @return Element of array.
+ ///
T& operator[](int index)
{
return data[index];
}
- /* ڴ */
- void bind(T* d, int len)
+ ///
+ /// Bind data with given data.
+ ///
+ /// @param data Data pointer.
+ /// @param length Length of data.
+ ///
+ void bind(T* data, int length)
{
if (data != nullptr)
delete data;
- data = d;
- length = len;
+ this->data = data;
+ this->length = length;
}
- void add(T v)
+ ///
+ /// Add an element.
+ ///
+ /// @param v Value of element.
+ ///
+ void add(T value)
{
int len = length + 1;
T* d = new T[len];
memcpy(d, data, size());
- d[length] = v;
+ d[length] = value;
bind(d, len);
}
+ ///
+ /// Get size of data in byte.
+ ///
+ /// @return Size of data in byte.
+ ///
int size()
{
return sizeof(T) * length;
}
+ ///
+ /// Get length of data.
+ ///
+ /// @return Count of data.
+ ///
int count()
{
return length;
}
private:
- ///
- /// http://blog.jobbole.com/106923/
- /// new ڴ洴
- /// 1. new ڴ
- /// 2. ù캯
- ///
- /// new, deleteڷͷڴ棬
- ///
+ // Disable new and delete.
void* operator new(size_t t);
-
- ///
- /// Disable delete.
- ///
void operator delete(void* ptr);
T * data;
diff --git a/src/libjin/Common/je_object.cpp b/src/libjin/Common/je_object.cpp
deleted file mode 100644
index 69e4a56..0000000
--- a/src/libjin/Common/je_object.cpp
+++ /dev/null
@@ -1,32 +0,0 @@
-// LOVE
-#include "je_object.h"
-
-namespace JinEngine
-{
-
- Object::Object()
- : count(1)
- {
- }
-
- Object::~Object()
- {
- }
-
- int Object::getReferenceCount() const
- {
- return count;
- }
-
- void Object::retain()
- {
- ++count;
- }
-
- void Object::release()
- {
- if (--count <= 0)
- delete this;
- }
-
-} // love
diff --git a/src/libjin/Common/je_object.h b/src/libjin/Common/je_object.h
deleted file mode 100644
index ca17586..0000000
--- a/src/libjin/Common/je_object.h
+++ /dev/null
@@ -1,49 +0,0 @@
-#ifndef __JE_COMMON_OBJECT_H
-#define __JE_COMMON_OBJECT_H
-
-namespace JinEngine
-{
-
- class Object
- {
- private:
-
- // The reference count.
- int count;
-
- public:
-
- /**
- * Constructor. Sets reference count to one.
- **/
- Object();
-
- /**
- * Destructor.
- **/
- virtual ~Object() = 0;
-
- /**
- * Gets the reference count of this Object.
- * @returns The reference count.
- **/
- int getReferenceCount() const;
-
- /**
- * Retains the Object, i.e. increases the
- * reference count by one.
- **/
- void retain();
-
- /**
- * Releases one reference to the Object, i.e. decrements the
- * reference count by one, and potentially deletes the Object
- * if there are no more references.
- **/
- void release();
-
- }; // Object
-
-} // namespace JinEngine
-
-#endif \ No newline at end of file
diff --git a/src/libjin/Common/je_singleton.hpp b/src/libjin/Common/je_singleton.hpp
index f37f3af..e981e7a 100644
--- a/src/libjin/Common/je_singleton.hpp
+++ b/src/libjin/Common/je_singleton.hpp
@@ -4,33 +4,76 @@
namespace JinEngine
{
+ ///
+ /// Singleton base class.
+ ///
template<class T>
class Singleton
{
public:
+ ///
+ /// Get singleton.
+ ///
+ /// @param Singleton instance of class.
+ ///
static T* get()
{
if (_instance == nullptr)
_instance = new T;
return _instance;
}
+
+ ///
+ /// Destroy instance of singleton.
+ ///
static void destroy()
{
delete _instance;
_instance = nullptr;
}
+
protected:
+ ///
+ /// Singleton constructor.
+ ///
Singleton() {};
+
+ ///
+ /// Singleton destructor.
+ ///
virtual ~Singleton() {};
+
+ ///
+ /// Singleton instance.
+ ///
static T* _instance;
+
private:
- Singleton(const Singleton&);
- Singleton& operator = (const Singleton&);
+ ///
+ /// Singleton copy constructor.
+ ///
+ /// @param singleton Singleton of class.
+ ///
+ Singleton(const Singleton& singleton);
+
+ ///
+ /// Singleton assignment.
+ ///
+ /// @param singleton Singleton of class.
+ ///
+ Singleton& operator = (const Singleton& singleton);
+
};
+ ///
+ /// Singleton instance.
+ ///
template<class T> T* Singleton<T>::_instance = nullptr;
-#define singleton(T) friend Singleton<T>
+ ///
+ /// Singleton notation.
+ ///
+ #define singleton(T) friend Singleton<T>
} // namespace JinEngine
diff --git a/src/libjin/Common/je_subsystem.hpp b/src/libjin/Common/je_subsystem.hpp
index 4966a9d..d8e106d 100644
--- a/src/libjin/Common/je_subsystem.hpp
+++ b/src/libjin/Common/je_subsystem.hpp
@@ -8,22 +8,40 @@
namespace JinEngine
{
+ ///
+ /// Subsystem class.
+ ///
template<class System>
class Subsystem : public Singleton<System>
{
public:
- struct Setting {};
+ ///
+ /// Subsystem setting.
+ ///
+ struct Setting
+ {
+ };
+
typedef Setting SettingBase;
+ ///
+ /// Initialize subsystem.
+ ///
+ /// @param setting Subsystem setting.
+ /// @return True if initialize sucessful, otherwise return false.
+ ///
bool init(const SettingBase* setting = nullptr)
{
static bool success = initSystem(setting);
return success;
}
+ ///
+ /// Quit subsystem.
+ ///
void quit()
{
- /*call only once*/
+ // Call only once.
static char __dummy__ = (quitSystem(), 1);
Singleton<System>::destroy();
}
@@ -31,11 +49,27 @@ namespace JinEngine
protected:
singleton(System);
+ ///
+ /// Subsystem constructor.
+ ///
Subsystem() {};
- virtual ~Subsystem() {};
- /*onlyonce*/ virtual bool initSystem(const Setting* setting) = 0;
- /*onlyonce*/ virtual void quitSystem() = 0;
+ ///
+ /// Subsystem destructor.
+ ///
+ virtual ~Subsystem()
+ {
+ };
+
+ ///
+ /// Initializer callback.
+ ///
+ virtual bool initSystem(const Setting* setting) = 0;
+
+ ///
+ /// Quit subsystem callback.
+ ///
+ virtual void quitSystem() = 0;
};
diff --git a/src/libjin/Common/je_types.h b/src/libjin/Common/je_types.h
index 7e7ad21..446c413 100644
--- a/src/libjin/Common/je_types.h
+++ b/src/libjin/Common/je_types.h
@@ -4,20 +4,20 @@
namespace JinEngine
{
- namespace common
- {
- typedef int8_t int8;
- typedef uint8_t uint8;
- typedef uint8 byte;
- typedef int16_t int16;
- typedef uint16_t uint16;
- typedef int32_t int32;
- typedef uint32_t uint32;
- typedef int64_t int64;
- typedef uint64_t uint64;
+ typedef int8_t int8; ///< Signed integer with a size of 8 bits. Supports values from -128 to 127
+ typedef uint8_t uint8; ///< Unsigned integer with a size of 8 bits. Supports values from 0 to 255.
+ typedef uint8 byte; ///< Unsigned integer with 8 bits (1 byte). Supports 256 values from 0 to 255.
+ typedef int16_t int16; ///< Signed integer with a size of 16 bits. Supports values from -32768 to 32767
+ typedef uint16_t uint16; ///< Unsigned integer with a size of 16 bits. Supports values from 0 to 65535.
+ typedef int32_t int32; ///< Signed integer with a size of 32 bits. Supports values from -2147483648 to 2147483647.
+ typedef uint32_t uint32; ///< Unsigned integer with a size of 32 bits. Supports values from 0 to 4294967295, (2^32 - 1).
+ typedef int64_t int64; ///< Signed integer with a size of 64 bits. Supports values from -(2^63) to (2^63 - 1).
+ typedef uint64_t uint64; ///< Unsigned integer with a size of 64 bits, Supports values from 0 to (2^64 - 1).
+
+ typedef uint32_t uint;
+ typedef int32_t sint;
- }
}
#endif \ No newline at end of file
diff --git a/src/libjin/Common/je_utf8.cpp b/src/libjin/Common/je_utf8.cpp
index b2c1d31..012bf5e 100644
--- a/src/libjin/Common/je_utf8.cpp
+++ b/src/libjin/Common/je_utf8.cpp
@@ -39,4 +39,4 @@ namespace JinEngine
} // namespace JinEngine
-#endif // LIBJIN_OS == LIBJIN_WINDOWS
+#endif // LIBJIN_OS == LIBJIN_WINDOWS \ No newline at end of file
diff --git a/src/libjin/Common/je_utf8.h b/src/libjin/Common/je_utf8.h
index 9fdff10..72a11af 100644
--- a/src/libjin/Common/je_utf8.h
+++ b/src/libjin/Common/je_utf8.h
@@ -10,22 +10,25 @@
namespace JinEngine
{
- /**
- * Convert the wide string to a UTF-8 encoded string.
- * @param wstr The wide-char string.
- * @return A UTF-8 string.
- **/
+ ///
+ /// Convert the wide string to a UTF-8 encoded string.
+ ///
+ /// @param wstr The wide-char string.
+ /// @return A UTF-8 string.
+ ///
std::string to_utf8(LPCWSTR wstr);
- /**
- * Replace all occurences of 'find' with 'replace' in a string.
- * @param str The string to modify.
- * @param find The character to match.
- * @param replace The character to replace matches.
- **/
+ ///
+ /// Replace all occurences of 'find' with 'replace' in a string.
+ ///
+ /// @param str The string to modify.
+ /// @param find The character to match.
+ /// @param replace The character to replace matches.
+ ///
void replace_char(std::string & str, char find, char replace);
} // namespace JinEngine
#endif // LIBJIN_OS == LIBJIN_WINDOWS
-#endif // __JE_COMMON_UTF8_H
+
+#endif // __JE_COMMON_UTF8_H \ No newline at end of file