Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #ifndef _CVECTOR_H_
- #define _CVECTOR_H_
- /*
- cvector: C vector implementation, almost a copy of the STL vector itself but
- with some small changes with how the operator overloaded operations are done.
- Please read notes near the bottom of this file for directions/use of regarding
- operator overloaded operations, there is some things that ain't exacly like
- the STL vector, some things are done in other ways (like comparing contents
- of two different vectors) etc.
- Author: xyz (heulanith @ bitbucket).
- */
- #define CVECTOR_16BIT_INT // DEFAULT :>
- #ifdef CVECTOR_16BIT_INT
- #define CVECTOR_UINT unsigned short
- #else
- #define CVECTOR_UINT unsigned int
- #endif
- #define CVECTOR_VOID void
- // config-bits
- #define CVECTOR_DYN_ALLOC 1
- /* CVECTOR SPECIFIC */
- struct t_cvector* cvector_alloc(struct t_cvector *pvector,
- CVECTOR_UINT element_size, CVECTOR_UINT capacity);
- void cvector_free(struct t_cvector *v);
- /* ITERATORS */
- CVECTOR_VOID* cvector_begin(struct t_cvector *v);
- CVECTOR_VOID* cvector_end(struct t_cvector *v);
- /* CAPACITY */
- //CVECTOR_UINT cvector_grow_capacity(struct t_cvector *v, CVECTOR_UINT n);
- CVECTOR_UINT cvector_size(struct t_cvector *v);
- CVECTOR_UINT cvector_capacity(struct t_cvector *v);
- CVECTOR_UINT cvector_empty(struct t_cvector *v);
- CVECTOR_UINT cvector_resize(struct t_cvector *v, CVECTOR_UINT n, CVECTOR_VOID* data);
- CVECTOR_UINT cvector_reserve(struct t_cvector *v, CVECTOR_UINT n);
- /* ELEMENT ACCESS */
- CVECTOR_VOID* cvector_at(struct t_cvector *v, CVECTOR_UINT i);
- CVECTOR_VOID* cvector_front(struct t_cvector *v);
- CVECTOR_VOID* cvector_back(struct t_cvector *v);
- /* MODIFIERS */
- CVECTOR_UINT cvector_assign(struct t_cvector *d, struct t_cvector *s);
- //fill, copy, range
- CVECTOR_UINT cvector_push_back(struct t_cvector *v, CVECTOR_VOID *data);
- CVECTOR_UINT cvector_pop_back(struct t_cvector *v);
- CVECTOR_UINT cvector_insert(struct t_cvector *v, CVECTOR_UINT i, CVECTOR_VOID *data);
- CVECTOR_UINT cvector_erase(struct t_cvector *v, CVECTOR_UINT i);
- CVECTOR_UINT cvector_swap(struct t_cvector *v, CVECTOR_UINT a, CVECTOR_UINT b);
- void cvector_clear(struct t_cvector *v);
- /* vector container structure */
- struct t_cvector {
- CVECTOR_UINT elements;
- CVECTOR_UINT capacity;
- CVECTOR_UINT element_size;
- CVECTOR_VOID *data;
- CVECTOR_VOID **iterators;
- /* used in cvector_free(...) to know wether the cvector structure was dynamically
- allocated by malloc() in cvector_alloc() OR if it was referred to from already
- allocated memory of size (sizeof(struct t_cvector)) */
- unsigned char conf_bits;
- /* OPERATOR OVERLOADING FOR EASE OF USE
- Explanations of all operator operations comes below:
- First off we got the vector-to-vector operations, those does NOT compare
- the elements in the vector as the STL vector does - instead they compare the
- size (number of elements) of the vectors. This is because we can never know
- the type of data that is stored in the vector without templates (which use
- alot of space on harddrive) or ugly hacks. Instead it is entirely logic
- to write those operator overloaded operations in the structure the data
- that is stored in the vector belongs to in the first place - then it is
- easy to use the vector's [] overloaded operator to compare to elements of
- the same type with each other, that kind of stuff doesn't belong in this
- code anyway as all sorts of structures or datatypes should be treated
- individually when those operators are used.
- Otherwise the [] and = operators all got the same function as the
- STL vector's counterparts.
- */
- /*struct t_cvector operator =(struct t_cvector r) {
- cvector_clear(this);
- cvector_assign(this, &r);
- //return a;
- }*/
- /*CVECTOR_VOID* operator [](CVECTOR_UINT i) {
- return cvector_at(this, i);
- }*/
- };
- #endif
Add Comment
Please, Sign In to add comment