Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Docker-in-Docker (DinD) capabilities of public runners deactivated.
More info
Open sidebar
CTA-LAPP
PHOENIX_LIBS
PhoenixGenerator
Commits
7edd1cd8
Commit
7edd1cd8
authored
Jan 05, 2021
by
Pierre Aubert
Browse files
Add DataStream integration
parent
36232f19
Changes
6
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
110 additions
and
14 deletions
+110
-14
.gitignore
.gitignore
+1
-0
TESTS/TEST_CLASS_CONFIG/main.cpp
TESTS/TEST_CLASS_CONFIG/main.cpp
+38
-1
src/parserClassConfig.cpp
src/parserClassConfig.cpp
+2
-1
src/parserClassConfig.h
src/parserClassConfig.h
+1
-1
src/saveClassConfig.cpp
src/saveClassConfig.cpp
+65
-8
src/saveClassConfig.h
src/saveClassConfig.h
+3
-3
No files found.
.gitignore
View file @
7edd1cd8
...
...
@@ -2,4 +2,5 @@ build
build2
.kdev4/
.tmp_project/
*.kdev4
TESTS/TEST_CLASS_CONFIG/main.cpp
View file @
7edd1cd8
...
...
@@ -108,10 +108,47 @@ bool testClassConfigInheritance(){
return
b
;
}
///Test the PClassConfig
/** @return true on success, false otherwise
*/
bool
testClassConfigDataStream
(){
bool
b
(
true
);
PClassConfig
conf
;
PClassAttribute
attrA
(
createClassAttribute
(
"int"
,
"attr1"
,
"///some attribute doc"
)),
attrB
,
attrC
,
attrD
;
attrB
=
createClassAttribute
(
"int"
,
"attr2"
,
false
,
true
,
"///some attribute doc"
);
attrC
=
createClassAttribute
(
"double"
,
"attr3"
,
true
,
false
,
"///some attribute doc"
);
attrD
=
createClassAttribute
(
"float"
,
"attr4"
,
true
,
true
,
"///some attribute doc"
);
printPClassAttribute
(
attrA
);
printPClassAttributeConst
(
attrA
);
conf
.
setClassDocumentation
(
"///Some documentation of the class"
);
conf
.
setName
(
"Shadok"
);
std
::
list
<
PClassAttribute
>
listAttribute1
,
listAttribute2
;
listAttribute1
.
push_back
(
attrA
);
listAttribute1
.
push_back
(
attrB
);
listAttribute2
.
push_back
(
attrD
);
conf
.
setListAttribute
(
listAttribute1
);
conf
.
addAttribute
(
attrC
);
conf
.
addListAttribute
(
listAttribute2
);
std
::
list
<
PClassConfig
>
listClassConfig
;
listClassConfig
.
push_back
(
conf
);
std
::
list
<
std
::
string
>
listInclude
;
b
&=
saveClassImplDecl
(
listClassConfig
,
"ShadokDS"
,
listInclude
,
true
);
return
b
;
}
int
main
(
int
argc
,
char
**
argv
){
bool
b
(
testClassConfig
());
b
&=
testClassConfigInheritance
();
b
&=
testClassConfigDataStream
();
return
b
-
1
;
}
...
...
src/parserClassConfig.cpp
View file @
7edd1cd8
...
...
@@ -165,9 +165,10 @@ bool parserClassConfig(std::list<PClassConfig> & listClassConfig, std::list<std:
///Parser list class config
/** @param baseFileNameOutput : base of the output files
* @param fileName : file name of the config
* @param enableDataStream : true to enable the serialization/deserialization with DataStream, false otherwise
* @return true on success, false otherwise
*/
bool
saveParserClassConfig
(
const
std
::
string
&
baseFileNameOutput
,
const
std
::
string
&
fileName
){
bool
saveParserClassConfig
(
const
std
::
string
&
baseFileNameOutput
,
const
std
::
string
&
fileName
,
bool
enableDataStream
){
std
::
list
<
std
::
string
>
listInclude
;
std
::
list
<
PClassConfig
>
listClassConfig
;
if
(
!
parserClassConfig
(
listClassConfig
,
listInclude
,
fileName
)){
...
...
src/parserClassConfig.h
View file @
7edd1cd8
...
...
@@ -12,7 +12,7 @@
#include "PClassConfig.h"
bool
parserClassConfig
(
std
::
list
<
PClassConfig
>
&
listClassConfig
,
std
::
list
<
std
::
string
>
&
listInclude
,
const
std
::
string
&
fileName
);
bool
saveParserClassConfig
(
const
std
::
string
&
baseFileNameOutput
,
const
std
::
string
&
fileName
);
bool
saveParserClassConfig
(
const
std
::
string
&
baseFileNameOutput
,
const
std
::
string
&
fileName
,
bool
enableDataStream
=
false
);
#endif
src/saveClassConfig.cpp
View file @
7edd1cd8
...
...
@@ -67,7 +67,6 @@ std::string createGetterDecl(const std::string & varType, const std::string & va
///Creates setters header file
/** @param[out] fs : header file name
* @param classConfig : class config we want to save
* @return true on success, false otherwise
*/
void
saveDeclSetters
(
std
::
ofstream
&
fs
,
const
PClassConfig
&
classConfig
){
const
std
::
list
<
PClassAttribute
>
&
listAttr
(
classConfig
.
getListAttribute
());
...
...
@@ -79,7 +78,6 @@ void saveDeclSetters(std::ofstream & fs, const PClassConfig & classConfig){
///Creates getters header file
/** @param[out] fs : header file name
* @param classConfig : class config we want to save
* @return true on success, false otherwise
*/
void
saveDeclGetters
(
std
::
ofstream
&
fs
,
const
PClassConfig
&
classConfig
){
const
std
::
list
<
PClassAttribute
>
&
listAttr
(
classConfig
.
getListAttribute
());
...
...
@@ -89,12 +87,55 @@ void saveDeclGetters(std::ofstream & fs, const PClassConfig & classConfig){
}
}
///Creates the method which enable to save/load generated class with any kind of stream/message/file
/** @param[out] fs : header file name
* @param classConfig : class config we want to save
*/
void
saveClassDataStreamMethod
(
std
::
ofstream
&
fs
,
const
PClassConfig
&
classConfig
){
std
::
string
name
(
classConfig
.
getName
());
fs
<<
std
::
endl
;
fs
<<
"
\t\t
///Load the current "
<<
name
<<
" with a stream"
<<
std
::
endl
;
fs
<<
"
\t\t
/** @param[out] ds : stream to be used"
<<
std
::
endl
;
fs
<<
"
\t\t
* @return true on success, false otherwise"
<<
std
::
endl
;
fs
<<
"
\t\t
*/"
<<
std
::
endl
;
fs
<<
"
\t\t
template<typename Stream, DataStreamMode::DataStreamMode Mode>"
<<
std
::
endl
;
fs
<<
"
\t\t
bool readWriteStream(Stream & ds){"
<<
std
::
endl
;
fs
<<
"
\t\t\t
bool b(true);"
<<
std
::
endl
;
const
std
::
list
<
PClassAttribute
>
&
listAttr
(
classConfig
.
getListAttribute
());
for
(
std
::
list
<
PClassAttribute
>::
const_iterator
it
(
listAttr
.
begin
());
it
!=
listAttr
.
end
();
++
it
){
fs
<<
"
\t\t\t
b &= DataStream<Stream, Mode, "
<<
it
->
getType
()
<<
" >::data_stream(ds, p_"
<<
it
->
getName
()
<<
");"
<<
std
::
endl
;
}
fs
<<
"
\t\t\t
return b;"
<<
std
::
endl
;
fs
<<
"
\t\t
}"
<<
std
::
endl
<<
std
::
endl
;
}
///Creates the method which enable to save/load generated class with any kind of stream/message/file
/** @param[out] fs : header file name
* @param classConfig : class config we want to save
*/
void
saveClassDataStreamGenericFunction
(
std
::
ofstream
&
fs
,
const
PClassConfig
&
classConfig
){
std
::
string
name
(
classConfig
.
getName
());
fs
<<
"///@brief Generic "
<<
name
<<
" serialisation/deserialisation, load/save and size function"
<<
std
::
endl
;
fs
<<
"template<typename Stream, DataStreamMode::DataStreamMode Mode>"
<<
std
::
endl
;
fs
<<
"struct DataStream<Stream, Mode, "
<<
name
<<
">{"
<<
std
::
endl
;
fs
<<
"
\t
///Generic function to load/save/serialise/deserialise "
<<
name
<<
std
::
endl
;
fs
<<
"
\t
/**
\t
@param data : "
<<
name
<<
" to be used"
<<
std
::
endl
;
fs
<<
"
\t
*
\t
@return true on success, false otherwise"
<<
std
::
endl
;
fs
<<
"
\t
*/"
<<
std
::
endl
;
fs
<<
"
\t
static bool data_stream(Stream & ds, "
<<
name
<<
" & data){"
<<
std
::
endl
;
fs
<<
"
\t\t
return data.readWriteStream<Stream, Mode>(ds);"
<<
std
::
endl
;
fs
<<
"
\t
}"
<<
std
::
endl
;
fs
<<
"};"
<<
std
::
endl
<<
std
::
endl
;
}
///Creates header file
/** @param[out] fs : header file name
* @param classConfig : class config we want to save
* @
return true on success
, false otherwise
* @
param enableDataStream : true to enable the serialization/deserialization with DataStream
, false otherwise
*/
void
saveClassDecl
(
std
::
ofstream
&
fs
,
const
PClassConfig
&
classConfig
){
void
saveClassDecl
(
std
::
ofstream
&
fs
,
const
PClassConfig
&
classConfig
,
bool
enableDataStream
){
if
(
classConfig
.
getClassDocumentation
()
!=
""
)
fs
<<
classConfig
.
getClassDocumentation
()
<<
endl
;
string
name
(
classConfig
.
getName
());
fs
<<
"class "
<<
name
;
...
...
@@ -116,6 +157,11 @@ void saveClassDecl(std::ofstream & fs, const PClassConfig & classConfig){
fs
<<
"
\t\t
"
<<
name
<<
" & operator = (const "
<<
name
<<
" & other);"
<<
endl
;
saveDeclSetters
(
fs
,
classConfig
);
saveDeclGetters
(
fs
,
classConfig
);
if
(
enableDataStream
){
saveClassDataStreamMethod
(
fs
,
classConfig
);
}
fs
<<
"
\t
protected:"
<<
endl
;
fs
<<
"
\t\t
void copy"
<<
name
<<
"(const "
<<
name
<<
" & other);"
<<
endl
;
...
...
@@ -126,6 +172,11 @@ void saveClassDecl(std::ofstream & fs, const PClassConfig & classConfig){
fs
<<
"
\t\t
"
<<
it
->
getType
()
<<
" p_"
<<
it
->
getName
()
<<
";"
<<
endl
;
}
fs
<<
"};"
<<
endl
<<
endl
;
if
(
enableDataStream
){
saveClassDataStreamGenericFunction
(
fs
,
classConfig
);
fs
<<
endl
<<
endl
;
}
}
///Saves constructor of the class
...
...
@@ -267,9 +318,10 @@ void saveClassImpl(std::ofstream & fs, const PClassConfig & classConfig){
/** @param classConfig : class config we want to save
* @param headerFile : header file name
* @param listInclude : list of the include files
* @param enableDataStream : true to enable the serialization/deserialization with DataStream, false otherwise
* @return true on success, false otherwise
*/
bool
saveClassDecl
(
const
std
::
list
<
PClassConfig
>
&
classConfig
,
const
std
::
string
&
headerFile
,
const
std
::
list
<
std
::
string
>
&
listInclude
){
bool
saveClassDecl
(
const
std
::
list
<
PClassConfig
>
&
classConfig
,
const
std
::
string
&
headerFile
,
const
std
::
list
<
std
::
string
>
&
listInclude
,
bool
enableDataStream
){
if
(
headerFile
==
""
)
return
false
;
std
::
ofstream
fs
;
fs
.
open
(
headerFile
.
c_str
());
...
...
@@ -287,8 +339,12 @@ bool saveClassDecl(const std::list<PClassConfig> & classConfig, const std::strin
}
fs
<<
endl
;
}
if
(
enableDataStream
){
fs
<<
"#include
\"
data_all.h
\"
"
<<
std
::
endl
<<
std
::
endl
;
}
for
(
std
::
list
<
PClassConfig
>::
const_iterator
it
(
classConfig
.
begin
());
it
!=
classConfig
.
end
();
++
it
){
saveClassDecl
(
fs
,
*
it
);
saveClassDecl
(
fs
,
*
it
,
enableDataStream
);
}
fs
<<
endl
<<
endl
<<
"#endif"
<<
endl
<<
endl
;
fs
.
close
();
...
...
@@ -322,11 +378,12 @@ bool saveClassImpl(const std::list<PClassConfig> & classConfig, const std::strin
/** @param classConfig : class config we want to save
* @param baseFileName : base file name for header or source file
* @param listInclude : list of the include files
* @param enableDataStream : true to enable the serialization/deserialization with DataStream, false otherwise
* @return true on success, false otherwise
*/
bool
saveClassImplDecl
(
const
std
::
list
<
PClassConfig
>
&
classConfig
,
const
std
::
string
&
baseFileName
,
const
std
::
list
<
std
::
string
>
&
listInclude
){
bool
saveClassImplDecl
(
const
std
::
list
<
PClassConfig
>
&
classConfig
,
const
std
::
string
&
baseFileName
,
const
std
::
list
<
std
::
string
>
&
listInclude
,
bool
enableDataStream
){
if
(
baseFileName
==
""
)
return
false
;
if
(
!
saveClassDecl
(
classConfig
,
baseFileName
+
".h"
,
listInclude
))
return
false
;
if
(
!
saveClassDecl
(
classConfig
,
baseFileName
+
".h"
,
listInclude
,
enableDataStream
))
return
false
;
if
(
!
saveClassImpl
(
classConfig
,
baseFileName
+
".cpp"
,
baseFileName
+
".h"
))
return
false
;
return
true
;
}
...
...
src/saveClassConfig.h
View file @
7edd1cd8
...
...
@@ -18,7 +18,7 @@ std::string createGetterDecl(const std::string & varType, const std::string & va
void
saveDeclSetters
(
std
::
ofstream
&
fs
,
const
PClassConfig
&
classConfig
);
void
saveDeclGetters
(
std
::
ofstream
&
fs
,
const
PClassConfig
&
classConfig
);
void
saveClassDecl
(
std
::
ofstream
&
fs
,
const
PClassConfig
&
classConfig
);
void
saveClassDecl
(
std
::
ofstream
&
fs
,
const
PClassConfig
&
classConfig
,
bool
enableDataStream
);
void
saveClassConstructorImpl
(
std
::
ofstream
&
fs
,
const
PClassConfig
&
classConfig
);
...
...
@@ -30,10 +30,10 @@ void saveClassGettersImpl(std::ofstream & fs, const PClassConfig & classConfig);
void
saveClassCopyFunctionImpl
(
std
::
ofstream
&
fs
,
const
PClassConfig
&
classConfig
);
void
saveClassImpl
(
std
::
ofstream
&
fs
,
const
PClassConfig
&
classConfig
);
bool
saveClassDecl
(
const
std
::
list
<
PClassConfig
>
&
classConfig
,
const
std
::
string
&
headerFile
,
const
std
::
list
<
std
::
string
>
&
listInclude
);
bool
saveClassDecl
(
const
std
::
list
<
PClassConfig
>
&
classConfig
,
const
std
::
string
&
headerFile
,
const
std
::
list
<
std
::
string
>
&
listInclude
,
bool
enableDataStream
);
bool
saveClassImpl
(
const
std
::
list
<
PClassConfig
>
&
classConfig
,
const
std
::
string
&
sourceFile
,
const
std
::
string
&
headerFile
);
bool
saveClassImplDecl
(
const
std
::
list
<
PClassConfig
>
&
classConfig
,
const
std
::
string
&
baseFileName
,
const
std
::
list
<
std
::
string
>
&
listInclude
=
std
::
list
<
std
::
string
>
());
bool
saveClassImplDecl
(
const
std
::
list
<
PClassConfig
>
&
classConfig
,
const
std
::
string
&
baseFileName
,
const
std
::
list
<
std
::
string
>
&
listInclude
=
std
::
list
<
std
::
string
>
()
,
bool
enableDataStream
=
false
);
#endif
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment