Skip to content

tbagrel1/cvector

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

35 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

C-Vector: Python-like list for C

Goal

Have you ever experienced the full power of Python list with tons of useful methods and then switching back to a C project with poor but incredibly fast arrays?

This lightweight library provides a simple way to use Python-like list in a C environment without too much overhead.

Implementation details

This library is much inspired by both Python list and Java List interface, to provide something similar in C without impacting performance. It uses a lot of C Preprocessor commands to provide support for any desired type in the same project (but not inside the same vector).

Disclaimer

Be careful! This library comes with only a few security measures, and should not be used in security-dependant apps. The library is still in alpha phase, any comment or bug/issue report would be useful!

Documentation

The full documentation is generated by Doxygen! Just read it there !

Link to the documentation: online documentation
You can also download the offline documentation there: PDF documentation

How to use it

DON'T FORGET TO LINK THE MATH LIBRARY

What you should put in your project is the two .h files of lib: cvector_interface.h and cvector_core.h

Then, for each required type (denoted $TYPE here, which MUST be a valid C identifier), create the following files

$TYPE_vect.h

#ifndef DEF_$TYPE_VECT
#define DEF_$TYPE_VECT

// If your $TYPE is not a primitive one, for example "typedef char * str;"
typedef $SOMETHING $TYPE;
#define CVECTOR_T $TYPE
#define CVECTOR_DEFAULT_VALUE $YOUR_TYPE_DEFAULT_VALUE
// Put your options ("#define CVECTOR_ERROR_FUNC"...) here

#include "cvector_interface.h"

#endif  // DEF_$TYPE_VECT

$TYPE_vect.c

#include "$TYPE_vect.h"
#include "cvector_core.h"

Then, you can use these .h and .c files like the other ones.

Examples

int_vect

int_vect.h

#ifndef DEF_INT_VECT
#define DEF_INT_VECT

#include "cvector_interface.h"

#endif  // DEF_INT_VECT

int_vect.c

#include "int_vect.h"
#include "cvector_core.h"

str_vect

str_vect.h

#ifndef DEF_STR_VECT
#define DEF_STR_VECT

typedef char * str;
#define CVECTOR_T str
#define CVECTOR_DEFAULT_VALUE NULL
#include "cvector_interface.h"

#endif  // DEF_STR_VECT

str_vect.c

#include "str_vect.h"
#include "cvector_core.h"

N.B. These examples are present in the includes directory.

Licence

Copyright (C) 2018 Thomas BAGREL

This program is free software: you can redistribute it and/or modify it under the terms of the GNU Affero General Public License as published by the Free Software Foundation, version 3.0.

This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more details.

You should have received a copy of the GNU Affero General Public License along with this program. If not, see https://www.gnu.org/licenses/.

Author

Thomas BAGREL, student in Lycée H. Poincaré, Nancy, France
Contact me at: tomsb07 at gmail dot com!

About

Python-like list for C

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published