This repository has been archived by the owner on Jan 13, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 30
/
usage.cpp
94 lines (76 loc) · 2.12 KB
/
usage.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
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
// PHP EMBED tutorial program
// Copyright (c) 2007 Andrew Bosworth, Facebook, inc
// All rights reserved
#include "php_stl.h"
// define our own output functions with this exact signature
void print_null(const char *str) {}
void print_mine(const char *str){ printf("%s", str); }
int main(int argc, char **argv){
// Instantiate the object without type warnings
php_stl p;
// redefine the output functions to do what we want
p.set_message_function(print_null);
p.set_output_function(print_mine);
long memused = p.call_long("memory_get_usage");
hash_set<string> ex;
ex = p.call_string_hash_set("get_loaded_extensions");
printf("memused = %ldb\n", memused);
char *one = "test1";
int comp = 4;
long match = p.call_long("strncmp", "ssi", one, "test2", comp);
printf("match = %ld (should be 0)\n", match);
php_array a;
php_array b(a);
a.add("l", 5);
a.add_assoc("slsd", "one", 1, "two", 2.5);
a.add_index("lsll", 6, "six", 128, 129);
a.remove(6);
a.remove("two");
p.call_void("print_r", "a", &a);
php_iterator it(a);
int count = 0;
while(!it.done()){
count++;
it++;
}
it.go_to_end();
if(!it.done()){
switch(it.get_key_type()){
case IS_LONG:
printf("long %ld => ", it.get_key_long());
break;
case IS_STRING:
printf("string %s => ", it.get_key_c_string());
break;
default:
printf("??? %s => ", it.get_key_c_string());
break;
}
switch(it.get_data_type()){
case IS_LONG:
printf("long %ld\n", it.get_data_long());
break;
case IS_STRING:
printf("string %s\n", it.get_data_c_string());
break;
case IS_DOUBLE:
printf("double %f\n", it.get_data_double());
break;
case IS_BOOL:
printf("bool %s\n", it.get_data_c_string());
break;
case IS_ARRAY:
printf("Array\n");
{
php_array suba = it.get_data_array();
php_iterator subit(suba);
// now iterate on the sub array!
}
break;
default:
printf("??? %s\n", it.get_data_c_string());
break;
}
}
return 0;
}