-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlist.cpp
More file actions
51 lines (47 loc) ยท 2.08 KB
/
Copy pathlist.cpp
File metadata and controls
51 lines (47 loc) ยท 2.08 KB
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
#include "database.h"
#include <iostream>
// ๋ฐ์ดํฐ๋ฒ ์ด์ค ๋ชฉ๋ก์ ์ถ๋ ฅํ๋ค.
void listPrint(Database &database) {
for (int i = 0; i < database.size; ++i) {
//์ํธ๋ฆฌ์ ํค๊ฐ์ ์ถ๋ ฅํ๋ค.
std::cout << database.entries[i].key << ": ";
// ์ํธ๋ฆฌ์ value๊ฐ void ํฌ์ธํฐ ํ์
์ด๋ฏ๋ก ์๋ ํ์
์ผ๋ก ๋ณํํ๊ธฐ ์ํด ์บ์คํ
์ ํจ
if (database.entries[i].type == INT) {
std::cout << *((int*)(database.entries[i].value)) << std::endl;
} else if (database.entries[i].type == DOUBLE) {
std::cout << *((double*)(database.entries[i].value)) << std::endl;
} else if (database.entries[i].type == STRING) {
std::cout << "\"" << *((std::string*)(database.entries[i].value)) << "\"" << std::endl;
} else if (database.entries[i].type == ARRAY) {
Array* arr = (Array*)(database.entries[i].value);
//์ถ๋ ฅ ํ์์ ๋ง๊ฒ ๋๊ดํธ ์ถ๊ฐํจ
arrayPrint(arr);
std::cout << std::endl;
}
}
}
void arrayPrint(Array* array) {
std::cout << "[";
for (int i = 0; i < array->size; ++i) {
if (array->type == INT) {
int* items = static_cast<int*>(array->items);
std::cout << items[i];
} else if (array->type == DOUBLE) {
double* items = static_cast<double*>(array->items);
std::cout << items[i];
} else if (array->type == STRING) {
std::string* items = static_cast<std::string*>(array->items);
std::cout << "\"" << items[i] << "\"";
} else if (array->type == ARRAY) {
Array** items = static_cast<Array**>(array->items);
if (array->items == ""){
break;
}
arrayPrint(items[i]);
}
if (i < array->size - 1) {
std::cout << ", ";
}
}
std::cout << "]";
}