Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
C
caosdb-cpplib
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Iterations
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package Registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
caosdb
Software
caosdb-cpplib
Commits
a2bc40f2
Verified
Commit
a2bc40f2
authored
3 years ago
by
Timm Fitschen
Browse files
Options
Downloads
Patches
Plain Diff
WIP: insert delete
parent
636ca477
No related branches found
Branches containing commit
No related tags found
Tags containing commit
1 merge request
!4
ENH: Allow insertion and deletion of single entities
Pipeline
#10923
passed
3 years ago
Stage: info
Stage: setup
Stage: test
Stage: deploy
Pipeline: caosdb-cppinttest
#10927
Changes
1
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
include/caosdb/entity.h
+156
-48
156 additions, 48 deletions
include/caosdb/entity.h
with
156 additions
and
48 deletions
include/caosdb/entity.h
+
156
−
48
View file @
a2bc40f2
...
...
@@ -38,20 +38,88 @@ using caosdb::entity::v1alpha1::IdResponse;
using
ProtoParent
=
caosdb
::
entity
::
v1alpha1
::
Parent
;
using
ProtoEntity
=
caosdb
::
entity
::
v1alpha1
::
Entity
;
class
Message
{
public:
[[
nodiscard
]]
inline
auto
GetCode
()
const
->
MessageCode
{
return
get_message_code
(
wrapped
->
code
());
}
[[
nodiscard
]]
inline
auto
GetDescription
()
const
->
std
::
string
{
return
wrapped
->
description
();
}
friend
class
Entity
;
friend
class
Messages
;
private
:
explicit
inline
Message
(
caosdb
::
entity
::
v1alpha1
::
Message
*
wrapped
)
:
wrapped
(
wrapped
){};
caosdb
::
entity
::
v1alpha1
::
Message
*
wrapped
;
};
/**
* Container for Messages.
*/
class
Messages
{
public:
[[
nodiscard
]]
inline
auto
Size
()
const
->
int
{
return
wrapped
->
size
();
}
[[
nodiscard
]]
inline
auto
At
(
int
index
)
const
->
const
Message
{
return
Message
(
&
(
wrapped
->
at
(
index
)));
}
friend
class
Entity
;
private
:
inline
Messages
()
:
wrapped
(
nullptr
){};
explicit
inline
Messages
(
::
google
::
protobuf
::
RepeatedPtrField
<
caosdb
::
entity
::
v1alpha1
::
Message
>
*
wrapped
)
:
wrapped
(
wrapped
){};
::
google
::
protobuf
::
RepeatedPtrField
<
caosdb
::
entity
::
v1alpha1
::
Message
>
*
wrapped
;
};
/**
* Parent of an Entity.
*
* This implementation uses protobuf messages as storage backends. In other
* words, this class wraps a protobuf message and provides getter and setter
* methods.
*/
class
Parent
{
public:
explicit
inline
Parent
(
caosdb
::
entity
::
v1alpha1
::
Parent
*
wrapped
)
:
wrapped
(
wrapped
){};
Parent
();
/**
* Return the id of the parent entity.
*/
[[
nodiscard
]]
auto
GetId
()
const
->
const
std
::
string
&
;
/**
* Return the name of the parent entity.
*/
[[
nodiscard
]]
auto
GetName
()
const
->
const
std
::
string
&
;
/**
* Return the description of the parent entity.
*/
[[
nodiscard
]]
auto
GetDescription
()
const
->
const
std
::
string
&
;
/**
* Set the id of the parent.
*/
auto
SetId
(
const
std
::
string
&
id
)
->
void
;
/**
* Set the name of the parent.
*/
auto
SetName
(
const
std
::
string
&
name
)
->
void
;
/**
* Return a json string representing this parent.
*
* This is intended for debugging.
*/
inline
auto
ToString
()
const
->
const
std
::
string
{
google
::
protobuf
::
util
::
JsonOptions
options
;
std
::
string
out
;
...
...
@@ -60,33 +128,84 @@ public:
return
out
;
}
// TODO(fspreck) These need implementations. See Entity::GetErrors for
// inspiration.
/**
* Return the error messages of this parent.
*/
[[
nodiscard
]]
inline
auto
GetErrors
()
const
->
const
Messages
&
;
/**
* Return the warning messages of this parent.
*/
[[
nodiscard
]]
inline
auto
GetWarnings
()
const
->
const
Messages
&
;
/**
* Return the info messages of this parent.
*/
[[
nodiscard
]]
inline
auto
GetInfos
()
const
->
const
Messages
&
;
friend
class
Entity
;
friend
class
Parents
;
private
:
/**
* Return an empty protobuf message pointer.
*
* This function is called by the default constructor of the
* caosdb::entity::Parent class and the protobuf message is used as the
* storage-backend for the new Parent instance.
*
* An 'Arena' takes care of the the memory management. Don't try to delete
* this.
*/
static
auto
CreateProtoParent
()
->
ProtoParent
*
;
/**
* Message which serves as storage backend.
*/
mutable
caosdb
::
entity
::
v1alpha1
::
Parent
*
wrapped
;
};
/**
* Container for parents of entities.
*
* Should only be instantiated and write-accessed by the owning entity.
*/
class
Parents
{
public:
inline
Parents
(){};
explicit
inline
Parents
(
::
google
::
protobuf
::
RepeatedPtrField
<
caosdb
::
entity
::
v1alpha1
::
Parent
>
*
wrapped
)
:
wrapped
(
wrapped
){};
auto
Append
(
const
Parent
&
parent
)
->
void
;
/**
* Return the current size of the parent container.
*
* That is also the number of parents the owning entity currently has.
*/
[[
nodiscard
]]
inline
auto
Size
()
const
->
int
{
return
wrapped
->
size
();
}
/**
* Return the parent at the given index.
*/
[[
nodiscard
]]
inline
auto
At
(
int
index
)
const
->
const
Parent
{
return
Parent
(
&
(
wrapped
->
at
(
index
)));
}
friend
class
Entity
;
private
:
inline
Parents
(){};
explicit
inline
Parents
(
::
google
::
protobuf
::
RepeatedPtrField
<
caosdb
::
entity
::
v1alpha1
::
Parent
>
*
wrapped
)
:
wrapped
(
wrapped
){};
/**
* Append a parent.
*
* This increases the Size() by one.
*/
auto
Append
(
const
Parent
&
parent
)
->
void
;
/**
* The collection of parent messages which serves as a backend for this
* class.
*/
::
google
::
protobuf
::
RepeatedPtrField
<
caosdb
::
entity
::
v1alpha1
::
Parent
>
*
wrapped
;
friend
class
Entity
;
};
/**
...
...
@@ -94,13 +213,13 @@ private:
*
* This is a property which belongs to another entity. Don't confuse it with
* an Entity with the "Property" role.
*
* @brief Property of an Entity.
*/
class
Property
{
public:
explicit
inline
Property
(
caosdb
::
entity
::
v1alpha1
::
Property
*
wrapped
)
:
wrapped
(
wrapped
){};
// TODO(fspreck) All of these methods need implementations.
[[
nodiscard
]]
auto
GetId
()
const
->
const
std
::
string
&
;
[[
nodiscard
]]
auto
GetName
()
const
->
const
std
::
string
&
;
[[
nodiscard
]]
auto
GetDescription
()
const
->
const
std
::
string
&
;
...
...
@@ -108,6 +227,10 @@ public:
[[
nodiscard
]]
auto
GetValue
()
const
->
const
std
::
string
&
;
[[
nodiscard
]]
auto
GetUnit
()
const
->
const
std
::
string
&
;
[[
nodiscard
]]
auto
GetDatatype
()
const
->
const
std
::
string
&
;
[[
nodiscard
]]
auto
GetErrors
()
const
->
const
Messages
&
;
[[
nodiscard
]]
auto
GetWarnings
()
const
->
const
Messages
&
;
[[
nodiscard
]]
auto
GetInfos
()
const
->
const
Messages
&
;
auto
SetId
(
const
std
::
string
&
id
)
->
void
;
auto
SetName
(
const
std
::
string
&
name
)
->
void
;
auto
SetImportance
(
const
std
::
string
&
importance
)
->
void
;
...
...
@@ -115,63 +238,36 @@ public:
auto
SetUnit
(
const
std
::
string
&
unit
)
->
void
;
auto
SetDatatype
(
const
std
::
string
&
datatype
)
->
void
;
friend
class
Entity
;
friend
class
Properties
;
private
:
caosdb
::
entity
::
v1alpha1
::
Property
*
wrapped
;
};
/**
* Container for Properties of Entities
* Container for Properties of Entities.
*
* Should only be instantiated and write-accessed by the owning entity.
*/
class
Properties
{
public:
inline
Properties
(){};
explicit
inline
Properties
(
::
google
::
protobuf
::
RepeatedPtrField
<
caosdb
::
entity
::
v1alpha1
::
Property
>
*
wrapped
)
:
wrapped
(
wrapped
){};
// TODO(fspreck) Implementations needed (basically everything). See Parents
// container for inspiration.
[[
nodiscard
]]
auto
At
(
int
index
)
const
->
const
Property
&
;
auto
Append
(
const
Property
&
property
)
->
void
;
private
:
::
google
::
protobuf
::
RepeatedPtrField
<
caosdb
::
entity
::
v1alpha1
::
Property
>
*
wrapped
;
friend
class
Entity
;
};
class
Message
{
public:
explicit
inline
Message
(
caosdb
::
entity
::
v1alpha1
::
Message
*
wrapped
)
:
wrapped
(
wrapped
){};
[[
nodiscard
]]
inline
auto
GetCode
()
const
->
MessageCode
{
return
get_message_code
(
wrapped
->
code
());
}
[[
nodiscard
]]
inline
auto
GetDescription
()
const
->
std
::
string
{
return
wrapped
->
description
();
}
private:
caosdb
::
entity
::
v1alpha1
::
Message
*
wrapped
;
};
/**
* Container for Messages.
*/
class
Messages
{
public:
inline
Messages
()
:
wrapped
(
nullptr
){};
explicit
inline
Messages
(
::
google
::
protobuf
::
RepeatedPtrField
<
caosdb
::
entity
::
v1alpha1
::
Message
>
inline
Properties
(){};
explicit
inline
Properties
(
::
google
::
protobuf
::
RepeatedPtrField
<
caosdb
::
entity
::
v1alpha1
::
Property
>
*
wrapped
)
:
wrapped
(
wrapped
){};
[[
nodiscard
]]
inline
auto
Size
()
const
->
int
{
return
wrapped
->
size
();
}
[[
nodiscard
]]
inline
auto
At
(
int
index
)
const
->
const
Message
{
return
Message
(
&
(
wrapped
->
at
(
index
)));
}
private
:
::
google
::
protobuf
::
RepeatedPtrField
<
caosdb
::
entity
::
v1alpha1
::
Message
>
::
google
::
protobuf
::
RepeatedPtrField
<
caosdb
::
entity
::
v1alpha1
::
Property
>
*
wrapped
;
friend
class
Entity
;
};
/**
...
...
@@ -183,6 +279,8 @@ public:
explicit
Entity
(
IdResponse
*
idResponse
);
explicit
inline
Entity
(
ProtoEntity
*
wrapped
)
:
wrapped
(
wrapped
)
{
errors
.
wrapped
=
this
->
wrapped
->
mutable_errors
();
warnings
.
wrapped
=
this
->
wrapped
->
mutable_warnings
();
infos
.
wrapped
=
this
->
wrapped
->
mutable_infos
();
properties
.
wrapped
=
this
->
wrapped
->
mutable_properties
();
parents
.
wrapped
=
this
->
wrapped
->
mutable_parents
();
};
...
...
@@ -219,6 +317,9 @@ public:
[[
nodiscard
]]
inline
auto
HasErrors
()
const
->
bool
{
return
this
->
errors
.
wrapped
->
size
()
>
0
;
}
// TODO(fspreck) These two need implementations...
[[
nodiscard
]]
auto
GetWarnings
()
const
->
const
Messages
&
;
[[
nodiscard
]]
auto
GetInfos
()
const
->
const
Messages
&
;
inline
auto
ToString
()
const
->
const
std
::
string
{
google
::
protobuf
::
util
::
JsonOptions
options
;
...
...
@@ -232,10 +333,15 @@ public:
auto
SetId
(
const
std
::
string
&
id
)
->
void
;
auto
SetName
(
const
std
::
string
&
name
)
->
void
;
auto
SetVersionId
(
const
std
::
string
&
id
)
->
void
;
// TODO(fspreck) ... and also these
auto
SetValue
(
const
std
::
string
&
value
)
->
void
;
auto
SetUnit
(
const
std
::
string
&
unit
)
->
void
;
// Currently no references or lists.
auto
SetDatatype
(
const
std
::
string
&
datatype
)
->
void
;
// TODO(fspreck) this one is tricky. See AppendParent
auto
AppendProperty
(
const
Property
&
property
)
->
void
;
auto
AppendParent
(
const
Parent
&
parent
)
->
void
;
auto
Switch
(
ProtoEntity
*
entity
)
->
void
;
...
...
@@ -245,6 +351,8 @@ private:
Properties
properties
;
Parents
parents
;
Messages
errors
;
Messages
warnings
;
Messages
infos
;
};
}
// namespace caosdb::entity
...
...
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