Add directory missed by silly .gitignore content. master
authorethereal <ethereal@ethv.net>
Fri, 24 Oct 2014 08:06:09 +0000 (01:06 -0700)
committerethereal <ethereal@ethv.net>
Fri, 24 Oct 2014 08:06:09 +0000 (01:06 -0700)
.gitignore
src/core/data_file.hpp [new file with mode: 0644]
src/core/strstream.hpp [new file with mode: 0644]
src/core/typename.hpp [new file with mode: 0644]
src/core/unused.hpp [new file with mode: 0644]

index 6be7d43..cdbd78b 100644 (file)
@@ -1,7 +1,8 @@
 /build
 /btt
+/tmp
 
-core
+/core.*
 
 .vimrc
 .gdb_history
diff --git a/src/core/data_file.hpp b/src/core/data_file.hpp
new file mode 100644 (file)
index 0000000..3f76524
--- /dev/null
@@ -0,0 +1,30 @@
+#ifndef CORE_DATA_FILE_HPP
+#define CORE_DATA_FILE_HPP
+
+#include <string>
+#include <istream>
+#include <fstream>
+
+#ifndef DATA_PATH
+    #define DATA_PATH "data/"
+#endif
+
+namespace core {
+
+class data_file {
+private:
+    std::string m_path;
+    std::ifstream m_last_stream;
+public:
+    data_file(const std::string &subpath) { m_path = DATA_PATH + subpath; }
+
+    std::istream &stream() {
+        m_last_stream.open(m_path.c_str());
+
+        return m_last_stream;
+    }
+};
+
+} // namespace core
+
+#endif
diff --git a/src/core/strstream.hpp b/src/core/strstream.hpp
new file mode 100644 (file)
index 0000000..ba14a39
--- /dev/null
@@ -0,0 +1,24 @@
+#ifndef CORE_STRSTREAM_HPP
+#define CORE_STRSTREAM_HPP
+
+#include <string>
+#include <sstream>
+
+namespace core {
+
+class strstream {
+private:
+    std::ostringstream m_ss;
+public:
+    template<typename T>
+    strstream &operator<<(const T &v) {
+        m_ss << v;
+        return *this;
+    }
+
+    operator std::string() const { return m_ss.str(); }
+};
+
+} // namespace core
+
+#endif
diff --git a/src/core/typename.hpp b/src/core/typename.hpp
new file mode 100644 (file)
index 0000000..4e79a8c
--- /dev/null
@@ -0,0 +1,41 @@
+#ifndef CORE_TYPENAME_HPP
+#define CORE_TYPENAME_HPP
+
+#include <string>
+#include <typeinfo>
+
+#ifdef __GNUG__
+#include <cstdlib>
+#include <memory>
+#include <cxxabi.h>
+#endif
+
+namespace core {
+
+#ifdef __GNUG__
+inline std::string demangle(const char* name) {
+
+    int status = -4; // some arbitrary value to eliminate the compiler warning
+
+    // enable c++11 by passing the flag -std=c++11 to g++
+    std::unique_ptr<char, void(*)(void*)> res {
+        abi::__cxa_demangle(name, NULL, NULL, &status),
+        std::free
+    };
+
+    return (status==0) ? res.get() : name ;
+}
+#else
+std::string demangle(const char* name) {
+    return name;
+}
+#endif
+
+template<typename T>
+inline std::string type_name() {
+    return demangle(typeid(T).name());
+}
+
+} // namespace core
+
+#endif
diff --git a/src/core/unused.hpp b/src/core/unused.hpp
new file mode 100644 (file)
index 0000000..f877918
--- /dev/null
@@ -0,0 +1,6 @@
+#ifndef CORE_UNUSED_HPP
+#define CORE_UNUSED_HPP
+
+#define core_unused __attribute__((unused))
+
+#endif