Directory: | ./ |
---|---|
File: | tmp_project/PhoenixString/src/PStream_impl.h |
Date: | 2024-07-27 10:53:27 |
Exec | Total | Coverage | |
---|---|---|---|
Lines: | 26 | 26 | 100.0% |
Branches: | 4 | 4 | 100.0% |
Line | Branch | Exec | Source |
---|---|---|---|
1 | /*************************************** | ||
2 | Auteur : Pierre Aubert | ||
3 | Mail : pierre.aubert@lapp.in2p3.fr | ||
4 | Licence : CeCILL-C | ||
5 | ****************************************/ | ||
6 | |||
7 | #ifndef __PSTREAM_IMPL_H__ | ||
8 | #define __PSTREAM_IMPL_H__ | ||
9 | |||
10 | #include "PStream.h" | ||
11 | |||
12 | ///Flux operator for stream | ||
13 | /** @param value : value to be put in the stream | ||
14 | * @return modified stream | ||
15 | */ | ||
16 | template<typename T> | ||
17 | 1 | PStream & PStream::operator << (const T & value){ | |
18 | 1 | write(value); | |
19 | 1 | return *this; | |
20 | } | ||
21 | |||
22 | ///Flux operator for stream | ||
23 | /** @param value : value to be read from the stream | ||
24 | * @return modified stream | ||
25 | */ | ||
26 | template<typename T> | ||
27 | 1 | PStream & PStream::operator >> (T & value){ | |
28 | 1 | read(value); | |
29 | 1 | return *this; | |
30 | } | ||
31 | |||
32 | ///Write a value into the stream | ||
33 | /** @param value : value to be written into the stream | ||
34 | * @return true on success, false otherwise | ||
35 | */ | ||
36 | template<typename T> | ||
37 | 1 | bool PStream::write(const T & value){ | |
38 | 1 | return fwrite((const void*)&value, sizeof(T), 1lu, p_fp) == 1lu; | |
39 | } | ||
40 | |||
41 | ///Write a table values into the stream | ||
42 | /** @param tabValue : table of values to be written into the stream | ||
43 | * @param nbValue : number of values of the table | ||
44 | * @return true on success, false otherwise | ||
45 | */ | ||
46 | template<typename T> | ||
47 | 3 | bool PStream::write(const T * tabValue, size_t nbValue){ | |
48 | 3 | return fwrite((const void*)tabValue, sizeof(T), nbValue, p_fp) == nbValue; | |
49 | } | ||
50 | |||
51 | ///Write a table values into the stream | ||
52 | /** @param tabValue : table of values to be written into the stream | ||
53 | * @param nbRow : number of rows of the matrix | ||
54 | * @param nbCol : number of columns of the matrix | ||
55 | * @param padding : padding of the rows | ||
56 | * @return true on success, false otherwise | ||
57 | */ | ||
58 | template<typename T> | ||
59 | 1 | bool PStream::write(const T * tabValue, size_t nbRow, size_t nbCol, size_t padding){ | |
60 | 1 | bool b(true); | |
61 | 1 | size_t rowSize(nbCol + padding); | |
62 |
2/2✓ Branch 0 taken 2 times.
✓ Branch 1 taken 1 times.
|
3 | for(size_t i(0lu); i < nbRow; ++i){ |
63 | 2 | b &= write(tabValue + i*rowSize, nbCol); | |
64 | } | ||
65 | 1 | return b; | |
66 | } | ||
67 | |||
68 | ///Read a value from the stream | ||
69 | /** @param value : value to be read from the stream | ||
70 | * @return true on success, false otherwise | ||
71 | */ | ||
72 | template<typename T> | ||
73 | 1 | bool PStream::read(T & value){ | |
74 | 1 | return fread((void*)&value, sizeof(T), 1lu, p_fp) == 1lu; | |
75 | } | ||
76 | |||
77 | ///Read a value from the stream | ||
78 | /** @param tabValue : table of values to be read from the stream | ||
79 | * @param nbValue : number of values of the table | ||
80 | */ | ||
81 | template<typename T> | ||
82 | 3 | bool PStream::read(T * tabValue, size_t nbValue){ | |
83 | 3 | return fread((void*)tabValue, sizeof(T), nbValue, p_fp) == nbValue; | |
84 | } | ||
85 | |||
86 | ///Read a table values from the stream | ||
87 | /** @param tabValue : table of values to be read from the stream | ||
88 | * @param nbRow : number of rows of the matrix | ||
89 | * @param nbCol : number of columns of the matrix | ||
90 | * @param padding : padding of the rows | ||
91 | * @return true on success, false otherwise | ||
92 | */ | ||
93 | template<typename T> | ||
94 | 1 | bool PStream::read(T * tabValue, size_t nbRow, size_t nbCol, size_t padding){ | |
95 | 1 | bool b(true); | |
96 | 1 | size_t rowSize(nbCol + padding); | |
97 |
2/2✓ Branch 0 taken 2 times.
✓ Branch 1 taken 1 times.
|
3 | for(size_t i(0lu); i < nbRow; ++i){ |
98 | 2 | b &= read(tabValue + i*rowSize, nbCol); | |
99 | } | ||
100 | 1 | return b; | |
101 | } | ||
102 | |||
103 | |||
104 | |||
105 | #endif | ||
106 | |||
107 |