Index: ext/libicpf/src/err_codes.h =================================================================== diff -u -re17c80d36eaa0430313e7d1058aa7a301d1510af -r2909ac3cba8d0ad71d8cd3f53e259b68e0569516 --- ext/libicpf/src/err_codes.h (.../err_codes.h) (revision e17c80d36eaa0430313e7d1058aa7a301d1510af) +++ ext/libicpf/src/err_codes.h (.../err_codes.h) (revision 2909ac3cba8d0ad71d8cd3f53e259b68e0569516) @@ -96,4 +96,10 @@ /// Error in converting a hex string to the binary data #define CE_HEX2BIN (CE_BASE+0x0000) +///////////////////////////////////////////////////////////////////// +// container related +#define CO_BASE 0x00040000 +/// Index specified is out of acceptable range +#define CO_OUTOFRANGE (CO_BASE+0x0000) + #endif Index: ext/libicpf/src/vector.cpp =================================================================== diff -u --- ext/libicpf/src/vector.cpp (revision 0) +++ ext/libicpf/src/vector.cpp (revision 2909ac3cba8d0ad71d8cd3f53e259b68e0569516) @@ -0,0 +1,80 @@ +#include "vector.h" +#include "err_codes.h" +#include +#include "exception.h" + +BEGIN_ICPF_NAMESPACE + +#define STORAGE32 ((std::vector*)m_pStorage) +#define STORAGE64 ((std::vector*)m_pStorage) + +vector64::vector64() +{ + m_pStorage=(void*)new std::vector; +} + +vector64::~vector64() +{ + delete STORAGE64; +} + +void vector64::push(ull_t ullValue) +{ + STORAGE64->push_back(ullValue); +} + +void vector64::remove(ulong_t ulIndex) +{ + if (ulIndex >= STORAGE64->size()) + THROW(exception::format("[vector64::remove()] Index (" ULFMT ") out of range", ulIndex), CO_OUTOFRANGE, 0, 0); + STORAGE64->erase(STORAGE64->begin()+ulIndex); +} + +ull_t vector64::at(ulong_t ulIndex) +{ + if (ulIndex >= STORAGE64->size()) + THROW(exception::format("[vector64::at()] Index (" ULFMT ") out of range", ulIndex), CO_OUTOFRANGE, 0, 0); + return STORAGE64->at(ulIndex); +} + +ulong_t vector64::size() +{ + return (ulong_t)STORAGE64->size(); +} + + +vector32::vector32() +{ + m_pStorage=(void*)new std::vector; +} + +vector32::~vector32() +{ + delete STORAGE32; +} + +void vector32::push(ulong_t ulValue) +{ + STORAGE32->push_back(ulValue); +} + +void vector32::remove(ulong_t ulIndex) +{ + if (ulIndex >= STORAGE32->size()) + THROW(exception::format("[vector32::remove()] Index (" ULFMT ") out of range", ulIndex), CO_OUTOFRANGE, 0, 0); + STORAGE32->erase(STORAGE32->begin()+ulIndex); +} + +ulong_t vector32::at(ulong_t ulIndex) +{ + if (ulIndex >= STORAGE32->size()) + THROW(exception::format("[vector32::at()] Index (" ULFMT ") out of range", ulIndex), CO_OUTOFRANGE, 0, 0); + return STORAGE32->at(ulIndex); +} + +ulong_t vector32::size() +{ + return (ulong_t)STORAGE32->size(); +} + +END_ICPF_NAMESPACE Index: ext/libicpf/src/vector.h =================================================================== diff -u --- ext/libicpf/src/vector.h (revision 0) +++ ext/libicpf/src/vector.h (revision 2909ac3cba8d0ad71d8cd3f53e259b68e0569516) @@ -0,0 +1,68 @@ +#ifndef __ICPFVECTOR_H__ +#define __ICPFVECTOR_H__ + +#include "libicpf.h" +#include "gen_types.h" + +BEGIN_ICPF_NAMESPACE + +class vector64 +{ +public: + vector64(); + virtual ~vector64(); + + void push(ull_t ullValue); + void remove(ulong_t ulIndex); + ull_t at(ulong_t ulIndex); + ulong_t size(); + +private: + void* m_pStorage; +}; + +class vector32 +{ +public: + vector32(); + virtual ~vector32(); + + void push(ulong_t ulValue); + void remove(ulong_t ulIndex); + ulong_t at(ulong_t ulIndex); + ulong_t size(); + +private: + void* m_pStorage; +}; + +// needs to be fixed for linux +#if defined _WIN64 + typedef vector64 vectorptr; + typedef ull_t vectoritem; +#else + typedef vector32 vectorptr; + typedef ulong_t vectoritem; +#endif + +template +class vector : public BASE +{ +public: + vector() : BASE() { }; + virtual ~vector() { }; + + void push(T tValue) + { + ((BASE*)this)->push((BASEITEM)tValue); + } + + T at(ulong_t ulIndex) + { + return (T)(((BASE*)this)->at(ulIndex)); + } +}; + +END_ICPF_NAMESPACE + +#endif