PhoenixPresentation
2.0.0
Set of cmake function to automate presentation generation
main.cpp
Go to the documentation of this file.
1
/***************************************
2
Auteur : Pierre Aubert
3
Mail : pierre.aubert@lapp.in2p3.fr
4
Licence : CeCILL-C
5
****************************************/
6
7
#include "
phoenix_data_stream.h
"
8
9
10
namespace
ShadokType
{
12
enum
ShadokType
{
13
NONE
= 0,
//Nothing to do
14
HAUT
= 1,
//Shadok from the top of the planet
15
BAS
= 2
//Shadok from the bottom of the planet
16
};
17
}
18
20
template
<
typename
Stream>
21
struct
DataStream
<Stream,
DataStreamMode
::
READ
,
ShadokType::ShadokType
>{
23
27
static
bool
data_stream
(Stream & ds,
ShadokType::ShadokType
& data){
28
int
value(0);
29
bool
b =
DataStream<Stream, DataStreamMode::READ, int>::data_stream
(ds, value);
30
data = (
ShadokType::ShadokType
)value;
31
return
b;
32
}
33
};
34
36
template
<
typename
Stream>
37
struct
DataStream
<Stream,
DataStreamMode
::
WRITE
,
ShadokType::ShadokType
>{
39
43
static
bool
data_stream
(Stream & ds,
ShadokType::ShadokType
& data){
44
int
value = (int)data;
45
return
DataStream<Stream, DataStreamMode::WRITE, int>::data_stream
(ds, value);
46
}
47
};
48
49
51
void
testShadokTypeSize
(){
52
ShadokType::ShadokType
type(
ShadokType::HAUT
);
53
size_t
shadokSize(
data_size
(type));
54
data_stream_assert
(
checkValue
(
"testShadokTypeSize"
, shadokSize, 4lu));
55
}
56
58
void
testShadokTypeMessage
(){
59
ShadokType::ShadokType
type(
ShadokType::BAS
);
60
61
DataStreamMsg
messageIn(
data_size
(type));
62
DataStreamIter
iter = (
DataStreamIter
)messageIn.data();
63
data_stream_assert
(
data_message_save
(iter, type));
64
66
ShadokType::ShadokType
out;
67
DataStreamIter
iterOut = (
DataStreamIter
)messageIn.data();
68
data_stream_assert
(
data_message_load
(iterOut, out));
69
70
data_stream_assert
(
checkValue
(
"testShadokMessage"
, out, type));
71
}
72
74
void
testShadokTypeFile
(){
75
ShadokType::ShadokType
type(
ShadokType::BAS
);
76
std::string fileName(
"ShadokType.data"
);
77
data_save
(fileName, type);
78
80
ShadokType::ShadokType
out;
81
data_load
(fileName, out);
82
83
data_stream_assert
(
checkValue
(
"testShadokFile"
, out, type));
84
}
85
86
87
int
main
(
int
argc,
char
** argv){
88
testShadokTypeSize
();
89
testShadokTypeMessage
();
90
testShadokTypeFile
();
91
return
0;
92
}
93
main
int main(int argc, char **argv)
Definition:
main.cpp:228
testShadokTypeFile
void testShadokTypeFile()
Test the Shadok message.
Definition:
main.cpp:74
testShadokTypeMessage
void testShadokTypeMessage()
Test the Shadok message.
Definition:
main.cpp:58
testShadokTypeSize
void testShadokTypeSize()
Test the Shadok size.
Definition:
main.cpp:51
data_load
bool data_load(FILE *iter, T &data)
Load data from a message.
Definition:
data_file.h:39
data_save
bool data_save(FILE *iter, const T &data)
Save data in a message.
Definition:
data_file.h:18
data_message_save
bool data_message_save(DataStreamIter &iter, T &data)
Save data in a message.
Definition:
data_message.h:18
data_message_load
bool data_message_load(DataStreamIter &iter, T &data)
Load data from a message.
Definition:
data_message.h:60
data_size
size_t data_size(T &data)
Get size of data.
Definition:
data_size.h:17
data_stream_assert
#define data_stream_assert(isOk)
Definition:
data_stream_assert.h:17
checkValue
bool checkValue(const std::string &testName, const T &givenSize, const T &referenceSize)
Check given value compare to the reference value.
Definition:
data_stream_check_value_impl.h:19
DataStreamMsg
std::vector< DataStreamType > DataStreamMsg
Definition:
data_stream_include.h:27
DataStreamIter
DataStreamType * DataStreamIter
Definition:
data_stream_include.h:28
DataStreamMode
Definition:
data_stream_include.h:18
DataStreamMode::READ
@ READ
Definition:
data_stream_include.h:21
DataStreamMode::WRITE
@ WRITE
Definition:
data_stream_include.h:22
ShadokType
Definition:
main.cpp:10
ShadokType::ShadokType
ShadokType
Type of the Shadok we want to serialized.
Definition:
main.cpp:12
ShadokType::HAUT
@ HAUT
Definition:
main.cpp:14
ShadokType::BAS
@ BAS
Definition:
main.cpp:15
ShadokType::NONE
@ NONE
Definition:
main.cpp:13
phoenix_data_stream.h
DataStream< Stream, DataStreamMode::READ, ShadokType::ShadokType >::data_stream
static bool data_stream(Stream &ds, ShadokType::ShadokType &data)
Generic function to load/deserialise ShadokType.
Definition:
main.cpp:27
DataStream< Stream, DataStreamMode::WRITE, ShadokType::ShadokType >::data_stream
static bool data_stream(Stream &ds, ShadokType::ShadokType &data)
Generic function to save/serialise ShadokType.
Definition:
main.cpp:43
DataStream
Generic DataStream class.
Definition:
data_stream_include.h:32
DataStream::data_stream
static bool data_stream(Stream &ds, T &data)
Dummy function to catch if a type is not specialised.
Definition:
data_stream_include.h:37
tmp_project
PhoenixInkscape
tmp_project
PhoenixDataStream
TESTS
TEST_ENUM
main.cpp
Generated on Fri Mar 14 2025 15:50:10 for PhoenixPresentation by
1.9.1