-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
3c7eeae
commit 604bf02
Showing
47 changed files
with
742 additions
and
324 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
/* vim: set tabstop=4 shiftwidth=4 softtabstop=4 expandtab smarttab : */ | ||
/** | ||
* @file {file} | ||
* @author Soo Han, Kim (princeb612.kr@gmail.com) | ||
* @desc | ||
* | ||
* Revision History | ||
* Date Name Description | ||
* | ||
*/ | ||
|
||
#ifndef __HOTPLACE_SDK_BASE_BASIC_NOSTD_CONTAINER__ | ||
#define __HOTPLACE_SDK_BASE_BASIC_NOSTD_CONTAINER__ | ||
|
||
#include <deque> | ||
#include <functional> | ||
#include <map> | ||
#include <sdk/base/error.hpp> | ||
#include <sdk/base/stl.hpp> | ||
#include <sdk/base/stream/basic_stream.hpp> | ||
#include <sdk/base/syntax.hpp> | ||
#include <sdk/base/types.hpp> | ||
|
||
namespace hotplace { | ||
|
||
template <typename container_t> | ||
void for_each(const container_t& c, typename std::function<void(typename container_t::const_iterator, int)> f) { | ||
if (c.size()) { | ||
auto iter = c.begin(); | ||
f(iter++, 0); | ||
while (c.end() != iter) { | ||
f(iter++, 1); | ||
} | ||
f(c.end(), 2); | ||
} | ||
} | ||
|
||
template <typename container_t, typename stream_type> | ||
void print(const container_t& c, stream_type& s) { | ||
for_each<container_t>(c, [&](typename container_t::const_iterator iter, int where) -> void { | ||
switch (where) { | ||
case 0: | ||
s << "[" << *iter; | ||
break; | ||
case 1: | ||
s << ", " << *iter; | ||
break; | ||
case 2: | ||
s << "]"; | ||
break; | ||
} | ||
}); | ||
} | ||
|
||
} // namespace hotplace | ||
|
||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,121 @@ | ||
/* vim: set tabstop=4 shiftwidth=4 softtabstop=4 expandtab smarttab : */ | ||
/** | ||
* @file {file} | ||
* @author Soo Han, Kim (princeb612.kr@gmail.com) | ||
* @desc | ||
* | ||
* Revision History | ||
* Date Name Description | ||
* | ||
*/ | ||
|
||
#ifndef __HOTPLACE_SDK_BASE_BASIC_NOSTD_VECTOR__ | ||
#define __HOTPLACE_SDK_BASE_BASIC_NOSTD_VECTOR__ | ||
|
||
#include <sdk/base/stl.hpp> | ||
#include <sdk/base/syntax.hpp> | ||
#include <sdk/base/types.hpp> | ||
|
||
namespace hotplace { | ||
|
||
/** | ||
* @brief vector | ||
* @refer Data Structures and Algorithm Analysis in C++ - 3 Lists, Stacks, and Queues | ||
*/ | ||
template <typename T> | ||
class t_vector { | ||
public: | ||
explicit t_vector(size_t size = 0) : _size(size), _capacity(size + const_vector_spare) { _items = new T[_capacity]; } | ||
t_vector(const t_vector& rhs) : _size(rhs._size), _capacity(rhs._capacity), _items(nullptr) { | ||
_items = new T[_capacity]; | ||
for (size_t i = 0; i < _size; i++) { | ||
_items[i] = rhs._items[i]; | ||
} | ||
} | ||
t_vector(t_vector&& rhs) : _size(rhs._size), _capacity(rhs._capacity), _items(rhs._items) { | ||
rhs._items = nullptr; | ||
rhs.clear(); | ||
} | ||
~t_vector() { clear(); } | ||
|
||
t_vector& operator=(const t_vector& rhs) { | ||
t_vector o = rhs; | ||
std::swap(*this, o); | ||
return *this; | ||
} | ||
t_vector& operator=(t_vector&& rhs) { | ||
clear(); | ||
_size = rhs._size; | ||
_capacity = rhs._capacity; | ||
_items = rhs._items; | ||
rhs._items = nullptr; | ||
rhs._size = 0; | ||
rhs._capacity = 0; | ||
return *this; | ||
} | ||
void resize(size_t size) { | ||
if (size > _capacity) { | ||
reserve(size << 1); | ||
} | ||
_size = size; | ||
} | ||
void reserve(size_t capacity) { | ||
if (capacity >= _size) { | ||
T* items = new T[capacity]; | ||
for (size_t i = 0; i < _size; ++i) { | ||
items[i] = std::move(_items[i]); | ||
} | ||
_capacity = capacity; | ||
std::swap(items, _items); | ||
delete[] items; | ||
} | ||
} | ||
T& operator[](size_t index) { return _items[index]; } | ||
const T& operator[](size_t index) const { return _items[index]; } | ||
bool empty() const { return 0 == size(); } | ||
size_t size() const { return _size; } | ||
int capacity() const { return _capacity; } | ||
|
||
void push_back(const T& x) { | ||
if (_size == _capacity) { | ||
reserve((_capacity << 1) + 1); | ||
} | ||
_items[_size++] = x; | ||
} | ||
void push_back(T&& x) { | ||
if (_size == _capacity) { | ||
reserve((_capacity << 1) + 1); | ||
} | ||
_items[_size++] = std::move(x); | ||
} | ||
void pop_back() { --_size; } | ||
const T& back() const { return _items[_size - 1]; } | ||
|
||
void clear() { | ||
if (_items) { | ||
delete[] _items; | ||
_items = nullptr; | ||
} | ||
_size = 0; | ||
_capacity = 0; | ||
} | ||
|
||
typedef T* iterator; | ||
typedef const T* const_iterator; | ||
|
||
T* begin() { return &_items[0]; } | ||
T* end() { return &_items[size()]; } | ||
const T* begin() const { return &_items[0]; } | ||
const T* end() const { return &_items[size()]; } | ||
|
||
private: | ||
size_t _size; | ||
size_t _capacity; | ||
T* _items; | ||
|
||
static const size_t const_vector_spare = 16; | ||
}; | ||
|
||
} // namespace hotplace | ||
|
||
#endif |
Oops, something went wrong.