@@ -46,7 +46,7 @@ function assertHash(de::BlobEntry, db; hashfunction::Function = sha256)
46
46
end
47
47
48
48
49
- function Base. show (io:: IO , entry:: BlobEntry )
49
+ function Base. show (io:: IO , :: MIME"text/plain" , entry:: BlobEntry )
50
50
println (io, " _type=BlobEntry {" )
51
51
println (io, " id: " , entry. id)
52
52
println (io, " blobId: " , entry. blobId)
@@ -62,10 +62,6 @@ function Base.show(io::IO, entry::BlobEntry)
62
62
println (io, " }" )
63
63
end
64
64
65
- Base. show (io:: IO , :: MIME"text/plain" , entry:: BlobEntry ) = show (io, entry)
66
-
67
-
68
-
69
65
# #==============================================================================
70
66
# # BlobEntry - CRUD
71
67
# #==============================================================================
@@ -77,13 +73,15 @@ Get data entry
77
73
Also see: [`addBlobEntry`](@ref), [`getBlob`](@ref), [`listBlobEntries`](@ref)
78
74
"""
79
75
function getBlobEntry (var:: AbstractDFGVariable , key:: Symbol )
80
- ! hasBlobEntry (var, key) && error (" No dataEntry label $(key) found in variable $(getLabel (var)) " )
76
+ if ! hasBlobEntry (var, key)
77
+ throw (KeyError (" No dataEntry label $(key) found in variable $(getLabel (var)) . Available keys: $(keys (var. dataDict)) " ))
78
+ end
81
79
return var. dataDict[key]
82
80
end
83
81
84
82
function getBlobEntry (var:: AbstractDFGVariable , blobId:: UUID )
85
83
for (k,v) in var. dataDict
86
- if v . id == blobId
84
+ if blobId in [v . originId, v . blobId]
87
85
return v
88
86
end
89
87
end
@@ -92,9 +90,15 @@ function getBlobEntry(var::AbstractDFGVariable, blobId::UUID)
92
90
)
93
91
end
94
92
95
- # TODO consider changing this to use `first` as in julia's findfirst - as in findfirstBlobEntry->label::Symbol
96
- # or getBlobEntryFirst, btw this returns a vector in some other places
97
- function getBlobEntry (var:: AbstractDFGVariable , key:: Regex )
93
+ @deprecate getBlobEntry (var:: AbstractDFGVariable , key:: Regex ) getBlobEntryFirst (var, key)
94
+
95
+ """
96
+ $(SIGNATURES)
97
+ Finds and returns the first blob entry that matches the regex.
98
+
99
+ Also see: [`getBlobEntry`](@ref)
100
+ """
101
+ function getBlobEntryFirst (var:: AbstractDFGVariable , key:: Regex )
98
102
for (k,v) in var. dataDict
99
103
if occursin (key, string (v. label))
100
104
return v
107
111
108
112
getBlobEntry (var:: AbstractDFGVariable , key:: AbstractString ) = getBlobEntry (var,Regex (key))
109
113
110
-
114
+ # TODO split betweeen getfirstBlobEntry and getBlobEntry
111
115
getBlobEntry (dfg:: AbstractDFG , label:: Symbol , key:: Union{Symbol, UUID, <:AbstractString, Regex} ) = getBlobEntry (getVariable (dfg, label), key)
112
116
# getBlobEntry(dfg::AbstractDFG, label::Symbol, key::Symbol) = getBlobEntry(getVariable(dfg, label), key)
113
117
@@ -117,16 +121,35 @@ getBlobEntry(dfg::AbstractDFG, label::Symbol, key::Union{Symbol, UUID, <:Abstrac
117
121
Add Data Entry to a DFG variable
118
122
Should be extended if DFG variable is not returned by reference.
119
123
120
- Also see: [`getBlobEntry`](@ref), [`addBlob`](@ref), [`mergeBlobEntries!`](@ref)
124
+ Also see: [`getBlobEntry`](@ref), [`addBlob! `](@ref), [`mergeBlobEntries!`](@ref)
121
125
"""
122
- function addBlobEntry! (var:: AbstractDFGVariable , bde:: BlobEntry )
123
- haskey (var. dataDict, bde. label) && error (" blobEntry $(bde. label) already exists on variable $(getLabel (var)) " )
124
- var. dataDict[bde. label] = bde
125
- return bde
126
+ function addBlobEntry! (
127
+ var:: AbstractDFGVariable ,
128
+ entry:: BlobEntry ;
129
+ )
130
+ # see https://github.com/JuliaRobotics/DistributedFactorGraphs.jl/issues/985
131
+ # blobId::Union{UUID,Nothing} = (isnothing(entry.blobId) ? entry.id : entry.blobId),
132
+ # blobSize::Int = (hasfield(BlobEntry, :size) ? entry.size : -1)
133
+ haskey (var. dataDict, entry. label) && error (" blobEntry $(entry. label) already exists on variable $(getLabel (var)) " )
134
+ var. dataDict[entry. label] = entry
135
+ return entry
126
136
end
127
137
128
- function addBlobEntry! (dfg:: AbstractDFG , label:: Symbol , bde:: BlobEntry )
129
- return addBlobEntry! (getVariable (dfg, label), bde)
138
+ function addBlobEntry! (
139
+ var:: PackedVariable ,
140
+ entry:: BlobEntry ,
141
+ )
142
+ entry. label in getproperty .(var. blobEntries,:label ) && error (" blobEntry $(entry. label) already exists on variable $(getLabel (var)) " )
143
+ push! (var. blobEntries, entry)
144
+ return entry
145
+ end
146
+
147
+ function addBlobEntry! (
148
+ dfg:: AbstractDFG ,
149
+ vLbl:: Symbol ,
150
+ entry:: BlobEntry ;
151
+ )
152
+ return addBlobEntry! (getVariable (dfg, vLbl), entry)
130
153
end
131
154
132
155
@@ -186,18 +209,62 @@ hasBlobEntry(var::AbstractDFGVariable, blobLabel::Symbol) = haskey(var.dataDict,
186
209
187
210
"""
188
211
$(SIGNATURES)
189
- Get data entries, Vector{BlobEntry}
212
+
213
+ Get blob entries, Vector{BlobEntry}
190
214
"""
191
215
function getBlobEntries (var:: AbstractDFGVariable )
192
216
# or should we return the iterator, Base.ValueIterator{Dict{Symbol,BlobEntry}}?
193
217
collect (values (var. dataDict))
194
218
end
219
+
220
+ function getBlobEntries (var:: PackedVariable )
221
+ var. blobEntries
222
+ end
223
+
195
224
function getBlobEntries (dfg:: AbstractDFG , label:: Symbol )
196
225
# !isVariable(dfg, label) && return nothing
197
226
# or should we return the iterator, Base.ValueIterator{Dict{Symbol,BlobEntry}}?
198
227
getBlobEntries (getVariable (dfg, label))
199
228
end
200
229
230
+ function getBlobEntries (dfg:: AbstractDFG , label:: Symbol , regex:: Regex )
231
+ entries = getBlobEntries (dfg, label)
232
+ return filter (entries) do e
233
+ occursin (regex, string (e. label))
234
+ end
235
+ end
236
+
237
+
238
+ """
239
+ $(SIGNATURES)
240
+
241
+ Get all blob entries matching a Regex pattern over variables
242
+
243
+ Notes
244
+ - Use `dropEmpties=true` to not include empty lists in result.
245
+ - Use keyword `varList` for which variables to search through.
246
+ """
247
+ function getBlobEntriesVariables (
248
+ dfg:: AbstractDFG ,
249
+ bLblPattern:: Regex ;
250
+ varList:: AbstractVector{Symbol} = sort (listVariables (dfg); lt= natural_lt),
251
+ dropEmpties:: Bool = false
252
+ )
253
+ RETLIST = Vector {Vector{BlobEntry}} ()
254
+ @showprogress " Get entries matching $bLblPattern " for vl in varList
255
+ bes = filter (
256
+ s-> occursin (bLblPattern,string (s. label)),
257
+ listBlobEntries (dfg,vl)
258
+ )
259
+ # only push to list if there are entries on this variable
260
+ (! dropEmpties || 0 < length (bes)) ? nothing : continue
261
+ push! (RETLIST, bes)
262
+ end
263
+
264
+ return RETLIST
265
+ end
266
+
267
+
201
268
"""
202
269
$(SIGNATURES)
203
270
List the blob entries associated with a particular variable.
0 commit comments