-
Notifications
You must be signed in to change notification settings - Fork 0
/
indexed_types_test.cpp
80 lines (60 loc) · 1.64 KB
/
indexed_types_test.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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
#include <sps/config.h>
#include <sps/stdlib.h>
#include <sps/cstdio>
#include <list>
#include <memory>
#define _INDEXED_TYPES_CLONEABLE 1
#include <sps/indexed_types.hpp>
#include <sps/indexed_types_custom.hpp>
#include <sps/indexed_nodes.hpp>
#include <sps/aligned_allocator.hpp>
#include <iostream>
#include <vector>
class A {
public:
A()
{
data = std::shared_ptr<int>(new int(2));
}
#ifdef _INDEXED_TYPES_CLONEABLE
A* clone() const
{
A* out = new A(*this);
out->data = std::shared_ptr<int>(new int(*this->data.get()));
return out;
}
#endif
private:
public:
std::shared_ptr<int> data;
};
using namespace sps;
int main(const int argc, const char* argv[]) {
SPS_UNREFERENCED_PARAMETERS(argc, argv);
std::vector<int,aligned_allocator<int> > vec = std::vector<int, aligned_allocator<int> >(4);
A* pA = new A();
uint64_t i = types::create_handle<A>(pA);
fprintf(stdout, "index of new object is: %zu\n",i);
pA = &(types::get_object<A>(i));
*pA->data.get() = 4;
printf("%d\n",*pA->data.get());
*pA->data = 5;
printf("%d\n",*pA->data.get());
#ifdef _INDEXED_TYPES_CLONEABLE
uint64_t j = types::clone_object<A>(i);
fprintf(stdout, "index of new object is: %zu\n",j);
types::destroy_object<A>(j);
#endif
// Nodes not working
A* pA1 = new A();
uint64_t k = types::create_handle(pA1);
fprintf(stdout, "index of new object is: %zu\n",k);
// assert equal to 1
types::destroy_object<A>(i);
A* pA2 = new A();
uint64_t l = types::create_handle(pA2);
fprintf(stdout, "index of new object is: %zu\n",l);
// assert equal to 0
//throw sps::bad_indexed_auto_ptr();
return EXIT_SUCCESS;
}