summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorljfa-ag <ljfa-ag@web.de>2015-06-23 21:33:17 +0200
committerljfa-ag <ljfa-ag@web.de>2015-06-23 22:00:28 +0200
commit50d94e7d513f68d25cd5e72de880bb6f78de50e7 (patch)
treedf32393408ee93c067c10f303a3b654a47713d2f
parent669a1c4b24d3993dc29917daa60bb46dd9e4fd3b (diff)
downloadProject-Tick-50d94e7d513f68d25cd5e72de880bb6f78de50e7.tar.gz
Project-Tick-50d94e7d513f68d25cd5e72de880bb6f78de50e7.zip
Add methods and tests to tag_primitive
-rw-r--r--include/tag_primitive.h21
-rw-r--r--test/nbttest.cpp17
2 files changed, 38 insertions, 0 deletions
diff --git a/include/tag_primitive.h b/include/tag_primitive.h
index 3b8ac51237..397ea64da3 100644
--- a/include/tag_primitive.h
+++ b/include/tag_primitive.h
@@ -45,8 +45,11 @@ public:
tag_primitive(T value = 0);
tag_primitive& operator=(T value);
+ void set(T value);
+ operator T&();
operator T() const;
+ T get() const;
tag_type get_type() const noexcept override;
@@ -75,12 +78,30 @@ tag_primitive<T>& tag_primitive<T>::operator=(T val)
}
template<class T>
+void tag_primitive<T>::set(T val)
+{
+ value = val;
+}
+
+template<class T>
+tag_primitive<T>::operator T&()
+{
+ return value;
+}
+
+template<class T>
tag_primitive<T>::operator T() const
{
return value;
}
template<class T>
+T tag_primitive<T>::get() const
+{
+ return value;
+}
+
+template<class T>
tag_type tag_primitive<T>::get_type() const noexcept
{
return type;
diff --git a/test/nbttest.cpp b/test/nbttest.cpp
index 93a31c0375..482e28ab64 100644
--- a/test/nbttest.cpp
+++ b/test/nbttest.cpp
@@ -33,7 +33,24 @@ void test_get_type()
ASSERT(tag_double().get_type() == tag_type::Double);
}
+void test_tag_primitive()
+{
+ tag_int tag(6);
+ ASSERT(tag.get() == 6);
+ int& ref = tag;
+ ref = 12;
+ ASSERT(tag == 12);
+ ASSERT(tag != 6);
+ tag.set(24);
+ ASSERT(ref == 24);
+ tag = 7;
+ ASSERT(7 == static_cast<int>(tag));
+
+ ASSERT(tag_double() == 0.0);
+}
+
int main()
{
test_get_type();
+ test_tag_primitive();
}