Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
I
illuna-minetest
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Model registry
Operate
Environments
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository 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
Illuna-Minetest
illuna-minetest
Commits
0754f2a7
Commit
0754f2a7
authored
13 years ago
by
Perttu Ahola
Browse files
Options
Downloads
Patches
Plain Diff
ToolDefManager serialization
parent
8d2d28f1
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
src/tooldef.cpp
+36
-1
36 additions, 1 deletion
src/tooldef.cpp
src/tooldef.h
+3
-0
3 additions, 0 deletions
src/tooldef.h
with
39 additions
and
1 deletion
src/tooldef.cpp
+
36
−
1
View file @
0754f2a7
...
...
@@ -66,7 +66,7 @@ void ToolDefinition::deSerialize(std::istream &is)
{
int
version
=
readU8
(
is
);
if
(
version
!=
0
)
throw
SerializationError
(
"unsupported ToolD
iggingProperties
version"
);
"unsupported ToolD
efinition
version"
);
imagename
=
deSerializeString
(
is
);
properties
.
basetime
=
readF1000
(
is
);
properties
.
dt_weight
=
readF1000
(
is
);
...
...
@@ -133,6 +133,41 @@ class CToolDefManager: public IWritableToolDefManager
m_tool_definitions
[
toolname
]
=
new
ToolDefinition
(
def
);
return
true
;
}
virtual
void
serialize
(
std
::
ostream
&
os
)
{
writeU8
(
os
,
0
);
// version
u16
count
=
m_tool_definitions
.
size
();
writeU16
(
os
,
count
);
for
(
core
::
map
<
std
::
string
,
ToolDefinition
*>::
Iterator
i
=
m_tool_definitions
.
getIterator
();
i
.
atEnd
()
==
false
;
i
++
){
std
::
string
name
=
i
.
getNode
()
->
getKey
();
ToolDefinition
*
def
=
i
.
getNode
()
->
getValue
();
// Serialize name
os
<<
serializeString
(
name
);
// Serialize ToolDefinition and write wrapped in a string
std
::
ostringstream
tmp_os
(
std
::
ios
::
binary
);
def
->
serialize
(
tmp_os
);
os
<<
serializeString
(
tmp_os
.
str
());
}
}
virtual
void
deSerialize
(
std
::
istream
&
is
)
{
int
version
=
readU8
(
is
);
if
(
version
!=
0
)
throw
SerializationError
(
"unsupported ToolDefManager version"
);
u16
count
=
readU16
(
is
);
for
(
u16
i
=
0
;
i
<
count
;
i
++
){
// Deserialize name
std
::
string
name
=
deSerializeString
(
is
);
// Deserialize a string and grab a ToolDefinition from it
std
::
istringstream
tmp_is
(
deSerializeString
(
is
),
std
::
ios
::
binary
);
ToolDefinition
def
;
def
.
deSerialize
(
tmp_is
);
// Register
registerTool
(
name
,
def
);
}
}
private
:
// Key is name
core
::
map
<
std
::
string
,
ToolDefinition
*>
m_tool_definitions
;
...
...
This diff is collapsed.
Click to expand it.
src/tooldef.h
+
3
−
0
View file @
0754f2a7
...
...
@@ -85,6 +85,9 @@ class IWritableToolDefManager : public IToolDefManager
const
std
::
string
&
toolname
)
const
=
0
;
virtual
bool
registerTool
(
std
::
string
toolname
,
const
ToolDefinition
&
def
)
=
0
;
virtual
void
serialize
(
std
::
ostream
&
os
)
=
0
;
virtual
void
deSerialize
(
std
::
istream
&
is
)
=
0
;
};
IWritableToolDefManager
*
createToolDefManager
();
...
...
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