equal
deleted
inserted
replaced
1 /* |
1 /** |
2 * serialize.h: object serialization functions |
2 * @file serialize.h |
|
3 * @brief Object serialization functions |
3 * |
4 * |
4 * This file is part of Pyrit Ray Tracer. |
5 * This file is part of Pyrit Ray Tracer. |
5 * |
6 * |
6 * Copyright 2008 Radek Brich |
7 * Copyright 2008 Radek Brich |
7 * |
8 * |
31 |
32 |
32 #include "shapes.h" |
33 #include "shapes.h" |
33 #include "container.h" |
34 #include "container.h" |
34 #include "kdtree.h" |
35 #include "kdtree.h" |
35 |
36 |
|
37 /** |
|
38 * Maps pointers to indices |
|
39 * |
|
40 * This helps when we are saving objects from random memory places |
|
41 * to file stream |
|
42 */ |
36 class Indexer |
43 class Indexer |
37 { |
44 { |
38 map <void *, int> indexmap; |
45 map <void *, int> indexmap; |
39 int index; |
46 int index; |
40 public: |
47 public: |
41 Indexer(): indexmap(), index(0) {}; |
48 Indexer(): indexmap(), index(0) {}; |
42 void reset() { indexmap.clear(); index = 0; }; |
49 void reset() { indexmap.clear(); index = 0; }; |
|
50 |
|
51 /** |
|
52 * Make new index or return number of already indexed object |
|
53 * @param[in] o object for indexation |
|
54 * @param[out] retidx returned index |
|
55 * @retval true if object was found |
|
56 * @retval false if new index was made for the object |
|
57 */ |
43 bool get(void *o, int &retidx); |
58 bool get(void *o, int &retidx); |
|
59 |
44 const int &operator[](void *o) { return indexmap[o]; }; |
60 const int &operator[](void *o) { return indexmap[o]; }; |
45 }; |
61 }; |
46 |
62 |
47 extern Indexer vertex_index, shape_index; |
63 extern Indexer vertex_index, shape_index; |
48 |
64 |