summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/CMakeLists.txt2
-rw-r--r--src/message.h1
-rw-r--r--src/storage.cpp52
-rw-r--r--src/time.cpp35
-rw-r--r--src/uuid.cpp31
5 files changed, 69 insertions, 52 deletions
diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt
index d6d5441..64c14b5 100644
--- a/src/CMakeLists.txt
+++ b/src/CMakeLists.txt
@@ -10,4 +10,6 @@ add_library(erebos
pubkey
service
storage
+ time
+ uuid
)
diff --git a/src/message.h b/src/message.h
index 48487ba..7e0f597 100644
--- a/src/message.h
+++ b/src/message.h
@@ -3,6 +3,7 @@
#include <erebos/identity.h>
#include <erebos/message.h>
#include <erebos/storage.h>
+#include <erebos/time.h>
#include <mutex>
#include <vector>
diff --git a/src/storage.cpp b/src/storage.cpp
index 49bac54..81a70e1 100644
--- a/src/storage.cpp
+++ b/src/storage.cpp
@@ -535,58 +535,6 @@ const Storage & Ref::storage() const
}
-ZonedTime::ZonedTime(string str)
-{
- intmax_t t;
- unsigned int h, m;
- char sign[2];
- if (sscanf(str.c_str(), "%jd %1[+-]%2u%2u", &t, sign, &h, &m) != 4)
- throw runtime_error("invalid zoned time");
-
- time = std::chrono::system_clock::time_point(std::chrono::seconds(t));
- zone = std::chrono::minutes((sign[0] == '-' ? -1 : 1) * (60 * h + m));
-}
-
-ZonedTime::operator string() const
-{
- char buf[32];
- unsigned int az = std::chrono::abs(zone).count();
- snprintf(buf, sizeof(buf), "%jd %c%02u%02u",
- (intmax_t) std::chrono::duration_cast<std::chrono::seconds>(time.time_since_epoch()).count(),
- zone < decltype(zone)::zero() ? '-' : '+', az / 60, az % 60);
- return string(buf);
-}
-
-ZonedTime ZonedTime::now()
-{
- return ZonedTime(std::chrono::system_clock::now());
-}
-
-
-UUID::UUID(string str)
-{
- if (uuid_parse(str.c_str(), uuid) != 0)
- throw runtime_error("invalid UUID");
-}
-
-UUID::operator string() const
-{
- string str(UUID_STR_LEN - 1, '\0');
- uuid_unparse_lower(uuid, str.data());
- return str;
-}
-
-bool UUID::operator==(const UUID & other) const
-{
- return std::equal(std::begin(uuid), std::end(uuid), std::begin(other.uuid));
-}
-
-bool UUID::operator!=(const UUID & other) const
-{
- return !(*this == other);
-}
-
-
template<class S>
RecordT<S>::Item::operator bool() const
{
diff --git a/src/time.cpp b/src/time.cpp
new file mode 100644
index 0000000..631e0f8
--- /dev/null
+++ b/src/time.cpp
@@ -0,0 +1,35 @@
+#include <erebos/time.h>
+
+#include <stdexcept>
+
+using namespace erebos;
+
+using std::runtime_error;
+using std::string;
+
+ZonedTime::ZonedTime(string str)
+{
+ intmax_t t;
+ unsigned int h, m;
+ char sign[2];
+ if (sscanf(str.c_str(), "%jd %1[+-]%2u%2u", &t, sign, &h, &m) != 4)
+ throw runtime_error("invalid zoned time");
+
+ time = std::chrono::system_clock::time_point(std::chrono::seconds(t));
+ zone = std::chrono::minutes((sign[0] == '-' ? -1 : 1) * (60 * h + m));
+}
+
+ZonedTime::operator string() const
+{
+ char buf[32];
+ unsigned int az = std::chrono::abs(zone).count();
+ snprintf(buf, sizeof(buf), "%jd %c%02u%02u",
+ (intmax_t) std::chrono::duration_cast<std::chrono::seconds>(time.time_since_epoch()).count(),
+ zone < decltype(zone)::zero() ? '-' : '+', az / 60, az % 60);
+ return string(buf);
+}
+
+ZonedTime ZonedTime::now()
+{
+ return ZonedTime(std::chrono::system_clock::now());
+}
diff --git a/src/uuid.cpp b/src/uuid.cpp
new file mode 100644
index 0000000..e1f044a
--- /dev/null
+++ b/src/uuid.cpp
@@ -0,0 +1,31 @@
+#include <erebos/uuid.h>
+
+#include <stdexcept>
+
+using namespace erebos;
+
+using std::runtime_error;
+using std::string;
+
+UUID::UUID(string str)
+{
+ if (uuid_parse(str.c_str(), uuid) != 0)
+ throw runtime_error("invalid UUID");
+}
+
+UUID::operator string() const
+{
+ string str(UUID_STR_LEN - 1, '\0');
+ uuid_unparse_lower(uuid, str.data());
+ return str;
+}
+
+bool UUID::operator==(const UUID & other) const
+{
+ return std::equal(std::begin(uuid), std::end(uuid), std::begin(other.uuid));
+}
+
+bool UUID::operator!=(const UUID & other) const
+{
+ return !(*this == other);
+}