From 962f3ff2ff245c2214476969ec887589f7bcbf3c Mon Sep 17 00:00:00 2001 From: q66 Date: Mon, 6 Apr 2015 00:05:21 +0100 Subject: [PATCH] initial code --- COPYING.md | 30 ++++++++++++++++++++++++++++++ README.md | 5 ++++- octastd/new.h | 36 ++++++++++++++++++++++++++++++++++++ octastd/vector.h | 33 +++++++++++++++++++++++++++++++++ 4 files changed, 103 insertions(+), 1 deletion(-) create mode 100644 COPYING.md create mode 100644 octastd/new.h create mode 100644 octastd/vector.h diff --git a/COPYING.md b/COPYING.md new file mode 100644 index 0000000..5ef1ee0 --- /dev/null +++ b/COPYING.md @@ -0,0 +1,30 @@ +OctaSTD is licensed under the University of Illinois/NCSA Open Source License, +a permissive, non-copyleft, BSD style license. The license text goes as follows: + +Copyright (c) 2015 Daniel "q66" Kolesa. All rights reserved. + +Permission is hereby granted, free of charge, to any person obtaining a copy of +this software and associated documentation files (the "Software"), to deal with +the Software without restriction, including without limitation the rights to +use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies +of the Software, and to permit persons to whom the Software is furnished to do +so, subject to the following conditions: + +* Redistributions of source code must retain the above copyright notice, + this list of conditions and the following disclaimers. + +* Redistributions in binary form must reproduce the above copyright notice, + this list of conditions and the following disclaimers in the + documentation and/or other materials provided with the distribution. + +* Neither the names of OctaSTD developers nor any contributors may be + used to endorse or promote products derived from this Software without + specific prior written permission. + +**THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS +FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +CONTRIBUTORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS WITH THE +SOFTWARE.** \ No newline at end of file diff --git a/README.md b/README.md index b165102..698a5f6 100644 --- a/README.md +++ b/README.md @@ -3,4 +3,7 @@ OctaSTD is a collection of C++ utilities to aid the upcoming OctaForge C++ API. It provides containers (dynamic arrays etc) as well as other utilities. -Currently implemented: \ No newline at end of file +Currently implemented: + +* new/delete operators +* vector \ No newline at end of file diff --git a/octastd/new.h b/octastd/new.h new file mode 100644 index 0000000..bd9c588 --- /dev/null +++ b/octastd/new.h @@ -0,0 +1,36 @@ +/* Default new/delete operator overloads for OctaSTD. + * + * This file is part of OctaSTD. See COPYING.txt for futher information. + */ + +#ifndef OCTASTD_NEW_H +#define OCTASTD_NEW_H + +#include + +inline void *operator new(size_t size) { + void *p = malloc(size); + if (!p) abort(); + return p; +} + +inline void *operator new[](size_t size) { + void *p = malloc(size); + if (!p) abort(); + return p; +} + +inline void operator delete(void *p) { + free(p); +} + +inline void operator delete[](void *p) { + free(p); +} + +inline void *operator new (size_t, void *p) { return p; } +inline void *operator new [](size_t, void *p) { return p; } +inline void operator delete (void *, void *) {} +inline void operator delete[](void *, void *) {} + +#endif \ No newline at end of file diff --git a/octastd/vector.h b/octastd/vector.h new file mode 100644 index 0000000..b26dd85 --- /dev/null +++ b/octastd/vector.h @@ -0,0 +1,33 @@ +/* Self-expanding dynamic array implementation for OctaSTD. + * + * This file is part of OctaSTD. See COPYING.txt for futher information. + */ + +#ifndef OCTASTD_VECTOR_H +#define OCTASTD_VECTOR_H + +#include + +namespace octastd { + template + class vector { + T *buf; + size_t length, capacity; + + public: + explicit vector(): buf(NULL), length(0), capacity(0) {} + + vector(const vector &v): buf(NULL), length(0), capacity(0) { + *this = v; + } + + ~vector() { + } + + vector &operator=(const vector &v) { + return *this; + } + }; +} + +#endif \ No newline at end of file