add tags
authorDavid ‘Bombe’ Roden <bombe@pterodactylus.net>
Sun, 6 Jul 2008 03:21:49 +0000 (05:21 +0200)
committerDavid ‘Bombe’ Roden <bombe@pterodactylus.net>
Sun, 6 Jul 2008 03:21:49 +0000 (05:21 +0200)
StringTag.cpp [new file with mode: 0644]
StringTag.h [new file with mode: 0644]
Tag.cpp [new file with mode: 0644]
Tag.h [new file with mode: 0644]
TagType.h [new file with mode: 0644]

diff --git a/StringTag.cpp b/StringTag.cpp
new file mode 100644 (file)
index 0000000..d7482f0
--- /dev/null
@@ -0,0 +1,24 @@
+/**
+ * © 2008 by David Roden <droden@gmail.com>
+ */
+
+#include "StringTag.h"
+
+#include <stdlib.h>
+#include <string.h>
+
+StringTag::StringTag(int id, const char* value): Tag(String, id) {
+       this->value = (char*) malloc(strlen(value) + 1);
+       strcpy(this->value, value);
+}
+
+StringTag::~StringTag() {
+       if (value) {
+               free(value);
+       }
+}
+
+void* StringTag::getValue() {
+       return value;
+}
+
diff --git a/StringTag.h b/StringTag.h
new file mode 100644 (file)
index 0000000..9464834
--- /dev/null
@@ -0,0 +1,21 @@
+/**
+ * © 2008 by David Roden <droden@gmail.com>
+ */
+
+#pragma once
+
+#include "Tag.h"
+
+class StringTag: public Tag {
+
+public:
+       StringTag(int id, const char* value);
+       ~StringTag();
+
+       void* getValue();
+
+private:
+       char* value;
+
+};
+
diff --git a/Tag.cpp b/Tag.cpp
new file mode 100644 (file)
index 0000000..28c6956
--- /dev/null
+++ b/Tag.cpp
@@ -0,0 +1,22 @@
+/**
+ * © 2008 by David Roden <droden@gmail.com>
+ */
+
+#include "Tag.h"
+
+Tag::Tag(TagType type, int id) {
+       this->type = type;
+       this->id = id;
+}
+
+Tag::~Tag() {
+}
+
+TagType Tag::getType() {
+       return type;
+}
+
+int Tag::getId() {
+       return id;
+}
+
diff --git a/Tag.h b/Tag.h
new file mode 100644 (file)
index 0000000..926c58a
--- /dev/null
+++ b/Tag.h
@@ -0,0 +1,25 @@
+/**
+ * © 2008 by David Roden <droden@gmail.com>
+ */
+
+#pragma once
+
+#include "TagType.h"
+
+class Tag {
+
+protected:
+       Tag(TagType type, int id);
+       virtual ~Tag();
+
+public:
+       TagType getType();
+       int getId();
+       virtual void* getValue() = 0;
+
+private:
+       TagType type;
+       int id;
+
+};
+
diff --git a/TagType.h b/TagType.h
new file mode 100644 (file)
index 0000000..cdfd7ff
--- /dev/null
+++ b/TagType.h
@@ -0,0 +1,10 @@
+/**
+ * © 2008 by David Roden <droden@gmail.com>
+ */
+
+#pragma once
+
+enum TagType {
+       String, Blob, Hash, UInt32, UInt16, UInt8, UInt64
+};
+