From 5d07c630077c673b5a7ffaa23fcfb11eefe2136f Mon Sep 17 00:00:00 2001 From: =?utf8?q?David=20=E2=80=98Bombe=E2=80=99=20Roden?= Date: Sun, 6 Jul 2008 05:21:49 +0200 Subject: [PATCH] add tags --- StringTag.cpp | 24 ++++++++++++++++++++++++ StringTag.h | 21 +++++++++++++++++++++ Tag.cpp | 22 ++++++++++++++++++++++ Tag.h | 25 +++++++++++++++++++++++++ TagType.h | 10 ++++++++++ 5 files changed, 102 insertions(+) create mode 100644 StringTag.cpp create mode 100644 StringTag.h create mode 100644 Tag.cpp create mode 100644 Tag.h create mode 100644 TagType.h diff --git a/StringTag.cpp b/StringTag.cpp new file mode 100644 index 0000000..d7482f0 --- /dev/null +++ b/StringTag.cpp @@ -0,0 +1,24 @@ +/** + * © 2008 by David Roden + */ + +#include "StringTag.h" + +#include +#include + +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 index 0000000..9464834 --- /dev/null +++ b/StringTag.h @@ -0,0 +1,21 @@ +/** + * © 2008 by David Roden + */ + +#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 index 0000000..28c6956 --- /dev/null +++ b/Tag.cpp @@ -0,0 +1,22 @@ +/** + * © 2008 by David Roden + */ + +#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 index 0000000..926c58a --- /dev/null +++ b/Tag.h @@ -0,0 +1,25 @@ +/** + * © 2008 by David Roden + */ + +#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 index 0000000..cdfd7ff --- /dev/null +++ b/TagType.h @@ -0,0 +1,10 @@ +/** + * © 2008 by David Roden + */ + +#pragma once + +enum TagType { + String, Blob, Hash, UInt32, UInt16, UInt8, UInt64 +}; + -- 2.7.4