Subversion Repositories Kolibri OS

Rev

Blame | Last modification | View Log | Download | RSS feed

  1. # cvec - partial `std::vector` implementation in C.
  2. ## Partial implementation of `std::vector`
  3.  
  4. Member functions table:
  5.  
  6. | Status | Name | Function or reason if not implemented |
  7. | :---: | --- | --- |
  8. | :heavy_check_mark: | `(constructor)` | `new` |
  9. | :heavy_check_mark: | `(destructor)` | `free` |
  10. | :heavy_check_mark: | `operator=` | `assign_other` |
  11. | :heavy_check_mark: | `assign` | `assign_fill`, `assign_range` |
  12. | :heavy_minus_sign: | `get_allocator` | No `allocator` objects in the language |
  13. | :heavy_check_mark: | `at` | `at` |
  14. | :heavy_check_mark: | `operator[]` | `[]` |
  15. | :heavy_check_mark: | `front` | `front`, `front_p` |
  16. | :heavy_check_mark: | `back` | `back`, `back_p` |
  17. | :heavy_check_mark: | `data` | `data` |
  18. | :heavy_check_mark: | `begin` | `begin` |
  19. | :heavy_check_mark: | `cbegin` | `cbegin` |
  20. | :heavy_check_mark: | `end` | `end` |
  21. | :heavy_check_mark: | `cend` | `cend` |
  22. | :heavy_minus_sign: | `rbegin` | No reverse iterators in the language |
  23. | :heavy_minus_sign: | `crbegin` | No reverse iterators in the language |
  24. | :heavy_minus_sign: | `rend` | No reverse iterators in the language |
  25. | :heavy_minus_sign: | `crend` | No reverse iterators in the language |
  26. | :heavy_check_mark: | `empty` | `empty` |
  27. | :heavy_check_mark: | `size` | `size` |
  28. | :heavy_check_mark: | `max_size` | `max_size` |
  29. | :heavy_check_mark: | `reserve` | `reserve` |
  30. | :heavy_check_mark: | `capacity` | `capacity` |
  31. | :heavy_check_mark: | `shrink_to_fit` | `shrink_to_fit` |
  32. | :heavy_check_mark: | `clear` | `clear` |
  33. | :heavy_check_mark: | `insert` | `insert`, `insert_it` |
  34. | :heavy_minus_sign: | `emplace` | I know no way to preserve the original signature |
  35. | :heavy_check_mark: | `erase` | `erase` |
  36. | :heavy_check_mark: | `push_back` | `push_back` |
  37. | :heavy_minus_sign: | `emplace_back` | I know no way to preserve the original signature |
  38. | :heavy_check_mark: | `pop_back` | `pop_back` |
  39. | :heavy_check_mark: | `resize` | `resize` |
  40. | :heavy_minus_sign: | `swap` | Would have n complexity in this implementation |
  41.  
  42. ## Easy to use
  43.  
  44. To use the std::vector implementation for specified type they should be declared as follows:
  45.  
  46. ```C
  47. #define CVEC_TYPE TypeOfVectorElement
  48. #include "cvec.h"
  49.  
  50. // ...
  51.  
  52.     TypeOfVectorElement *vec = cvec_TypeOfVectorElement_new(128);
  53.    
  54.     cvec_TypeOfVectorElement_push_back(&vec, value);
  55. ```
  56.  
  57. Also somewhere in the project the functinos should be instantiated as follows:
  58.  
  59. ```C
  60. #define CVEC_TYPE TypeOfVectorElement
  61. #define CVEC_INST
  62. #include "cvec.h"
  63. ```
  64.  
  65. ## Allows using of custom allocators.
  66.  
  67. ```C
  68. #define CVEC_TYPE pchar
  69. #define CVEC_INST
  70. #define CVEC_MALLOC custom_malloc
  71. #define CVEC_REALLOC custom_realloc
  72. #define CVEC_FREE custom_free
  73. #include "cvec.h"
  74. ```
  75.  
  76. ## Allows handling of exceptional cases.
  77.  
  78. ```C
  79. #define CVEC_TYPE pchar
  80. #define CVEC_INST
  81. // Set Out Of Bounds handler
  82. #define CVEC_OOBH(funcname, vec, index) printf("Out of bounds in %s (vec = %p, i = %d)", funcname, vec, index); abort();
  83. #include "cvec.h"
  84. ```
  85.  
  86. ## Has no fixed dependencies
  87.  
  88. Every function it uses may be overridden. More information about dependencies in [cvec.h](cvec.h).
  89.