FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
livecode/libbrowser/src/libbrowser_value.cpp at develop · livecode/livecode · GitHub
Uh oh!
There was an error while loading.
Please reload this page
.
This repository was archived by the owner on Aug 31, 2021. It is now read-only.
livecode
/
livecode
Public archive
Notifications
You must be signed in to change notification settings
Fork
223
Star
517
Code
Pull requests
189
Actions
Security and quality
0
Insights
Additional navigation options
Code
Pull requests
Actions
Security and quality
Insights
Expand file tree
Breadcrumbs
livecode
/
libbrowser
/
src
/
libbrowser_value.cpp
Copy path
More file actions
More file actions
Latest commit
History
History
History
1077 lines (834 loc) · 23.6 KB
Breadcrumbs
livecode
/
libbrowser
/
src
/
libbrowser_value.cpp
Copy path
File metadata and controls
1077 lines (834 loc) · 23.6 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
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
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/*
Copyright (C) 2015 LiveCode Ltd.
This file is part of LiveCode.
LiveCode is free software; you can redistribute it and/or modify it under
the terms of the GNU General Public License v3 as published by the Free
Software Foundation.
LiveCode is distributed in the hope that it will be useful, but WITHOUT ANY
WARRANTY; without even the implied warranty of MERCHANTABILITY or
FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
for more details.
You should have received a copy of the GNU General Public License
along with LiveCode. If not see <http://www.gnu.org/licenses/>.
*/
#
include
<
core.h
>
#
include
"
libbrowser.h
"
#
include
"
libbrowser_internal.h
"
//
//////////////////////////////////////////////////////////////////////////////
void
MCBrowserValueClear
(MCBrowserValue &p_value)
{
switch
(p_value.
type
)
{
case
kMCBrowserValueTypeUTF8String
:
MCCStringFree
(p_value.
utf8_string
);
break
;
case
kMCBrowserValueTypeList
:
MCBrowserListRelease
(p_value.
array
);
break
;
case
kMCBrowserValueTypeDictionary
:
MCBrowserDictionaryRelease
(p_value.
dictionary
);
break
;
default
:
break
;
}
p_value.
type
=
kMCBrowserValueTypeNone
;
}
bool
MCBrowserValueCopy
(
const
MCBrowserValue &p_src, MCBrowserValue &r_dst)
{
switch
(p_src.
type
)
{
case
kMCBrowserValueTypeBoolean
:
return
MCBrowserValueSetBoolean
(r_dst, p_src.
boolean
);
case
kMCBrowserValueTypeInteger
:
return
MCBrowserValueSetInteger
(r_dst, p_src.
integer
);
case
kMCBrowserValueTypeDouble
:
return
MCBrowserValueSetDouble
(r_dst, p_src.
double_val
);
case
kMCBrowserValueTypeNone
:
MCBrowserValueClear
(r_dst);
return
true
;
case
kMCBrowserValueTypeUTF8String
:
return
MCBrowserValueSetUTF8String
(r_dst, p_src.
utf8_string
);
case
kMCBrowserValueTypeList
:
return
MCBrowserValueSetList
(r_dst, p_src.
array
);
case
kMCBrowserValueTypeDictionary
:
return
MCBrowserValueSetDictionary
(r_dst, p_src.
dictionary
);
default
:
//
unknown type
break
;
}
return
false
;
}
bool
MCBrowserValueSetBoolean
(MCBrowserValue &self,
bool
p_value)
{
MCBrowserValueClear
(self);
self.
type
=
kMCBrowserValueTypeBoolean
;
self.
boolean
= p_value;
return
true
;
}
bool
MCBrowserValueGetBoolean
(MCBrowserValue &self,
bool
&r_value)
{
if
(self.
type
!=
kMCBrowserValueTypeBoolean
)
return
false
;
r_value = self.
boolean
;
return
true
;
}
bool
MCBrowserValueSetInteger
(MCBrowserValue &self,
int32_t
p_value)
{
MCBrowserValueClear
(self);
self.
type
=
kMCBrowserValueTypeInteger
;
self.
integer
= p_value;
return
true
;
}
bool
MCBrowserValueGetInteger
(MCBrowserValue &self,
int32_t
&r_value)
{
if
(self.
type
!=
kMCBrowserValueTypeInteger
)
return
false
;
r_value = self.
integer
;
return
true
;
}
bool
MCBrowserValueSetDouble
(MCBrowserValue &self,
double
p_value)
{
MCBrowserValueClear
(self);
self.
type
=
kMCBrowserValueTypeDouble
;
self.
double_val
= p_value;
return
true
;
}
bool
MCBrowserValueGetDouble
(MCBrowserValue &self,
double
&r_value)
{
if
(self.
type
!=
kMCBrowserValueTypeDouble
)
return
false
;
r_value = self.
double_val
;
return
true
;
}
bool
MCBrowserValueSetUTF8String
(MCBrowserValue &self,
const
char
*p_value)
{
char
*t_string;
t_string = nil;
if
(!
MCCStringClone
(p_value, t_string))
return
false
;
MCBrowserValueClear
(self);
self.
type
=
kMCBrowserValueTypeUTF8String
;
self.
utf8_string
= t_string;
return
true
;
}
bool
MCBrowserValueGetUTF8String
(MCBrowserValue &self,
char
*&r_value)
{
if
(self.
type
!=
kMCBrowserValueTypeUTF8String
)
return
false
;
return
MCCStringClone
(self.
utf8_string
, r_value);
}
bool
MCBrowserValueSetList
(MCBrowserValue &self, MCBrowserListRef p_value)
{
MCBrowserListRef t_array;
t_array =
MCBrowserListRetain
(p_value);
MCBrowserValueClear
(self);
self.
type
=
kMCBrowserValueTypeList
;
self.
array
= t_array;
return
true
;
}
bool
MCBrowserValueGetList
(MCBrowserValue &self, MCBrowserListRef &r_value)
{
if
(self.
type
!=
kMCBrowserValueTypeList
)
return
false
;
r_value = self.
array
;
return
true
;
}
bool
MCBrowserValueSetDictionary
(MCBrowserValue &self, MCBrowserDictionaryRef p_value)
{
MCBrowserDictionaryRef t_dict;
t_dict =
MCBrowserDictionaryRetain
(p_value);
MCBrowserValueClear
(self);
self.
type
=
kMCBrowserValueTypeDictionary
;
self.
dictionary
= t_dict;
return
true
;
}
bool
MCBrowserValueGetDictionary
(MCBrowserValue &self, MCBrowserDictionaryRef &r_value)
{
if
(self.
type
!=
kMCBrowserValueTypeDictionary
)
return
false
;
r_value = self.
dictionary
;
return
true
;
}
//
//////////////////////////////////////////////////////////////////////////////
class
MCBrowserList
:
public
MCBrowserRefCounted
{
public:
MCBrowserList
()
{
m_elements = nil;
m_size =
0
;
}
virtual
~MCBrowserList
()
{
for
(
uint32_t
i =
0
; i < m_size; i++)
MCBrowserValueClear
(m_elements[i]);
MCBrowserMemoryDeleteArray
(m_elements);
}
uint32_t
GetSize
()
{
return
m_size;
}
bool
Expand
(
uint32_t
p_size)
{
if
(p_size <= m_size)
return
true
;
return
MCBrowserMemoryResizeArray
(p_size, m_elements, m_size);
}
bool
GetType
(
uint32_t
p_index, MCBrowserValueType &r_type)
{
if
(p_index >= m_size)
return
false
;
r_type = m_elements[p_index].
type
;
return
true
;
}
bool
SetValue
(
uint32_t
p_index,
const
MCBrowserValue &p_value)
{
if
(p_index >= m_size)
return
false
;
return
MCBrowserValueCopy
(p_value, m_elements[p_index]);
}
bool
GetValue
(
uint32_t
p_index, MCBrowserValue &r_value)
{
if
(p_index >= m_size)
return
false
;
return
MCBrowserValueCopy
(m_elements[p_index], r_value);
}
bool
SetBoolean
(
uint32_t
p_index,
bool
p_value)
{
if
(p_index >= m_size)
return
false
;
return
MCBrowserValueSetBoolean
(m_elements[p_index], p_value);
}
bool
GetBoolean
(
uint32_t
p_index,
bool
&r_value)
{
if
(p_index >= m_size)
return
false
;
return
MCBrowserValueGetBoolean
(m_elements[p_index], r_value);
}
bool
SetInteger
(
uint32_t
p_index,
int32_t
p_value)
{
if
(p_index >= m_size)
return
false
;
return
MCBrowserValueSetInteger
(m_elements[p_index], p_value);
}
bool
GetInteger
(
uint32_t
p_index,
int32_t
&r_value)
{
if
(p_index >= m_size)
return
false
;
return
MCBrowserValueGetInteger
(m_elements[p_index], r_value);
}
bool
SetDouble
(
uint32_t
p_index,
double
p_value)
{
if
(p_index >= m_size)
return
false
;
return
MCBrowserValueSetDouble
(m_elements[p_index], p_value);
}
bool
GetDouble
(
uint32_t
p_index,
double
&r_value)
{
if
(p_index >= m_size)
return
false
;
return
MCBrowserValueGetDouble
(m_elements[p_index], r_value);
}
bool
SetUTF8String
(
uint32_t
p_index,
const
char
*p_value)
{
if
(p_index >= m_size)
return
false
;
return
MCBrowserValueSetUTF8String
(m_elements[p_index], p_value);
}
bool
GetUTF8String
(
uint32_t
p_index,
char
*&r_value)
{
if
(p_index >= m_size)
return
false
;
return
MCBrowserValueGetUTF8String
(m_elements[p_index], r_value);
}
bool
SetList
(
uint32_t
p_index, MCBrowserListRef p_value)
{
if
(p_index >= m_size)
return
false
;
return
MCBrowserValueSetList
(m_elements[p_index], p_value);
}
bool
GetList
(
uint32_t
p_index, MCBrowserListRef &r_value)
{
if
(p_index >= m_size)
return
false
;
return
MCBrowserValueGetList
(m_elements[p_index], r_value);
}
bool
SetDictionary
(
uint32_t
p_index, MCBrowserDictionaryRef p_value)
{
if
(p_index >= m_size)
return
false
;
return
MCBrowserValueSetDictionary
(m_elements[p_index], p_value);
}
bool
GetDictionary
(
uint32_t
p_index, MCBrowserDictionaryRef &r_value)
{
if
(p_index >= m_size)
return
false
;
return
MCBrowserValueGetDictionary
(m_elements[p_index], r_value);
}
bool
AppendValue
(
const
MCBrowserValue &p_value)
{
uint32_t
t_index;
t_index = m_size;
return
Expand
(m_size +
1
) &&
SetValue
(t_index, p_value);
}
bool
AppendBoolean
(
bool
p_value)
{
uint32_t
t_index;
t_index = m_size;
return
Expand
(m_size +
1
) &&
SetBoolean
(t_index, p_value);
}
bool
AppendInteger
(
int32_t
p_value)
{
uint32_t
t_index;
t_index = m_size;
return
Expand
(m_size +
1
) &&
SetInteger
(t_index, p_value);
}
bool
AppendDouble
(
double
p_value)
{
uint32_t
t_index;
t_index = m_size;
return
Expand
(m_size +
1
) &&
SetDouble
(t_index, p_value);
}
bool
AppendUTF8String
(
const
char
*p_value)
{
uint32_t
t_index;
t_index = m_size;
return
Expand
(m_size +
1
) &&
SetUTF8String
(t_index, p_value);
}
bool
AppendList
(MCBrowserListRef p_value)
{
uint32_t
t_index;
t_index = m_size;
return
Expand
(m_size +
1
) &&
SetList
(t_index, p_value);
}
bool
AppendDictionary
(MCBrowserDictionaryRef p_value)
{
uint32_t
t_index;
t_index = m_size;
return
Expand
(m_size +
1
) &&
SetDictionary
(t_index, p_value);
}
private:
MCBrowserValue *m_elements;
uint32_t
m_size;
};
//
//////////////////////////////////////////////////////////////////////////////
MC_BROWSER_DLLEXPORT_DEF
bool
MCBrowserListCreate
(MCBrowserListRef &r_browser,
uint32_t
p_size)
{
MCBrowserList *t_browser;
t_browser =
new
(nothrow)
MCBrowserList
();
if
(t_browser == nil)
return
false
;
if
(!t_browser->
Expand
(p_size))
{
delete
t_browser;
return
false
;
}
r_browser = t_browser;
return
true
;
}
MC_BROWSER_DLLEXPORT_DEF
MCBrowserListRef
MCBrowserListRetain
(MCBrowserListRef p_list)
{
if
(p_list != nil)
p_list->
Retain
();
return
p_list;
}
MC_BROWSER_DLLEXPORT_DEF
void
MCBrowserListRelease
(MCBrowserListRef p_list)
{
if
(p_list != nil)
p_list->
Release
();
}
MC_BROWSER_DLLEXPORT_DEF
bool
MCBrowserListGetSize
(MCBrowserListRef p_list,
uint32_t
&r_size)
{
if
(p_list == nil)
return
false
;
r_size = p_list->
GetSize
();
return
true
;
}
MC_BROWSER_DLLEXPORT_DEF
bool
MCBrowserListGetType
(MCBrowserListRef p_list,
uint32_t
p_index, MCBrowserValueType &r_type)
{
if
(p_list == nil)
return
false
;
return
p_list->
GetType
(p_index, r_type);
}
bool
MCBrowserListSetValue
(MCBrowserListRef p_list,
uint32_t
p_index,
const
MCBrowserValue &p_value)
{
if
(p_list == nil)
return
false
;
return
p_list->
SetValue
(p_index, p_value);
}
MC_BROWSER_DLLEXPORT_DEF
bool
MCBrowserListSetBoolean
(MCBrowserListRef p_list,
uint32_t
p_index,
bool
p_value)
{
if
(p_list == nil)
return
false
;
return
p_list->
SetBoolean
(p_index, p_value);
}
MC_BROWSER_DLLEXPORT_DEF
bool
MCBrowserListSetInteger
(MCBrowserListRef p_list,
uint32_t
p_index,
int32_t
p_value)
{
if
(p_list == nil)
return
false
;
return
p_list->
SetInteger
(p_index, p_value);
}
MC_BROWSER_DLLEXPORT_DEF
bool
MCBrowserListSetDouble
(MCBrowserListRef p_list,
uint32_t
p_index,
double
p_value)
{
if
(p_list == nil)
return
false
;
return
p_list->
SetDouble
(p_index, p_value);
}
MC_BROWSER_DLLEXPORT_DEF
bool
MCBrowserListSetUTF8String
(MCBrowserListRef p_list,
uint32_t
p_index,
const
char
*p_value)
{
if
(p_list == nil)
return
false
;
return
p_list->
SetUTF8String
(p_index, p_value);
}
MC_BROWSER_DLLEXPORT_DEF
bool
MCBrowserListSetList
(MCBrowserListRef p_list,
uint32_t
p_index, MCBrowserListRef p_value)
{
if
(p_list == nil)
return
false
;
return
p_list->
SetList
(p_index, p_value);
}
MC_BROWSER_DLLEXPORT_DEF
bool
MCBrowserListSetDictionary
(MCBrowserListRef p_list,
uint32_t
p_index, MCBrowserDictionaryRef p_value)
{
if
(p_list == nil)
return
false
;
return
p_list->
SetDictionary
(p_index, p_value);
}
bool
MCBrowserListAppendValue
(MCBrowserListRef p_list,
const
MCBrowserValue &p_value)
{
if
(p_list == nil)
return
false
;
return
p_list->
AppendValue
(p_value);
}
MC_BROWSER_DLLEXPORT_DEF
bool
MCBrowserListAppendBoolean
(MCBrowserListRef p_list,
bool
p_value)
{
if
(p_list == nil)
return
false
;
return
p_list->
AppendBoolean
(p_value);
}
MC_BROWSER_DLLEXPORT_DEF
bool
MCBrowserListAppendInteger
(MCBrowserListRef p_list,
int32_t
p_value)
{
if
(p_list == nil)
return
false
;
return
p_list->
AppendInteger
(p_value);
}
MC_BROWSER_DLLEXPORT_DEF
bool
MCBrowserListAppendDouble
(MCBrowserListRef p_list,
double
p_value)
{
if
(p_list == nil)
return
false
;
return
p_list->
AppendDouble
(p_value);
}
MC_BROWSER_DLLEXPORT_DEF
bool
MCBrowserListAppendUTF8String
(MCBrowserListRef p_list,
const
char
*p_value)
{
if
(p_list == nil)
return
false
;
return
p_list->
AppendUTF8String
(p_value);
}
MC_BROWSER_DLLEXPORT_DEF
bool
MCBrowserListAppendList
(MCBrowserListRef p_list, MCBrowserListRef p_value)
{
if
(p_list == nil)
return
false
;
return
p_list->
AppendList
(p_value);
}
MC_BROWSER_DLLEXPORT_DEF
bool
MCBrowserListAppendDictionary
(MCBrowserListRef p_list, MCBrowserDictionaryRef p_value)
{
if
(p_list == nil)
return
false
;
return
p_list->
AppendDictionary
(p_value);
}
bool
MCBrowserListGetValue
(MCBrowserListRef p_list,
uint32_t
p_index, MCBrowserValue &r_value)
{
if
(p_list == nil)
return
false
;
return
p_list->
GetValue
(p_index, r_value);
}
MC_BROWSER_DLLEXPORT_DEF
bool
MCBrowserListGetBoolean
(MCBrowserListRef p_list,
uint32_t
p_index,
bool
&r_value)
{
if
(p_list == nil)
return
false
;
return
p_list->
GetBoolean
(p_index, r_value);
}
MC_BROWSER_DLLEXPORT_DEF
bool
MCBrowserListGetInteger
(MCBrowserListRef p_list,
uint32_t
p_index,
int32_t
&r_value)
{
if
(p_list == nil)
return
false
;
return
p_list->
GetInteger
(p_index, r_value);
}
MC_BROWSER_DLLEXPORT_DEF
bool
MCBrowserListGetDouble
(MCBrowserListRef p_list,
uint32_t
p_index,
double
&r_value)
{
if
(p_list == nil)
return
false
;
return
p_list->
GetDouble
(p_index, r_value);
}
MC_BROWSER_DLLEXPORT_DEF
bool
MCBrowserListGetUTF8String
(MCBrowserListRef p_list,
uint32_t
p_index,
char
*&r_value)
{
if
(p_list == nil)
return
false
;
return
p_list->
GetUTF8String
(p_index, r_value);
}
MC_BROWSER_DLLEXPORT_DEF
bool
MCBrowserListGetList
(MCBrowserListRef p_list,
uint32_t
p_index, MCBrowserListRef &r_value)
{
if
(p_list == nil)
return
false
;
return
p_list->
GetList
(p_index, r_value);
}
MC_BROWSER_DLLEXPORT_DEF
bool
MCBrowserListGetDictionary
(MCBrowserListRef p_list,
uint32_t
p_index, MCBrowserDictionaryRef &r_value)
{
if
(p_list == nil)
return
false
;
return
p_list->
GetDictionary
(p_index, r_value);
}
//
//////////////////////////////////////////////////////////////////////////////
class
MCBrowserDictionary
:
public
MCBrowserRefCounted
{
public:
MCBrowserDictionary
()
{
m_elements = nil;
m_keys = nil;
m_capacity =
0
;
m_size =
0
;
}
virtual
~MCBrowserDictionary
()
{
for
(
uint32_t
i =
0
; i < m_size; i++)
MCBrowserValueClear
(m_elements[i]);
for
(
uint32_t
i =
0
; i < m_size; i++)
MCCStringFree
(m_keys[i]);
MCBrowserMemoryDeleteArray
(m_elements);
MCBrowserMemoryDeleteArray
(m_keys);
}
bool
GetKeys
(
char
**&r_keys,
uint32_t
&r_count)
{
r_keys = m_keys;
r_count = m_size;
return
true
;
}
bool
Expand
(
uint32_t
p_size)
{
if
(p_size <= m_capacity)
return
true
;
uindex_t
t_element_capacity, t_key_capacity;
//
Need to pass original capacity to BOTH calls to MCBrowserMemoryResizeArray, to ensure memory is appropriately cleared.
t_element_capacity = t_key_capacity = m_capacity;
if
(
MCBrowserMemoryResizeArray
(p_size, m_elements, t_element_capacity) &&
MCBrowserMemoryResizeArray
(p_size, m_keys, t_key_capacity))
{
m_capacity = t_element_capacity;
return
true
;
}
return
false
;
}
bool
FindElement
(
const
char
*p_key,
uint32_t
&r_index)
{
for
(
uint32_t
i =
0
; i < m_size; i++)
{
if
(
MCCStringEqualCaseless
(m_keys[i], p_key))
{
r_index = i;
return
true
;
}
}
return
false
;
}
bool
EnsureElement
(
const
char
*p_key,
uint32_t
&r_index)
{
if
(
FindElement
(p_key, r_index))
return
true
;
if
(!
Expand
(m_size +
1
))
return
false
;
if
(!
MCCStringClone
(p_key, m_keys[m_size]))
return
false
;
r_index = m_size;
m_size +=
1
;
return
true
;
}
bool
GetType
(
const
char
*p_key, MCBrowserValueType &r_type)
{
uint32_t
t_index;
if
(!
FindElement
(p_key, t_index))
return
false
;
r_type = m_elements[t_index].
type
;
return
true
;
}
bool
SetValue
(
const
char
*p_key,
const
MCBrowserValue &p_value)
{
uint32_t
t_index;
if
(!
EnsureElement
(p_key, t_index))
return
false
;
return
MCBrowserValueCopy
(p_value, m_elements[t_index]);
}
bool
GetValue
(
const
char
*p_key, MCBrowserValue &r_value)
{
uint32_t
t_index;
if
(!
FindElement
(p_key, t_index))
return
false
;
return
MCBrowserValueCopy
(m_elements[t_index], r_value);
}
bool
SetBoolean
(
const
char
*p_key,
bool
p_value)
{
uint32_t
t_index;
if
(!
EnsureElement
(p_key, t_index))
return
false
;
return
MCBrowserValueSetBoolean
(m_elements[t_index], p_value);
}
bool
GetBoolean
(
const
char
*p_key,
bool
&r_value)
{
uint32_t
t_index;
if
(!
FindElement
(p_key, t_index))
return
false
;
return
MCBrowserValueGetBoolean
(m_elements[t_index], r_value);
}
bool
SetInteger
(
const
char
*p_key,
int32_t
p_value)
{
uint32_t
t_index;
if
(!
EnsureElement
(p_key, t_index))
return
false
;
return
MCBrowserValueSetInteger
(m_elements[t_index], p_value);
}
bool
GetInteger
(
const
char
*p_key,
int32_t
&r_value)
{
uint32_t
t_index;
if
(!
FindElement
(p_key, t_index))
return
false
;
return
MCBrowserValueGetInteger
(m_elements[t_index], r_value);
}
bool
SetDouble
(
const
char
*p_key,
double
p_value)
{
uint32_t
t_index;
if
(!
EnsureElement
(p_key, t_index))
return
false
;
return
MCBrowserValueSetDouble
(m_elements[t_index], p_value);
}
bool
GetDouble
(
const
char
*p_key,
double
&r_value)
{
uint32_t
t_index;
if
(!
FindElement
(p_key, t_index))
return
false
;
return
MCBrowserValueGetDouble
(m_elements[t_index], r_value);
}
bool
SetUTF8String
(
const
char
*p_key,
const
char
*p_value)
{
uint32_t
t_index;
if
(!
EnsureElement
(p_key, t_index))
return
false
;
return
MCBrowserValueSetUTF8String
(m_elements[t_index], p_value);
}
bool
GetUTF8String
(
const
char
*p_key,
char
*&r_value)
{
uint32_t
t_index;
if
(!
FindElement
(p_key, t_index))
return
false
;
return
MCBrowserValueGetUTF8String
(m_elements[t_index], r_value);
}
bool
SetList
(
const
char
*p_key, MCBrowserListRef p_value)
{
uint32_t
t_index;
if
(!
EnsureElement
(p_key, t_index))
return
false
;
return
MCBrowserValueSetList
(m_elements[t_index], p_value);
}
bool
GetList
(
const
char
*p_key, MCBrowserListRef &r_value)
{
uint32_t
t_index;
if
(!
FindElement
(p_key, t_index))
return
false
;
return
MCBrowserValueGetList
(m_elements[t_index], r_value);
}
bool
SetDictionary
(
const
char
*p_key, MCBrowserDictionaryRef p_value)
{
uint32_t
t_index;
if
(!
EnsureElement
(p_key, t_index))
return
false
;
return
MCBrowserValueSetDictionary
(m_elements[t_index], p_value);
}
bool
GetDictionary
(
const
char
*p_key, MCBrowserDictionaryRef &r_value)
{
uint32_t
t_index;
if
(!
FindElement
(p_key, t_index))
return
false
;
return
MCBrowserValueGetDictionary
(m_elements[t_index], r_value);
}
private:
MCBrowserValue *m_elements;
char
**m_keys;
uint32_t
m_capacity;
uint32_t
m_size;
};
//
//////////////////////////////////////////////////////////////////////////////
MC_BROWSER_DLLEXPORT_DEF
bool
MCBrowserDictionaryCreate
(MCBrowserDictionaryRef &r_dict,
uint32_t
p_size)
{
MCBrowserDictionary *t_dict;
t_dict =
new
(nothrow)
MCBrowserDictionary
();
if
(t_dict == nil)
return
false
;
if
(!t_dict->
Expand
(p_size))
{
delete
t_dict;
return
false
;
}
r_dict = t_dict;
return
true
;
}
MC_BROWSER_DLLEXPORT_DEF
MCBrowserDictionaryRef
MCBrowserDictionaryRetain
(MCBrowserDictionaryRef p_dictionary)
{
if
(p_dictionary != nil)
p_dictionary->
Retain
();
return
p_dictionary;
}
MC_BROWSER_DLLEXPORT_DEF
void
MCBrowserDictionaryRelease
(MCBrowserDictionaryRef p_dictionary)
{
if
(p_dictionary != nil)
p_dictionary->
Release
();
}
MC_BROWSER_DLLEXPORT_DEF
bool
MCBrowserDictionaryGetKeys
(MCBrowserDictionaryRef p_dictionary,
char
**&r_keys,
uint32_t
&r_count)
{
if
(p_dictionary == nil)
return
false
;
return
p_dictionary->
GetKeys
(r_keys, r_count);
}
/*
WORKAROUND - Lack of Pointer dereferencing or C Array abstraction in LCB
*/
MC_BROWSER_DLLEXPORT_DEF
bool
MCBrowserDictionaryGetKeyCount
(MCBrowserDictionaryRef p_dictionary,
uint32_t
&r_count)
{
char
**t_keys;
return
MCBrowserDictionaryGetKeys
(p_dictionary, t_keys, r_count);
}
/*
WORKAROUND - Lack of Pointer dereferencing or C Array abstraction in LCB
*/
MC_BROWSER_DLLEXPORT_DEF
bool
MCBrowserDictionaryGetKey
(MCBrowserDictionaryRef p_dictionary,
uint32_t
p_index,
char
*&r_key)
{
char
**t_keys;
uint32_t
t_count;
if
(!
MCBrowserDictionaryGetKeys
(p_dictionary, t_keys, t_count))
return
false
;
if
(p_index >= t_count)
return
false
;
return
MCCStringClone
(t_keys[p_index], r_key);
}
MC_BROWSER_DLLEXPORT_DEF
bool
MCBrowserDictionaryGetType
(MCBrowserDictionaryRef p_dictionary,
const
char
*p_key, MCBrowserValueType &r_type)
{
if
(p_dictionary == nil)
return
false
;
return
p_dictionary->
GetType
(p_key, r_type);
}
bool
MCBrowserDictionarySetValue
(MCBrowserDictionaryRef p_dictionary,
const
char
*p_key,
const
MCBrowserValue &p_value)
{
if
(p_dictionary == nil)
return
false
;
return
p_dictionary->
SetValue
(p_key, p_value);
}
bool
MCBrowserDictionaryGetValue
(MCBrowserDictionaryRef p_dictionary,
const
char
*p_key, MCBrowserValue &r_value)
{
if
(p_dictionary == nil)
return
false
;
return
p_dictionary->
GetValue
(p_key, r_value);
}
MC_BROWSER_DLLEXPORT_DEF
bool
MCBrowserDictionarySetBoolean
(MCBrowserDictionaryRef p_dictionary,
const
char
*p_key,
bool
p_value)
{
if
(p_dictionary == nil)
return
false
;
return
p_dictionary->
SetBoolean
(p_key, p_value);
}
MC_BROWSER_DLLEXPORT_DEF
bool
MCBrowserDictionarySetInteger
(MCBrowserDictionaryRef p_dictionary,
const
char
*p_key,
int32_t
p_value)
{
if
(p_dictionary == nil)
return
false
;
return
p_dictionary->
SetInteger
(p_key, p_value);
}
MC_BROWSER_DLLEXPORT_DEF
bool
MCBrowserDictionarySetDouble
(MCBrowserDictionaryRef p_dictionary,
const
char
*p_key,
double
p_value)
{
if
(p_dictionary == nil)
return
false
;
return
p_dictionary->
SetDouble
(p_key, p_value);
}
MC_BROWSER_DLLEXPORT_DEF
bool
MCBrowserDictionarySetUTF8String
(MCBrowserDictionaryRef p_dictionary,
const
char
*p_key,
const
char
*p_value)
{
if
(p_dictionary == nil)
return
false
;
View remainder of file in raw view
Back
|
FazBrowse Home
|
New Git URL