Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
K
knowL
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Iterations
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Model registry
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
This is an archived project. Repository and other project resources are read-only.
Show more breadcrumbs
lrs
knowL
Commits
b630c760
Commit
b630c760
authored
2 years ago
by
Cyrille Berger
Browse files
Options
Downloads
Patches
Plain Diff
add contains function that also check the datatype
parent
f3e4e9f8
No related branches found
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
src/knowCore/ValueHash.cpp
+27
-0
27 additions, 0 deletions
src/knowCore/ValueHash.cpp
src/knowCore/ValueHash.h
+29
-0
29 additions, 0 deletions
src/knowCore/ValueHash.h
with
56 additions
and
0 deletions
src/knowCore/ValueHash.cpp
+
27
−
0
View file @
b630c760
...
...
@@ -60,6 +60,33 @@ bool ValueHash::contains(const QString& _key) const
return
d
->
values
.
contains
(
_key
);
}
bool
ValueHash
::
contains
(
const
QString
&
_key
,
const
knowCore
::
Uri
&
_datatype
)
const
{
auto
it
=
d
->
values
.
find
(
_key
);
if
(
it
!=
d
->
values
.
end
())
{
return
it
.
value
().
canConvert
(
_datatype
);
}
else
{
return
false
;
}
}
knowCore
::
ReturnVoid
ValueHash
::
ensureContains
(
const
QString
&
_key
,
const
knowCore
::
Uri
&
_datatype
)
const
{
auto
it
=
d
->
values
.
find
(
_key
);
if
(
it
!=
d
->
values
.
end
())
{
if
(
it
.
value
().
canConvert
(
_datatype
))
{
return
kCrvSuccess
();
}
else
{
return
kCrvError
(
"Cannot convert '{}' to '{}'"
,
it
.
value
(),
_datatype
);
}
}
else
{
return
kCrvError
(
"Missing '{}' in value hash."
,
_key
);
}
}
bool
ValueHash
::
operator
==
(
const
ValueHash
&
_rhs
)
const
{
return
d
->
values
==
_rhs
.
d
->
values
;
...
...
This diff is collapsed.
Click to expand it.
src/knowCore/ValueHash.h
+
29
−
0
View file @
b630c760
...
...
@@ -48,6 +48,24 @@ namespace knowCore
* @return if the value is contained in the hash.
*/
bool
contains
(
const
QString
&
_key
)
const
;
/**
* @return if the value is contained in the hash and has the given \p _datatype.
*/
bool
contains
(
const
QString
&
_key
,
const
knowCore
::
Uri
&
_datatype
)
const
;
/**
* @return if the value is contained in the hash and is of type \p _T_.
*/
template
<
typename
_T_
>
bool
contains
(
const
QString
&
_key
)
const
;
/**
* @return if the value is contained in the hash and has the given \p _datatype.
*/
knowCore
::
ReturnVoid
ensureContains
(
const
QString
&
_key
,
const
knowCore
::
Uri
&
_datatype
)
const
;
/**
* @return if the value is contained in the hash and is of type \p _T_.
*/
template
<
typename
_T_
>
knowCore
::
ReturnVoid
ensureContains
(
const
QString
&
_key
)
const
;
/**
* @return attempt to return as a hash of a specific type @arg _T_ if they are convertible to @arg _T_
*/
...
...
@@ -156,6 +174,17 @@ namespace knowCore
struct
Private
;
QSharedDataPointer
<
Private
>
d
;
};
template
<
typename
_T_
>
bool
ValueHash
::
contains
(
const
QString
&
_key
)
const
{
return
contains
(
_key
,
MetaTypeInformation
<
_T_
>::
uri
());
}
template
<
typename
_T_
>
knowCore
::
ReturnVoid
ValueHash
::
ensureContains
(
const
QString
&
_key
)
const
{
return
ensureContains
(
_key
,
MetaTypeInformation
<
_T_
>::
uri
());
}
inline
ReturnValue
<
ValueHash
>
ValueHash
::
fromVariantMap
(
const
QVariantMap
&
_map
)
{
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment