aboutsummaryrefslogtreecommitdiff
path: root/src/libjin/Common
diff options
context:
space:
mode:
Diffstat (limited to 'src/libjin/Common')
-rw-r--r--src/libjin/Common/Data.h34
-rw-r--r--src/libjin/Common/Object.cpp32
-rw-r--r--src/libjin/Common/Object.h49
-rw-r--r--src/libjin/Common/Singleton.hpp38
-rw-r--r--src/libjin/Common/Subsystem.hpp43
-rw-r--r--src/libjin/Common/data.h34
-rw-r--r--src/libjin/Common/je_array.hpp123
-rw-r--r--src/libjin/Common/je_common.h6
-rw-r--r--src/libjin/Common/je_exception.cpp0
-rw-r--r--src/libjin/Common/je_exception.h22
-rw-r--r--src/libjin/Common/je_noncopyable.h24
-rw-r--r--src/libjin/Common/je_object.h16
-rw-r--r--src/libjin/Common/je_pool.hpp11
-rw-r--r--src/libjin/Common/je_singleton.hpp80
-rw-r--r--src/libjin/Common/je_stringmap.hpp (renamed from src/libjin/Common/StringMap.hpp)8
-rw-r--r--src/libjin/Common/je_subsystem.hpp78
-rw-r--r--src/libjin/Common/je_temporary.h31
-rw-r--r--src/libjin/Common/je_types.h23
-rw-r--r--src/libjin/Common/je_utf8.cpp (renamed from src/libjin/Common/utf8.cpp)12
-rw-r--r--src/libjin/Common/je_utf8.h34
-rw-r--r--src/libjin/Common/utf8.h31
21 files changed, 458 insertions, 271 deletions
diff --git a/src/libjin/Common/Data.h b/src/libjin/Common/Data.h
deleted file mode 100644
index 4b0f1ba..0000000
--- a/src/libjin/Common/Data.h
+++ /dev/null
@@ -1,34 +0,0 @@
-#ifndef __JIN_COMMON_DATA_H
-#define __JIN_COMMON_DATA_H
-
-
-
-namespace jin
-{
-
- class DataBuffer
- {
- public:
- DataBuffer(int n)
- : len(n)
- {
- buffer = new char[len];
- memset(buffer, 0, len);
- }
- ~DataBuffer()
- {
- delete[] buffer;
- }
- char* operator&()
- {
- return buffer;
- }
-
- private:
- char* buffer;
- int len;
- };
-
-} // jin
-
-#endif \ No newline at end of file
diff --git a/src/libjin/Common/Object.cpp b/src/libjin/Common/Object.cpp
deleted file mode 100644
index 6c3b667..0000000
--- a/src/libjin/Common/Object.cpp
+++ /dev/null
@@ -1,32 +0,0 @@
-// LOVE
-#include "Object.h"
-
-namespace jin
-{
-
- 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/Object.h b/src/libjin/Common/Object.h
deleted file mode 100644
index 9ac1b5a..0000000
--- a/src/libjin/Common/Object.h
+++ /dev/null
@@ -1,49 +0,0 @@
-#ifndef __JIN_COMMON_OBJECT_H
-#define __JIN_COMMON_OBJECT_H
-
-namespace jin
-{
-
- 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
-
-}
-
-#endif \ No newline at end of file
diff --git a/src/libjin/Common/Singleton.hpp b/src/libjin/Common/Singleton.hpp
deleted file mode 100644
index 48cd5bc..0000000
--- a/src/libjin/Common/Singleton.hpp
+++ /dev/null
@@ -1,38 +0,0 @@
-#ifndef __JIN_SINGLETON_H
-#define __JIN_SINGLETON_H
-
-namespace jin
-{
-
- template<class T>
- class Singleton
- {
- public:
- static T* get()
- {
- if (_instance == nullptr)
- _instance = new T;
- return _instance;
- }
- static void destroy()
- {
- delete _instance;
- _instance = nullptr;
- }
- protected:
- Singleton() {};
- virtual ~Singleton() {};
- static T* _instance;
- private:
- Singleton(const Singleton&);
- Singleton& operator = (const Singleton&);
- };
-
- template<class T> T* Singleton<T>::_instance = nullptr;
-
-#define SINGLETON(T) \
- friend Singleton<T>
-
-} // jin
-
-#endif // __JIN_SINGLETON_H \ No newline at end of file
diff --git a/src/libjin/Common/Subsystem.hpp b/src/libjin/Common/Subsystem.hpp
deleted file mode 100644
index 1374ad1..0000000
--- a/src/libjin/Common/Subsystem.hpp
+++ /dev/null
@@ -1,43 +0,0 @@
-#ifndef __JIN_COMMON_SUBSYSTEM_H
-#define __JIN_COMMON_SUBSYSTEM_H
-
-#include "singleton.hpp"
-#include "../utils/macros.h"
-
-namespace jin
-{
-
- template<class System>
- class Subsystem : public Singleton<System>
- {
- public:
- struct Setting {};
- typedef Setting SettingBase;
-
- bool init(const SettingBase* setting = nullptr)
- {
- static bool success = initSystem(setting);
- return success;
- }
-
- void quit()
- {
- CALLONCE(quitSystem());
- Singleton<System>::destroy();
- }
-
- protected:
-
- Subsystem() {};
- virtual ~Subsystem() {};
-
- SINGLETON(System);
-
- /*onlyonce*/ virtual bool initSystem(const Setting* setting) = 0;
- /*onlyonce*/ virtual void quitSystem() = 0;
-
- };
-
-} // jin
-
-#endif \ No newline at end of file
diff --git a/src/libjin/Common/data.h b/src/libjin/Common/data.h
deleted file mode 100644
index 4b0f1ba..0000000
--- a/src/libjin/Common/data.h
+++ /dev/null
@@ -1,34 +0,0 @@
-#ifndef __JIN_COMMON_DATA_H
-#define __JIN_COMMON_DATA_H
-
-
-
-namespace jin
-{
-
- class DataBuffer
- {
- public:
- DataBuffer(int n)
- : len(n)
- {
- buffer = new char[len];
- memset(buffer, 0, len);
- }
- ~DataBuffer()
- {
- delete[] buffer;
- }
- char* operator&()
- {
- return buffer;
- }
-
- private:
- char* buffer;
- int len;
- };
-
-} // jin
-
-#endif \ No newline at end of file
diff --git a/src/libjin/Common/je_array.hpp b/src/libjin/Common/je_array.hpp
new file mode 100644
index 0000000..361f1f0
--- /dev/null
+++ b/src/libjin/Common/je_array.hpp
@@ -0,0 +1,123 @@
+#ifndef __JE_COMMON_ARRAY_H
+#define __JE_COMMON_ARRAY_H
+
+namespace JinEngine
+{
+
+ ///
+ /// A array created on heap.
+ ///
+ template<typename T>
+ class Array
+ {
+ public:
+ ///
+ /// 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];
+ }
+
+ ///
+ /// 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;
+ this->data = data;
+ this->length = length;
+ }
+
+ ///
+ /// 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] = 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:
+ // Disable new and delete.
+ void* operator new(size_t t);
+ void operator delete(void* ptr);
+
+ T * data;
+ unsigned int length;
+
+ };
+
+} // namespace JinEngine
+
+#endif \ No newline at end of file
diff --git a/src/libjin/Common/je_common.h b/src/libjin/Common/je_common.h
new file mode 100644
index 0000000..0dfa79a
--- /dev/null
+++ b/src/libjin/Common/je_common.h
@@ -0,0 +1,6 @@
+#ifndef __JE_COMMON_H
+#define __JE_COMMON_H
+
+#include "je_array.hpp"
+
+#endif \ No newline at end of file
diff --git a/src/libjin/Common/je_exception.cpp b/src/libjin/Common/je_exception.cpp
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/src/libjin/Common/je_exception.cpp
diff --git a/src/libjin/Common/je_exception.h b/src/libjin/Common/je_exception.h
new file mode 100644
index 0000000..7c66af8
--- /dev/null
+++ b/src/libjin/Common/je_exception.h
@@ -0,0 +1,22 @@
+#ifndef __JE_EXCEPTION_H
+#define __JE_EXCEPTION_H
+
+#include <exception>
+
+namespace JinEngine
+{
+
+ ///
+ /// Built-in exception class.
+ ///
+ class JinException : public std::exception
+ {
+ public:
+ JinException();
+ const char* what() const throw();
+
+ };
+
+} // namespace JinEngine
+
+#endif \ No newline at end of file
diff --git a/src/libjin/Common/je_noncopyable.h b/src/libjin/Common/je_noncopyable.h
new file mode 100644
index 0000000..89a3e68
--- /dev/null
+++ b/src/libjin/Common/je_noncopyable.h
@@ -0,0 +1,24 @@
+#ifndef __JE_NONCOPYABLE_H
+#define __JE_NONCOPYABLE_H
+
+namespace JinEngine
+{
+
+ ///
+ /// Class inherites this could not be copied.
+ ///
+ class Noncopyable
+ {
+ public:
+ Noncopyable(void) { }
+ virtual ~Noncopyable(void) { }
+
+ private:
+ Noncopyable(const Noncopyable& other);
+ Noncopyable& operator=(const Noncopyable& other);
+
+ };
+
+} // namespace JinEngine
+
+#endif \ No newline at end of file
diff --git a/src/libjin/Common/je_object.h b/src/libjin/Common/je_object.h
new file mode 100644
index 0000000..c256879
--- /dev/null
+++ b/src/libjin/Common/je_object.h
@@ -0,0 +1,16 @@
+#ifndef __JE_OBJECT_H
+#define __JE_OBJECT_H
+
+namespace JinEngine
+{
+
+ ///
+ /// Base class of all objects in Jin.
+ ///
+ class Object
+ {
+ };
+
+} // namespace JinEngine
+
+#endif \ No newline at end of file
diff --git a/src/libjin/Common/je_pool.hpp b/src/libjin/Common/je_pool.hpp
new file mode 100644
index 0000000..1107fd5
--- /dev/null
+++ b/src/libjin/Common/je_pool.hpp
@@ -0,0 +1,11 @@
+#ifndef __JE_POOL_H
+#define __JE_POOL_H
+
+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
new file mode 100644
index 0000000..e981e7a
--- /dev/null
+++ b/src/libjin/Common/je_singleton.hpp
@@ -0,0 +1,80 @@
+#ifndef __JE_SINGLETON_H
+#define __JE_SINGLETON_H
+
+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 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;
+
+ ///
+ /// Singleton notation.
+ ///
+ #define singleton(T) friend Singleton<T>
+
+} // namespace JinEngine
+
+#endif // __JE_SINGLETON_H \ No newline at end of file
diff --git a/src/libjin/Common/StringMap.hpp b/src/libjin/Common/je_stringmap.hpp
index bebd94d..43e3e9b 100644
--- a/src/libjin/Common/StringMap.hpp
+++ b/src/libjin/Common/je_stringmap.hpp
@@ -1,7 +1,7 @@
-#ifndef __JIN_COMMON_SREINGMAP_H
-#define __JIN_COMMON_SREINGMAP_H
+#ifndef __JE_COMMON_SREINGMAP_H
+#define __JE_COMMON_SREINGMAP_H
-namespace jin
+namespace JinEngine
{
template<typename T, unsigned SIZE>
@@ -138,6 +138,6 @@ namespace jin
}; // StringMap
-}
+} // namespace JinEngine
#endif \ No newline at end of file
diff --git a/src/libjin/Common/je_subsystem.hpp b/src/libjin/Common/je_subsystem.hpp
new file mode 100644
index 0000000..d8e106d
--- /dev/null
+++ b/src/libjin/Common/je_subsystem.hpp
@@ -0,0 +1,78 @@
+#ifndef __JE_COMMON_SUBSYSTEM_H
+#define __JE_COMMON_SUBSYSTEM_H
+
+#include "../utils/je_macros.h"
+
+#include "je_singleton.hpp"
+
+namespace JinEngine
+{
+
+ ///
+ /// Subsystem class.
+ ///
+ template<class System>
+ class Subsystem : public Singleton<System>
+ {
+ public:
+ ///
+ /// 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.
+ static char __dummy__ = (quitSystem(), 1);
+ Singleton<System>::destroy();
+ }
+
+ protected:
+ singleton(System);
+
+ ///
+ /// Subsystem constructor.
+ ///
+ Subsystem() {};
+
+ ///
+ /// Subsystem destructor.
+ ///
+ virtual ~Subsystem()
+ {
+ };
+
+ ///
+ /// Initializer callback.
+ ///
+ virtual bool initSystem(const Setting* setting) = 0;
+
+ ///
+ /// Quit subsystem callback.
+ ///
+ virtual void quitSystem() = 0;
+
+ };
+
+} // namespace JinEngine
+
+#endif \ No newline at end of file
diff --git a/src/libjin/Common/je_temporary.h b/src/libjin/Common/je_temporary.h
new file mode 100644
index 0000000..5af8704
--- /dev/null
+++ b/src/libjin/Common/je_temporary.h
@@ -0,0 +1,31 @@
+#ifndef __JE_ON_STACK_H
+#define __JE_ON_STACK_H
+
+namespace JinEngine
+{
+
+ ///
+ /// Class inherites this clound only be created on stack or static zone.
+ ///
+ class Temporary
+ {
+ public:
+ Temporary() {};
+ virtual ~Temporary() {};
+/*
+ protected:
+ void operator delete(void* t)
+ {
+ if(t != nullptr)
+ free(t);
+ }
+*/
+ private:
+ // Disable new operands.
+ void* operator new(size_t);
+
+ };
+
+} // namespace JinEngine
+
+#endif \ No newline at end of file
diff --git a/src/libjin/Common/je_types.h b/src/libjin/Common/je_types.h
new file mode 100644
index 0000000..446c413
--- /dev/null
+++ b/src/libjin/Common/je_types.h
@@ -0,0 +1,23 @@
+#ifndef __JE_TYPES_H
+#define __JE_TYPES_H
+#include <stdint.h>
+
+namespace JinEngine
+{
+
+ 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/utf8.cpp b/src/libjin/Common/je_utf8.cpp
index bef6c85..bd7ce94 100644
--- a/src/libjin/Common/utf8.cpp
+++ b/src/libjin/Common/je_utf8.cpp
@@ -1,9 +1,9 @@
-#include "../modules.h"
-#if JIN_OS == JIN_WINDOWS
+#include "../core/je_configuration.h"
+#if jin_os == jin_os_windows
-#include "utf8.h"
+#include "je_utf8.h"
-namespace jin
+namespace JinEngine
{
std::string to_utf8(LPCWSTR wstr)
@@ -37,6 +37,6 @@ namespace jin
}
}
-} // jin
+} // namespace JinEngine
-#endif // JIN_OS == JIN_WINDOWS \ No newline at end of file
+#endif // jin_os == jin_os_windows \ No newline at end of file
diff --git a/src/libjin/Common/je_utf8.h b/src/libjin/Common/je_utf8.h
new file mode 100644
index 0000000..a11850c
--- /dev/null
+++ b/src/libjin/Common/je_utf8.h
@@ -0,0 +1,34 @@
+#ifndef __JE_COMMON_UTF8_H
+#define __JE_COMMON_UTF8_H
+
+#include "../core/je_configuration.h"
+#if jin_os == jin_os_windows
+
+#include <string>
+#include <windows.h>
+
+namespace JinEngine
+{
+
+ ///
+ /// 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.
+ ///
+ void replace_char(std::string & str, char find, char replace);
+
+} // namespace JinEngine
+
+#endif // jin_os == jin_os_windows
+
+#endif // __JE_COMMON_UTF8_H \ No newline at end of file
diff --git a/src/libjin/Common/utf8.h b/src/libjin/Common/utf8.h
deleted file mode 100644
index 7f26841..0000000
--- a/src/libjin/Common/utf8.h
+++ /dev/null
@@ -1,31 +0,0 @@
-#ifndef __JIN_COMMON_UTF8_H
-#define __JIN_COMMON_UTF8_H
-
-#include "../modules.h"
-#if JIN_OS == JIN_WINDOWS
-
-#include <string>
-#include <windows.h>
-
-namespace jin
-{
-
- /**
- * 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.
- **/
- void replace_char(std::string & str, char find, char replace);
-
-}
-
-#endif // JIN_OS == JIN_WINDOWS
-#endif // __JIN_COMMON_UTF8_H \ No newline at end of file