-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMembers.cls
More file actions
117 lines (102 loc) · 3.45 KB
/
Members.cls
File metadata and controls
117 lines (102 loc) · 3.45 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
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
VERSION 1.0 CLASS
BEGIN
MultiUse = -1 'True
END
Attribute VB_Name = "Members"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = False
Attribute VB_Exposed = True
'@IgnoreModule
'@ModuleDescription "Represent all members of a JSON object."
'@Exposed
'@IgnoreModule AssignmentNotUsed, VariableNotUsed
'@Folder("JSON")
Option Explicit
Private mMembers As Collection
Private Const ModuleName As String = "Members"
Private Sub Class_Initialize()
#If DEV Then
Const FunctionName As String = "Class_Initialize"
Dim Logger As JSON.Logger
Set Logger = Services.CreateLogger(Services.LibraryName & "." & ModuleName, FunctionName)
#End If
Set mMembers = New Collection
End Sub
'@Description "Enumerator"
'@Enumerator
Public Property Get NewEnum() As IUnknown
Attribute NewEnum.VB_UserMemId = -4
#If DEV Then
Const FunctionName As String = "NewEnum"
Dim Logger As JSON.Logger
Set Logger = Services.CreateLogger(Services.LibraryName & "." & ModuleName, FunctionName)
#End If
Set NewEnum = mMembers.[_NewEnum]
End Property
'@Description "Return the amount of members stored in the collection."
Public Function Count() As Long
#If DEV Then
Const FunctionName As String = "Count"
Dim Logger As JSON.Logger
Set Logger = Services.CreateLogger(Services.LibraryName & "." & ModuleName, FunctionName)
#End If
Count = mMembers.Count
End Function
'@DefaultMember
'@Description "Provide access to a single member."
Public Function Item(ByVal Key As String) As JSON.Pair
Attribute Item.VB_Description = "Provide access to a single member."
Attribute Item.VB_UserMemId = 0
#If DEV Then
Const FunctionName As String = "Item"
Dim Logger As JSON.Logger
Set Logger = Services.CreateLogger(Services.LibraryName & "." & ModuleName, FunctionName)
#End If
If (Me.HasKey(Key)) Then
Dim Pair As JSON.Pair
Set Pair = mMembers(Services.ToBase64(Key))
Set Item = Pair
Else
Err.Raise JSON.JException.JUnexpectedKey, "Members.Item", "Unexpected key: " & Key
End If
End Function
'@Description "Add a member to the collection, in the form of a key / value pair"
Public Sub Add(ByRef Pair As JSON.Pair)
#If DEV Then
Debug.Assert Not (Pair Is Nothing)
Const FunctionName As String = "Add"
Dim Logger As JSON.Logger
Set Logger = Services.CreateLogger(Services.LibraryName & "." & ModuleName, FunctionName)
#End If
mMembers.Add Pair, Services.ToBase64(Pair.Name)
End Sub
'@Description "Remove a member from the collection."
Public Sub Remove(ByVal Key As String)
#If DEV Then
Const FunctionName As String = "Remove"
Dim Logger As JSON.Logger
Set Logger = Services.CreateLogger(Services.LibraryName & "." & ModuleName, FunctionName)
#End If
mMembers.Remove Services.ToBase64(Key)
End Sub
'@Description "Check for a key's existance (case sensitive)."
Public Function HasKey(ByVal Key As String) As Boolean
#If DEV Then
Const FunctionName As String = "HasKey"
Dim Logger As JSON.Logger
Set Logger = Services.CreateLogger(Services.LibraryName & "." & ModuleName, FunctionName)
#End If
On Error GoTo Error
Dim Pair As JSON.Pair
Set Pair = mMembers(Services.ToBase64(Key))
HasKey = True
Exit Function
Error:
Select Case Err.Number
Case 5, 9 '// L'indice n'appartient pas à la sélection.
HasKey = False
Case Else
Err.Raise Err.Number, Err.Source, Err.Description, Err.HelpFile, Err.HelpContext
End Select
End Function