-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathzwlist.cpp
40 lines (35 loc) · 885 Bytes
/
zwlist.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
#include "zwlist.h"
#include <stdlib.h>
#include <string.h>
#include <assert.h>
zwlist_t *zwlist_new()
{
std::vector<std::string> *vec = new std::vector<std::string>();
assert(vec);
return (zwlist_t*)vec;
}
size_t zwlist_size(zwlist_t *list)
{
assert(list);
std::vector<std::string> *vec = (std::vector<std::string>*)list;
return vec->size();
}
char* zwlist_at(zwlist_t *list, size_t pos)
{
assert(list);
std::vector<std::string> *vec = (std::vector<std::string>*)list;
char* cstr = strdup(vec->at(pos).c_str());
return cstr;
}
void zwlist_free(zwlist_t *list)
{
assert(list);
std::vector<std::string> *vec = (std::vector<std::string>*)list;
delete vec;
}
zwlist_t* zwlist_copy(std::vector<std::string> &vec)
{
std::vector<std::string> *out = new std::vector<std::string>(vec);
assert(out);
return (zwlist_t*)out;
}