├── .clang-format
├── .gitignore
├── LICENSE
├── Makefile
├── Makefile.base
├── README.md
├── RUNME
├── build
└── common.sh
├── c_plus_plus_serializer.h
└── examples
├── .clang-format
├── basic_example.cpp
├── bitfields_in_class_example.cpp
├── container_example.cpp
├── custom_class_example.cpp
├── deque_example.cpp
├── hexdump.cpp
├── hexdump.h
├── main.cpp
├── map_custom_class_example.cpp
├── map_example.cpp
├── map_string_to_list_of_strings_example.cpp
├── multiset_example.cpp
├── quicklz.cpp
├── quicklz.h
├── raw_memory.cpp
├── set_example.cpp
├── template_class_example.cpp
├── unordered_map_example.cpp
└── zipped_container_example.cpp
/.clang-format:
--------------------------------------------------------------------------------
1 | ---
2 | Language: Cpp
3 | # BasedOnStyle: LLVM
4 | AccessModifierOffset: -2
5 | AlignAfterOpenBracket: Align
6 | AlignConsecutiveMacros: true
7 | AlignConsecutiveAssignments: true
8 | AlignConsecutiveBitFields: true
9 | AlignConsecutiveDeclarations: true
10 | AlignEscapedNewlines: Right
11 | AlignOperands: Align
12 | AlignTrailingComments: true
13 | AllowAllArgumentsOnNextLine: true
14 | AllowAllConstructorInitializersOnNextLine: true
15 | AllowAllParametersOfDeclarationOnNextLine: true
16 | AllowShortEnumsOnASingleLine: true
17 | AllowShortBlocksOnASingleLine: Never
18 | AllowShortCaseLabelsOnASingleLine: true
19 | AllowShortFunctionsOnASingleLine: All
20 | AllowShortLambdasOnASingleLine: All
21 | AllowShortIfStatementsOnASingleLine: Never
22 | AllowShortLoopsOnASingleLine: false
23 | AlwaysBreakAfterDefinitionReturnType: None
24 | AlwaysBreakAfterReturnType: None
25 | AlwaysBreakBeforeMultilineStrings: true
26 | AlwaysBreakTemplateDeclarations: MultiLine
27 | AttributeMacros:
28 | - __capability
29 | BinPackArguments: true
30 | BinPackParameters: true
31 | BraceWrapping:
32 | AfterCaseLabel: true
33 | AfterClass: true
34 | AfterControlStatement: Never
35 | AfterEnum: true
36 | AfterFunction: true
37 | AfterNamespace: true
38 | AfterObjCDeclaration: true
39 | AfterStruct: true
40 | AfterUnion: true
41 | AfterExternBlock: true
42 | BeforeCatch: true
43 | BeforeElse: true
44 | BeforeLambdaBody: true
45 | BeforeWhile: true
46 | IndentBraces: true
47 | SplitEmptyFunction: true
48 | SplitEmptyRecord: true
49 | SplitEmptyNamespace: true
50 | BreakBeforeBinaryOperators: None
51 | BreakBeforeConceptDeclarations: true
52 | BreakBeforeBraces: Linux
53 | BreakBeforeInheritanceComma: false
54 | BreakInheritanceList: BeforeColon
55 | BreakBeforeTernaryOperators: true
56 | BreakConstructorInitializersBeforeComma: false
57 | BreakConstructorInitializers: BeforeColon
58 | BreakAfterJavaFieldAnnotations: false
59 | BreakStringLiterals: true
60 | ColumnLimit: 118
61 | CommentPragmas: '^ IWYU pragma:'
62 | CompactNamespaces: false
63 | ConstructorInitializerAllOnOneLineOrOnePerLine: false
64 | ConstructorInitializerIndentWidth: 4
65 | ContinuationIndentWidth: 4
66 | Cpp11BracedListStyle: true
67 | DeriveLineEnding: true
68 | DerivePointerAlignment: false
69 | DisableFormat: false
70 | EmptyLineBeforeAccessModifier: LogicalBlock
71 | ExperimentalAutoDetectBinPacking: false
72 | FixNamespaceComments: true
73 | ForEachMacros:
74 | - foreach
75 | - Q_FOREACH
76 | - BOOST_FOREACH
77 | StatementAttributeLikeMacros:
78 | - Q_EMIT
79 | IncludeBlocks: Preserve
80 | IncludeCategories:
81 | - Regex: '^"(llvm|llvm-c|clang|clang-c)/'
82 | Priority: 2
83 | SortPriority: 0
84 | CaseSensitive: false
85 | - Regex: '^(<|"(gtest|gmock|isl|json)/)'
86 | Priority: 3
87 | SortPriority: 0
88 | CaseSensitive: false
89 | - Regex: '.*'
90 | Priority: 1
91 | SortPriority: 0
92 | CaseSensitive: false
93 | IncludeIsMainRegex: '(Test)?$'
94 | IncludeIsMainSourceRegex: ''
95 | IndentCaseLabels: true
96 | IndentCaseBlocks: true
97 | IndentGotoLabels: true
98 | IndentPPDirectives: None
99 | IndentExternBlock: AfterExternBlock
100 | IndentRequires: false
101 | IndentWidth: 2
102 | IndentWrappedFunctionNames: true
103 | InsertTrailingCommas: None
104 | JavaScriptQuotes: Leave
105 | JavaScriptWrapImports: true
106 | KeepEmptyLinesAtTheStartOfBlocks: true
107 | MacroBlockBegin: ''
108 | MacroBlockEnd: ''
109 | MaxEmptyLinesToKeep: 1
110 | NamespaceIndentation: None
111 | ObjCBinPackProtocolList: Auto
112 | ObjCBlockIndentWidth: 2
113 | ObjCBreakBeforeNestedBlockParam: true
114 | ObjCSpaceAfterProperty: false
115 | ObjCSpaceBeforeProtocolList: true
116 | PenaltyBreakAssignment: 2
117 | PenaltyBreakBeforeFirstCallParameter: 19
118 | PenaltyBreakComment: 300
119 | PenaltyBreakFirstLessLess: 120
120 | PenaltyBreakString: 1000
121 | PenaltyBreakTemplateDeclaration: 10
122 | PenaltyExcessCharacter: 1000000
123 | PenaltyReturnTypeOnItsOwnLine: 60
124 | PenaltyIndentedWhitespace: 0
125 | PointerAlignment: Right
126 | ReflowComments: true
127 | SortIncludes: true
128 | SortJavaStaticImport: Before
129 | SortUsingDeclarations: true
130 | SpaceAfterCStyleCast: true
131 | SpaceAfterLogicalNot: true
132 | SpaceAfterTemplateKeyword: true
133 | SpaceBeforeAssignmentOperators: true
134 | SpaceBeforeCaseColon: true
135 | SpaceBeforeCpp11BracedList: true
136 | SpaceBeforeCtorInitializerColon: true
137 | SpaceBeforeInheritanceColon: true
138 | SpaceBeforeParens: ControlStatements
139 | SpaceAroundPointerQualifiers: Default
140 | SpaceBeforeRangeBasedForLoopColon: true
141 | SpaceInEmptyBlock: false
142 | SpaceInEmptyParentheses: false
143 | SpacesBeforeTrailingComments: 1
144 | SpacesInAngles: true
145 | SpacesInConditionalStatement: false
146 | SpacesInContainerLiterals: true
147 | SpacesInCStyleCastParentheses: false
148 | SpacesInParentheses: false
149 | SpacesInSquareBrackets: true
150 | SpaceBeforeSquareBrackets: false
151 | BitFieldColonSpacing: Both
152 | Standard: Latest
153 | StatementMacros:
154 | - Q_UNUSED
155 | - QT_REQUIRE_VERSION
156 | TabWidth: 2
157 | UseCRLF: false
158 | UseTab: Never
159 | WhitespaceSensitiveMacros:
160 | - STRINGIZE
161 | - PP_STRINGIZE
162 | - BOOST_PP_STRINGIZE
163 | - NS_SWIFT_NAME
164 | - CF_SWIFT_NAME
165 | ...
166 |
167 |
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | # Prerequisites
2 | *.d
3 |
4 | # Compiled Object files
5 | *.slo
6 | *.lo
7 | *.o
8 | *.obj
9 |
10 | # Precompiled Headers
11 | *.gch
12 | *.pch
13 |
14 | # Compiled Dynamic libraries
15 | *.so
16 | *.dylib
17 | *.dll
18 |
19 | # Fortran module files
20 | *.mod
21 | *.smod
22 |
23 | # Compiled Static libraries
24 | *.lai
25 | *.la
26 | *.a
27 | *.lib
28 |
29 | # Executables
30 | *.exe
31 | *.out
32 | *.app
33 |
34 | basic_example.bin
35 | c_plus_plus_serializer
36 | container_example.bin
37 | custom_bitset_class.bin
38 | custom_class.bin
39 | deque_of_strings.bin
40 | map_of_custom_class.bin
41 | map_of_string_to_list_of_strings.bin
42 | map_of_strings.bin
43 | multiset_of_strings.bin
44 | raw_memory_example.bin
45 | set_of_strings.bin
46 | template_class.bin
47 | unordered_map_of_strings.bin
48 | zipper_container_example.bin
49 |
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | GNU GENERAL PUBLIC LICENSE
2 | Version 2, June 1991
3 |
4 | Copyright (C) 1989, 1991 Free Software Foundation, Inc.,
5 | 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
6 | Everyone is permitted to copy and distribute verbatim copies
7 | of this license document, but changing it is not allowed.
8 |
9 | Preamble
10 |
11 | The licenses for most software are designed to take away your
12 | freedom to share and change it. By contrast, the GNU General Public
13 | License is intended to guarantee your freedom to share and change free
14 | software--to make sure the software is free for all its users. This
15 | General Public License applies to most of the Free Software
16 | Foundation's software and to any other program whose authors commit to
17 | using it. (Some other Free Software Foundation software is covered by
18 | the GNU Lesser General Public License instead.) You can apply it to
19 | your programs, too.
20 |
21 | When we speak of free software, we are referring to freedom, not
22 | price. Our General Public Licenses are designed to make sure that you
23 | have the freedom to distribute copies of free software (and charge for
24 | this service if you wish), that you receive source code or can get it
25 | if you want it, that you can change the software or use pieces of it
26 | in new free programs; and that you know you can do these things.
27 |
28 | To protect your rights, we need to make restrictions that forbid
29 | anyone to deny you these rights or to ask you to surrender the rights.
30 | These restrictions translate to certain responsibilities for you if you
31 | distribute copies of the software, or if you modify it.
32 |
33 | For example, if you distribute copies of such a program, whether
34 | gratis or for a fee, you must give the recipients all the rights that
35 | you have. You must make sure that they, too, receive or can get the
36 | source code. And you must show them these terms so they know their
37 | rights.
38 |
39 | We protect your rights with two steps: (1) copyright the software, and
40 | (2) offer you this license which gives you legal permission to copy,
41 | distribute and/or modify the software.
42 |
43 | Also, for each author's protection and ours, we want to make certain
44 | that everyone understands that there is no warranty for this free
45 | software. If the software is modified by someone else and passed on, we
46 | want its recipients to know that what they have is not the original, so
47 | that any problems introduced by others will not reflect on the original
48 | authors' reputations.
49 |
50 | Finally, any free program is threatened constantly by software
51 | patents. We wish to avoid the danger that redistributors of a free
52 | program will individually obtain patent licenses, in effect making the
53 | program proprietary. To prevent this, we have made it clear that any
54 | patent must be licensed for everyone's free use or not licensed at all.
55 |
56 | The precise terms and conditions for copying, distribution and
57 | modification follow.
58 |
59 | GNU GENERAL PUBLIC LICENSE
60 | TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
61 |
62 | 0. This License applies to any program or other work which contains
63 | a notice placed by the copyright holder saying it may be distributed
64 | under the terms of this General Public License. The "Program", below,
65 | refers to any such program or work, and a "work based on the Program"
66 | means either the Program or any derivative work under copyright law:
67 | that is to say, a work containing the Program or a portion of it,
68 | either verbatim or with modifications and/or translated into another
69 | language. (Hereinafter, translation is included without limitation in
70 | the term "modification".) Each licensee is addressed as "you".
71 |
72 | Activities other than copying, distribution and modification are not
73 | covered by this License; they are outside its scope. The act of
74 | running the Program is not restricted, and the output from the Program
75 | is covered only if its contents constitute a work based on the
76 | Program (independent of having been made by running the Program).
77 | Whether that is true depends on what the Program does.
78 |
79 | 1. You may copy and distribute verbatim copies of the Program's
80 | source code as you receive it, in any medium, provided that you
81 | conspicuously and appropriately publish on each copy an appropriate
82 | copyright notice and disclaimer of warranty; keep intact all the
83 | notices that refer to this License and to the absence of any warranty;
84 | and give any other recipients of the Program a copy of this License
85 | along with the Program.
86 |
87 | You may charge a fee for the physical act of transferring a copy, and
88 | you may at your option offer warranty protection in exchange for a fee.
89 |
90 | 2. You may modify your copy or copies of the Program or any portion
91 | of it, thus forming a work based on the Program, and copy and
92 | distribute such modifications or work under the terms of Section 1
93 | above, provided that you also meet all of these conditions:
94 |
95 | a) You must cause the modified files to carry prominent notices
96 | stating that you changed the files and the date of any change.
97 |
98 | b) You must cause any work that you distribute or publish, that in
99 | whole or in part contains or is derived from the Program or any
100 | part thereof, to be licensed as a whole at no charge to all third
101 | parties under the terms of this License.
102 |
103 | c) If the modified program normally reads commands interactively
104 | when run, you must cause it, when started running for such
105 | interactive use in the most ordinary way, to print or display an
106 | announcement including an appropriate copyright notice and a
107 | notice that there is no warranty (or else, saying that you provide
108 | a warranty) and that users may redistribute the program under
109 | these conditions, and telling the user how to view a copy of this
110 | License. (Exception: if the Program itself is interactive but
111 | does not normally print such an announcement, your work based on
112 | the Program is not required to print an announcement.)
113 |
114 | These requirements apply to the modified work as a whole. If
115 | identifiable sections of that work are not derived from the Program,
116 | and can be reasonably considered independent and separate works in
117 | themselves, then this License, and its terms, do not apply to those
118 | sections when you distribute them as separate works. But when you
119 | distribute the same sections as part of a whole which is a work based
120 | on the Program, the distribution of the whole must be on the terms of
121 | this License, whose permissions for other licensees extend to the
122 | entire whole, and thus to each and every part regardless of who wrote it.
123 |
124 | Thus, it is not the intent of this section to claim rights or contest
125 | your rights to work written entirely by you; rather, the intent is to
126 | exercise the right to control the distribution of derivative or
127 | collective works based on the Program.
128 |
129 | In addition, mere aggregation of another work not based on the Program
130 | with the Program (or with a work based on the Program) on a volume of
131 | a storage or distribution medium does not bring the other work under
132 | the scope of this License.
133 |
134 | 3. You may copy and distribute the Program (or a work based on it,
135 | under Section 2) in object code or executable form under the terms of
136 | Sections 1 and 2 above provided that you also do one of the following:
137 |
138 | a) Accompany it with the complete corresponding machine-readable
139 | source code, which must be distributed under the terms of Sections
140 | 1 and 2 above on a medium customarily used for software interchange; or,
141 |
142 | b) Accompany it with a written offer, valid for at least three
143 | years, to give any third party, for a charge no more than your
144 | cost of physically performing source distribution, a complete
145 | machine-readable copy of the corresponding source code, to be
146 | distributed under the terms of Sections 1 and 2 above on a medium
147 | customarily used for software interchange; or,
148 |
149 | c) Accompany it with the information you received as to the offer
150 | to distribute corresponding source code. (This alternative is
151 | allowed only for noncommercial distribution and only if you
152 | received the program in object code or executable form with such
153 | an offer, in accord with Subsection b above.)
154 |
155 | The source code for a work means the preferred form of the work for
156 | making modifications to it. For an executable work, complete source
157 | code means all the source code for all modules it contains, plus any
158 | associated interface definition files, plus the build used to
159 | control compilation and installation of the executable. However, as a
160 | special exception, the source code distributed need not include
161 | anything that is normally distributed (in either source or binary
162 | form) with the major components (compiler, kernel, and so on) of the
163 | operating system on which the executable runs, unless that component
164 | itself accompanies the executable.
165 |
166 | If distribution of executable or object code is made by offering
167 | access to copy from a designated place, then offering equivalent
168 | access to copy the source code from the same place counts as
169 | distribution of the source code, even though third parties are not
170 | compelled to copy the source along with the object code.
171 |
172 | 4. You may not copy, modify, sublicense, or distribute the Program
173 | except as expressly provided under this License. Any attempt
174 | otherwise to copy, modify, sublicense or distribute the Program is
175 | void, and will automatically terminate your rights under this License.
176 | However, parties who have received copies, or rights, from you under
177 | this License will not have their licenses terminated so long as such
178 | parties remain in full compliance.
179 |
180 | 5. You are not required to accept this License, since you have not
181 | signed it. However, nothing else grants you permission to modify or
182 | distribute the Program or its derivative works. These actions are
183 | prohibited by law if you do not accept this License. Therefore, by
184 | modifying or distributing the Program (or any work based on the
185 | Program), you indicate your acceptance of this License to do so, and
186 | all its terms and conditions for copying, distributing or modifying
187 | the Program or works based on it.
188 |
189 | 6. Each time you redistribute the Program (or any work based on the
190 | Program), the recipient automatically receives a license from the
191 | original licensor to copy, distribute or modify the Program subject to
192 | these terms and conditions. You may not impose any further
193 | restrictions on the recipients' exercise of the rights granted herein.
194 | You are not responsible for enforcing compliance by third parties to
195 | this License.
196 |
197 | 7. If, as a consequence of a court judgment or allegation of patent
198 | infringement or for any other reason (not limited to patent issues),
199 | conditions are imposed on you (whether by court order, agreement or
200 | otherwise) that contradict the conditions of this License, they do not
201 | excuse you from the conditions of this License. If you cannot
202 | distribute so as to satisfy simultaneously your obligations under this
203 | License and any other pertinent obligations, then as a consequence you
204 | may not distribute the Program at all. For example, if a patent
205 | license would not permit royalty-free redistribution of the Program by
206 | all those who receive copies directly or indirectly through you, then
207 | the only way you could satisfy both it and this License would be to
208 | refrain entirely from distribution of the Program.
209 |
210 | If any portion of this section is held invalid or unenforceable under
211 | any particular circumstance, the balance of the section is intended to
212 | apply and the section as a whole is intended to apply in other
213 | circumstances.
214 |
215 | It is not the purpose of this section to induce you to infringe any
216 | patents or other property right claims or to contest validity of any
217 | such claims; this section has the sole purpose of protecting the
218 | integrity of the free software distribution system, which is
219 | implemented by public license practices. Many people have made
220 | generous contributions to the wide range of software distributed
221 | through that system in reliance on consistent application of that
222 | system; it is up to the author/donor to decide if he or she is willing
223 | to distribute software through any other system and a licensee cannot
224 | impose that choice.
225 |
226 | This section is intended to make thoroughly clear what is believed to
227 | be a consequence of the rest of this License.
228 |
229 | 8. If the distribution and/or use of the Program is restricted in
230 | certain countries either by patents or by copyrighted interfaces, the
231 | original copyright holder who places the Program under this License
232 | may add an explicit geographical distribution limitation excluding
233 | those countries, so that distribution is permitted only in or among
234 | countries not thus excluded. In such case, this License incorporates
235 | the limitation as if written in the body of this License.
236 |
237 | 9. The Free Software Foundation may publish revised and/or new versions
238 | of the General Public License from time to time. Such new versions will
239 | be similar in spirit to the present version, but may differ in detail to
240 | address new problems or concerns.
241 |
242 | Each version is given a distinguishing version number. If the Program
243 | specifies a version number of this License which applies to it and "any
244 | later version", you have the option of following the terms and conditions
245 | either of that version or of any later version published by the Free
246 | Software Foundation. If the Program does not specify a version number of
247 | this License, you may choose any version ever published by the Free Software
248 | Foundation.
249 |
250 | 10. If you wish to incorporate parts of the Program into other free
251 | programs whose distribution conditions are different, write to the author
252 | to ask for permission. For software which is copyrighted by the Free
253 | Software Foundation, write to the Free Software Foundation; we sometimes
254 | make exceptions for this. Our decision will be guided by the two goals
255 | of preserving the free status of all derivatives of our free software and
256 | of promoting the sharing and reuse of software generally.
257 |
258 | NO WARRANTY
259 |
260 | 11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY
261 | FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN
262 | OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES
263 | PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED
264 | OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
265 | MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS
266 | TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE
267 | PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING,
268 | REPAIR OR CORRECTION.
269 |
270 | 12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
271 | WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR
272 | REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES,
273 | INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING
274 | OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED
275 | TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY
276 | YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER
277 | PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE
278 | POSSIBILITY OF SUCH DAMAGES.
279 |
280 | END OF TERMS AND CONDITIONS
281 |
282 | How to Apply These Terms to Your New Programs
283 |
284 | If you develop a new program, and you want it to be of the greatest
285 | possible use to the public, the best way to achieve this is to make it
286 | free software which everyone can redistribute and change under these terms.
287 |
288 | To do so, attach the following notices to the program. It is safest
289 | to attach them to the start of each source file to most effectively
290 | convey the exclusion of warranty; and each file should have at least
291 | the "copyright" line and a pointer to where the full notice is found.
292 |
293 | {description}
294 | Copyright (C) {year} {fullname}
295 |
296 | This program is free software; you can redistribute it and/or modify
297 | it under the terms of the GNU General Public License as published by
298 | the Free Software Foundation; either version 2 of the License, or
299 | (at your option) any later version.
300 |
301 | This program is distributed in the hope that it will be useful,
302 | but WITHOUT ANY WARRANTY; without even the implied warranty of
303 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
304 | GNU General Public License for more details.
305 |
306 | You should have received a copy of the GNU General Public License along
307 | with this program; if not, write to the Free Software Foundation, Inc.,
308 | 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
309 |
310 | Also add information on how to contact you by electronic and paper mail.
311 |
312 | If the program is interactive, make it output a short notice like this
313 | when it starts in an interactive mode:
314 |
315 | Gnomovision version 69, Copyright (C) year name of author
316 | Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
317 | This is free software, and you are welcome to redistribute it
318 | under certain conditions; type `show c' for details.
319 |
320 | The hypothetical commands `show w' and `show c' should show the appropriate
321 | parts of the General Public License. Of course, the commands you use may
322 | be called something other than `show w' and `show c'; they could even be
323 | mouse-clicks or menu items--whatever suits your program.
324 |
325 | You should also get your employer (if you work as a programmer) or your
326 | school, if any, to sign a "copyright disclaimer" for the program, if
327 | necessary. Here is a sample; alter the names:
328 |
329 | Yoyodyne, Inc., hereby disclaims all copyright interest in the program
330 | `Gnomovision' (which makes passes at compilers) written by James Hacker.
331 |
332 | {signature of Ty Coon}, 1 April 1989
333 | Ty Coon, President of Vice
334 |
335 | This General Public License does not permit incorporating your program into
336 | proprietary programs. If your program is a subroutine library, you may
337 | consider it more useful to permit linking proprietary applications with the
338 | library. If this is what you want to do, use the GNU Lesser General
339 | Public License instead of this License.
340 |
--------------------------------------------------------------------------------
/Makefile:
--------------------------------------------------------------------------------
1 | COMPILER_FLAGS=-Werror -g -ggdb3 -O3 -fstack-protector-all -I . -I examples # AUTOGEN
2 |
3 | CLANG_COMPILER_WARNINGS=-Wall # AUTOGEN
4 | GCC_COMPILER_WARNINGS=-Wall # AUTOGEN
5 | GXX_COMPILER_WARNINGS=-Wall # AUTOGEN
6 | COMPILER_WARNINGS=$(GCC_COMPILER_WARNINGS) # AUTOGEN
7 | COMPILER_WARNINGS=$(GXX_COMPILER_WARNINGS) # AUTOGEN
8 | COMPILER_WARNINGS=$(CLANG_COMPILER_WARNINGS) # AUTOGEN
9 | CXX=clang++ # AUTOGEN
10 |
11 | EXE= # AUTOGEN
12 | LDLIBS= # AUTOGEN
13 | CFLAGS=$(COMPILER_FLAGS) $(COMPILER_WARNINGS) # AUTOGEN
14 | NAME=c_plus_plus_serializer
15 | OBJDIR=.o
16 |
17 | TARGET_OBJECTS=\
18 | $(OBJDIR)/main.o \
19 | $(OBJDIR)/basic_example.o \
20 | $(OBJDIR)/bitfields_in_class_example.o \
21 | $(OBJDIR)/container_example.o \
22 | $(OBJDIR)/custom_class_example.o \
23 | $(OBJDIR)/deque_example.o \
24 | $(OBJDIR)/hexdump.o \
25 | $(OBJDIR)/map_custom_class_example.o \
26 | $(OBJDIR)/map_example.o \
27 | $(OBJDIR)/map_string_to_list_of_strings_example.o \
28 | $(OBJDIR)/multiset_example.o \
29 | $(OBJDIR)/quicklz.o \
30 | $(OBJDIR)/raw_memory.o \
31 | $(OBJDIR)/set_example.o \
32 | $(OBJDIR)/template_class_example.o \
33 | $(OBJDIR)/unordered_map_example.o \
34 | $(OBJDIR)/zipped_container_example.o \
35 |
36 | EXTRA_CFLAGS=-std=c++11
37 | #EXTRA_CFLAGS+=-DDEBUG_C_PLUS_PLUS_SERIALIZER
38 | #EXTRA_CFLAGS+=-DUSE_SIZE_T
39 |
40 | $(OBJDIR)/%.o: examples/%.cpp
41 | $(shell echo clang-format -i $<)
42 | @echo $(CXX) $(EXTRA_CFLAGS) $(CFLAGS) -c -o $@ $<
43 | @$(CXX) $(EXTRA_CFLAGS) $(CFLAGS) -c -o $@ $<
44 |
45 | #
46 | # link
47 | #
48 | TARGET=$(NAME)$(EXE)
49 | $(TARGET): $(TARGET_OBJECTS)
50 | $(CXX) $(TARGET_OBJECTS) $(LDLIBS) -o $(TARGET)
51 |
52 | #
53 | # To force clean and avoid "up to date" warning.
54 | #
55 | .PHONY: clean
56 | .PHONY: clobber
57 |
58 | clean:
59 | rm -rf $(TARGET) $(OBJDIR)/*.o
60 |
61 | clobber: clean
62 | mkdir -p $(OBJDIR)
63 |
64 | all: $(TARGET)
65 |
66 | format:
67 | git diff -U0 HEAD^ | clang-format-diff -i -p1
68 |
--------------------------------------------------------------------------------
/Makefile.base:
--------------------------------------------------------------------------------
1 | NAME=c_plus_plus_serializer
2 | OBJDIR=.o
3 |
4 | TARGET_OBJECTS=\
5 | $(OBJDIR)/main.o \
6 | $(OBJDIR)/basic_example.o \
7 | $(OBJDIR)/bitfields_in_class_example.o \
8 | $(OBJDIR)/container_example.o \
9 | $(OBJDIR)/custom_class_example.o \
10 | $(OBJDIR)/deque_example.o \
11 | $(OBJDIR)/hexdump.o \
12 | $(OBJDIR)/map_custom_class_example.o \
13 | $(OBJDIR)/map_example.o \
14 | $(OBJDIR)/map_string_to_list_of_strings_example.o \
15 | $(OBJDIR)/multiset_example.o \
16 | $(OBJDIR)/quicklz.o \
17 | $(OBJDIR)/raw_memory.o \
18 | $(OBJDIR)/set_example.o \
19 | $(OBJDIR)/template_class_example.o \
20 | $(OBJDIR)/unordered_map_example.o \
21 | $(OBJDIR)/zipped_container_example.o \
22 |
23 | EXTRA_CFLAGS=-std=c++11
24 | #EXTRA_CFLAGS+=-DDEBUG_C_PLUS_PLUS_SERIALIZER
25 | #EXTRA_CFLAGS+=-DUSE_SIZE_T
26 |
27 | $(OBJDIR)/%.o: examples/%.cpp
28 | $(shell echo clang-format -i $<)
29 | @echo $(CXX) $(EXTRA_CFLAGS) $(CFLAGS) -c -o $@ $<
30 | @$(CXX) $(EXTRA_CFLAGS) $(CFLAGS) -c -o $@ $<
31 |
32 | #
33 | # link
34 | #
35 | TARGET=$(NAME)$(EXE)
36 | $(TARGET): $(TARGET_OBJECTS)
37 | $(CXX) $(TARGET_OBJECTS) $(LDLIBS) -o $(TARGET)
38 |
39 | #
40 | # To force clean and avoid "up to date" warning.
41 | #
42 | .PHONY: clean
43 | .PHONY: clobber
44 |
45 | clean:
46 | rm -rf $(TARGET) $(OBJDIR)/*.o
47 |
48 | clobber: clean
49 | mkdir -p $(OBJDIR)
50 |
51 | all: $(TARGET)
52 |
53 | format:
54 | git diff -U0 HEAD^ | clang-format-diff -i -p1
55 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | Simple C++ 11 header-only serializer
2 | ====================================
3 |
4 | Have you ever wanted a really minimal header-only C++11 serializer? Of course
5 | you have! Having tried some other implementations I found them too hard to
6 | maintain and grok when they inevitably failed to compile under the latest
7 | g++ version. Hopefully this one is simple enough to avoid such issues. All you
8 | need to do is add
9 |
10 |
11 | #include "c_plus_plus_serializer.h"
12 |
13 |
14 | in your project for any files that need to do serialization.
15 |
16 | The data is saved in raw binary format, hence this is only loadable on the
17 | same architecture that it was saved in.
18 |
19 | Credits
20 | =======
21 |
22 | This work was based on some of the ideas in [this link](https://stackoverflow.com/questions/1559254/are-there-binary-memory-streams-in-c), specifically,
23 | those by Samuel Powell.
24 |
25 | Tested types
26 | ============
27 |
28 | - POD types (char, wchar_t, int, float, double etc...)
29 | - std::array (multidimensional works too)
30 | - std::list
31 | - std::map
32 | - std::deque
33 | - std::multiset
34 | - std::pair
35 | - std::set
36 | - std::string, std::wstring
37 | - std::unordered_map
38 | - std::vector
39 | - custom class
40 | - nested types e.g. std::map< std::string, std::list>
41 |
42 | POD serialization
43 | =================
44 |
45 | ```C++
46 | #include "c_plus_plus_serializer.h"
47 |
48 | static void serialize (std::ofstream out)
49 | {
50 | char a = 42;
51 | unsigned short b = 65535;
52 | int c = 123456;
53 | float d = std::numeric_limits::max();
54 | double e = std::numeric_limits::max();
55 | std::string f("hello");
56 | wchar_t g = L'💩';
57 | std::wstring h(L"wide string 💩");
58 |
59 | out << bits(a) << bits(b) << bits(c) << bits(d);
60 | out << bits(e) << bits(f) << bits(g) << bits(h);
61 | }
62 |
63 | static void deserialize (std::ifstream in)
64 | {
65 | char a;
66 | unsigned short b;
67 | int c;
68 | float d;
69 | double e;
70 | std::string f;
71 | wchar_t g;
72 | std::wstring h;
73 |
74 | in >> bits(a) >> bits(b) >> bits(c) >> bits(d);
75 | in >> bits(e) >> bits(f) >> bits(g) >> bits(h);
76 | }
77 | ```
78 |
79 | Container serialization
80 | =======================
81 |
82 | ```C++
83 | #include "c_plus_plus_serializer.h"
84 |
85 | static void serialize (std::ofstream out)
86 | {
87 | std::initializer_list< std::string > d1 = {"vec-elem1", "vec-elem2"};
88 | std::vector< std::string > a(d1);
89 |
90 | std::initializer_list< std::string > d2 = {"list-elem1", "list-elem2"};
91 | std::list< std::string > b(d2);
92 |
93 | std::array< std::string, 2> c = {"arr-elem1", "arr-elem2"};
94 |
95 | //
96 | // 2d array
97 | //
98 | std::array< std::array, 3> d;
99 | d[0][0] = '0'; d[0][1] = '1';
100 | d[1][0] = '2'; d[1][1] = '3';
101 | d[2][0] = '4'; d[2][1] = '5';
102 |
103 | //
104 | // 3d array
105 | //
106 | std::array< std::array< std::array, 3>, 4> ddd;
107 | ddd[0][0][0] = 'a'; ddd[0][0][1] = 'b';
108 | ddd[0][1][0] = 'c'; ddd[0][1][1] = 'd';
109 | ddd[0][2][0] = 'e'; ddd[0][2][1] = 'f';
110 | ddd[1][0][0] = 'g'; ddd[1][0][1] = 'h';
111 | ddd[1][1][0] = 'i'; ddd[1][1][1] = 'j';
112 | ddd[1][2][0] = 'k'; ddd[1][2][1] = 'l';
113 | ddd[2][0][0] = 'm'; ddd[2][0][1] = 'n';
114 | ddd[2][1][0] = 'o'; ddd[2][1][1] = 'p';
115 | ddd[2][2][0] = 'q'; ddd[2][2][1] = 'r';
116 | ddd[3][0][0] = 's'; ddd[3][0][1] = 't';
117 | ddd[3][1][0] = 'u'; ddd[3][1][1] = 'v';
118 | ddd[3][2][0] = 'w'; ddd[3][2][1] = 'x';
119 |
120 | out << bits(a) << bits(b) << bits(c) << bits(dd) << bits(ddd);
121 | }
122 |
123 | static void deserialize (std::ifstream in)
124 | {
125 | std::string f;
126 | std::vector< std::string > a;
127 | std::list< std::string > b;
128 | std::array< std::string, 2> c;
129 | std::array< std::array, 3> d;
130 | std::array< std::array< std::array, 3>, 4> ddd;
131 |
132 | in >> bits(a) >> bits(b) >> bits(c) >> bits(dd) >> bits(ddd);
133 | }
134 | ```
135 |
136 | Map serialization
137 | =================
138 |
139 | ```C++
140 | static void serialize (std::ofstream out)
141 | {
142 | std::map< std::string, std::string > m;
143 | m.insert(std::make_pair(std::string("key1"), std::string("value1")));
144 | m.insert(std::make_pair(std::string("key2"), std::string("value2")));
145 | m.insert(std::make_pair(std::string("key3"), std::string("value3")));
146 | m.insert(std::make_pair(std::string("key4"), std::string("value4")));
147 | out << bits(m);
148 | }
149 |
150 | static void deserialize (std::ifstream in)
151 | {
152 | std::map< std::string, std::string > m;
153 | in >> bits(m);
154 | }
155 | ```
156 |
157 | Unordered map serialization
158 | ===========================
159 |
160 | ```C++
161 | static void serialize (std::ofstream out)
162 | {
163 | std::unordered_map< std::string, std::string > m;
164 | m.insert(std::make_pair(std::string("key1"), std::string("value1")));
165 | m.insert(std::make_pair(std::string("key2"), std::string("value2")));
166 | m.insert(std::make_pair(std::string("key3"), std::string("value3")));
167 | m.insert(std::make_pair(std::string("key4"), std::string("value4")));
168 | out << bits(m);
169 | }
170 |
171 | static void deserialize (std::ifstream in)
172 | {
173 | std::unordered_map< std::string, std::string > m;
174 | in >> bits(m);
175 | }
176 | ```
177 |
178 | std::map< std::string, std::list > example
179 | ========================================
180 |
181 | ```C++
182 | static void serialize (std::ofstream out)
183 | {
184 | std::map< std::string, std::list< std::string > > m;
185 |
186 | std::initializer_list< std::string > L1 = {"list-elem1", "list-elem2"};
187 | std::list< std::string > l1(L1);
188 | std::initializer_list< std::string > L2 = {"list-elem3", "list-elem4"};
189 | std::list< std::string > l2(L2);
190 |
191 | m.insert(std::make_pair(std::string("key1"), l1));
192 | m.insert(std::make_pair(std::string("key2"), l2));
193 |
194 | out << bits(m);
195 | }
196 |
197 | static void deserialize (std::ifstream in)
198 | {
199 | std::map< std::string, std::list< std::string > > m;
200 |
201 | in >> bits(m);
202 | }
203 | ```
204 |
205 | Set serialization
206 | =================
207 |
208 | ```C++
209 | static void serialize (std::ofstream out)
210 | {
211 | std::set< std::string > m;
212 | m.insert(std::string("key1"));
213 | m.insert(std::string("key2"));
214 | m.insert(std::string("key3"));
215 | m.insert(std::string("key4"));
216 | out << bits(m);
217 | }
218 |
219 | static void deserialize (std::ifstream in)
220 | {
221 | std::set< std::string > m;
222 | in >> bits(m);
223 | }
224 | ```
225 |
226 | Multiset serialization
227 | ======================
228 |
229 | ```C++
230 | static void serialize (std::ofstream out)
231 | {
232 | std::multiset< std::string > m;
233 | m.insert(std::string("key1"));
234 | m.insert(std::string("key1"));
235 | m.insert(std::string("key1"));
236 | m.insert(std::string("key1"));
237 | m.insert(std::string("key2"));
238 | m.insert(std::string("key3"));
239 | m.insert(std::string("key4"));
240 | out << bits(m);
241 | }
242 |
243 | static void deserialize (std::ifstream in)
244 | {
245 | std::multiset< std::string > m;
246 | in >> bits(m);
247 | }
248 | ```
249 |
250 | Deque serialization
251 | ===================
252 |
253 | ```C++
254 | static void serialize (std::ofstream out)
255 | {
256 | std::deque< std::string > m;
257 | m.push_front(std::string("key1"));
258 | m.push_front(std::string("key2"));
259 | m.push_back(std::string("key3"));
260 | m.push_back(std::string("key4"));
261 | out << bits(m);
262 | }
263 |
264 | static void deserialize (std::ifstream in)
265 | {
266 | std::deque< std::string > m;
267 | in >> bits(m);
268 | }
269 | ```
270 |
271 | User defined class serialization
272 | ================================
273 |
274 | ```C++
275 | class Custom {
276 | public:
277 | int a;
278 | std::string b;
279 | std::vector< std::string > c;
280 |
281 | friend std::ostream& operator<<(std::ostream &out,
282 | Bits my)
283 | {
284 | out << bits(my.t.a) << bits(my.t.b) << bits(my.t.c);
285 | return (out);
286 | }
287 |
288 | friend std::istream& operator>>(std::istream &in,
289 | Bits my)
290 | {
291 | in >> bits(my.t.a) >> bits(my.t.b) >> bits(my.t.c);
292 | return (in);
293 | }
294 | };
295 | ```
296 |
297 | Serializing a custom template class
298 | ===================================
299 |
300 | ```C++
301 | template class MyPoint
302 | {
303 | public:
304 | T x {};
305 | T y {};
306 |
307 | MyPoint (void) : x(0), y(0) {};
308 |
309 | MyPoint (T x, T y) : x(x), y(y) { }
310 |
311 | friend std::ostream& operator<<(std::ostream &out,
312 | Bits const my)
313 | {
314 | out << bits(my.t.x) << bits(my.t.y);
315 | return (out);
316 | }
317 |
318 | friend std::istream& operator>>(std::istream &in, Bits my)
319 | {
320 | in >> bits(my.t.x) >> bits(my.t.y);
321 | return (in);
322 | }
323 |
324 | friend std::ostream& operator << (std::ostream &out, const MyPoint &my)
325 | {
326 | out << "(" << my.x << ", " << my.y << ")";
327 | return (out);
328 | }
329 | };
330 |
331 | typedef MyPoint IntPoint;
332 | typedef MyPoint FloatPoint;
333 | typedef MyPoint DoublePoint;
334 |
335 | static void serialize (std::ofstream out)
336 | {
337 | out << bits(IntPoint(1, 2));
338 | out << bits(FloatPoint(1.1, 2.2));
339 | out << bits(DoublePoint(3.3, 4.4));
340 | }
341 |
342 | static void deserialize (std::ifstream in)
343 | {
344 | IntPoint a;
345 | FloatPoint b;
346 | DoublePoint c;
347 |
348 | in >> bits(a);
349 | in >> bits(b);
350 | in >> bits(c);
351 | }
352 | ```
353 |
354 | User defined class serialization (more complex one, a map of classes)
355 | =====================================================================
356 |
357 | ```C++
358 | class Custom {
359 | public:
360 | int a;
361 | std::string b;
362 | std::vector< std::string > c;
363 |
364 | friend std::ostream& operator<<(std::ostream &out,
365 | Bits my)
366 | {
367 | out << bits(my.t.a) << bits(my.t.b) << bits(my.t.c);
368 | return (out);
369 | }
370 |
371 | friend std::istream& operator>>(std::istream &in,
372 | Bits my)
373 | {
374 | in >> bits(my.t.a) >> bits(my.t.b) >> bits(my.t.c);
375 | return (in);
376 | }
377 |
378 | friend std::ostream& operator<<(std::ostream &out,
379 | class Custom &my)
380 | {
381 | out << "a:" << my.a << " b:" << my.b;
382 |
383 | out << " c:[" << my.c.size() << " elems]:";
384 | for (auto v : my.c) {
385 | out << v << " ";
386 | }
387 | out << std::endl;
388 |
389 | return (out);
390 | }
391 | };
392 |
393 | static void serialize (...)
394 | {
395 | std::map< std::string, class Custom > m;
396 |
397 | auto c1 = Custom();
398 | c1.a = 1;
399 | c1.b = "hello";
400 | std::initializer_list< std::string > L1 = {"vec-elem1", "vec-elem2"};
401 | std::vector< std::string > l1(L1);
402 | c1.c = l1;
403 |
404 | auto c2 = Custom();
405 | c2.a = 2;
406 | c2.b = "there";
407 | std::initializer_list< std::string > L2 = {"vec-elem3", "vec-elem4"};
408 | std::vector< std::string > l2(L2);
409 | c2.c = l2;
410 |
411 | m.insert(std::make_pair(std::string("key1"), c1));
412 | m.insert(std::make_pair(std::string("key2"), c2));
413 |
414 | out << bits(m);
415 | }
416 |
417 | static void deserialize (...)
418 | {
419 | std::cout << "read from " << filename << std::endl;
420 | std::ifstream in(filename);
421 |
422 | std::map< std::string, class Custom > m;
423 |
424 | in >> bits(m);
425 | std::cout << std::endl;
426 |
427 | std::cout << "m = " << m.size() << " list-elems { " << std::endl;
428 | for (auto i : m) {
429 | std::cout << " [" << i.first << "] = " << i.second;
430 | }
431 | std::cout << "}" << std::endl;
432 | }
433 | ```
434 |
435 | Bitfield serialization (C and C++ style)
436 | ========================================
437 |
438 | ```C++
439 | class BitsetClass {
440 | public:
441 | std::bitset<1> a;
442 | std::bitset<2> b;
443 | std::bitset<3> c;
444 |
445 | unsigned int d:1; // need c++20 for default initializers for bitfields
446 | unsigned int e:2;
447 | unsigned int f:3;
448 | BitsetClass(void) { d = 0; e = 0; f = 0; }
449 |
450 | friend std::ostream& operator<<(std::ostream &out,
451 | Bits const my)
452 | {
453 | out << bits(my.t.a);
454 | out << bits(my.t.b);
455 | out << bits(my.t.c);
456 |
457 | std::bitset<6> s(my.t.d | my.t.e << 1 | my.t.f << 3);
458 | out << bits(s);
459 |
460 | return (out);
461 | }
462 |
463 | friend std::istream& operator>>(std::istream &in,
464 | Bits my)
465 | {
466 | std::bitset<1> a;
467 | in >> bits(a);
468 | my.t.a = a;
469 |
470 | in >> bits(my.t.b);
471 | in >> bits(my.t.c);
472 | std::bitset<6> s;
473 | in >> bits(s);
474 |
475 | unsigned long raw_bits = static_cast(s.to_ulong());
476 | my.t.d = raw_bits & 0b000001;
477 | my.t.e = (raw_bits & 0b000110) >> 1;
478 | my.t.f = (raw_bits & 0b111000) >> 3;
479 |
480 | return (in);
481 | }
482 | };
483 | ```
484 |
485 | Raw memory
486 | ==========
487 | ```C++
488 | #include "hexdump.h"
489 |
490 | auto elems = 128;
491 |
492 | static void serialize (std::ofstream out)
493 | {
494 | auto a = new char[elems];
495 | for (auto i = 0; i < elems; i++) {
496 | a[i] = i;
497 | }
498 | out << bits(a);
499 | }
500 |
501 | static void deserialize (std::ifstream in)
502 | {
503 | auto a = new char[elems];
504 | in >> bits(a);
505 |
506 | hexdump(a, elems);
507 | }
508 | ```
509 |
510 | Output:
511 |
512 | ```C++
513 | 128 bytes:
514 | 0000 00 01 02 03 04 05 06 07 08 09 0a 0b 0c 0d 0e 0f |................|
515 | 0010 10 11 12 13 14 15 16 17 18 19 1a 1b 1c 1d 1e 1f |................|
516 | 0020 20 21 22 23 24 25 26 27 28 29 2a 2b 2c 2d 2e 2f | !"#$%&'()*+,-./|
517 | 0030 30 31 32 33 34 35 36 37 38 39 3a 3b 3c 3d 3e 3f |0123456789:;<=>?|
518 | 0040 40 41 42 43 44 45 46 47 48 49 4a 4b 4c 4d 4e 4f |@ABCDEFGHIJKLMNO|
519 | 0050 50 51 52 53 54 55 56 57 58 59 5a 5b 5c 5d 5e 5f |PQRSTUVWXYZ[\]^_|
520 | 0060 60 61 62 63 64 65 66 67 68 69 6a 6b 6c 6d 6e 6f |`abcdefghijklmno|
521 | 0070 70 71 72 73 74 75 76 77 78 79 7a 7b 7c 7d 7e 7f |pqrstuvwxyz{|}~.|
522 | ```
523 |
524 | Compression
525 | ===========
526 |
527 | For compression, look at the following which uses [quicklz](http://www.quicklz.com/download.html)
528 |
529 |
530 | zipped_container_example.cpp
531 |
532 |
533 | Building
534 | ========
535 |
536 | Do
537 |
538 |
539 | sh ./RUNME
540 |
541 |
542 | Or, if that fails, manual build:
543 |
544 |
545 | c++ -std=c++11 -Werror -O2 -Wall -c -o .o/main.o main.cpp
546 | c++ .o/main.o -o c_plus_plus_serializer
547 |
548 |
549 | To test:
550 |
551 |
552 | ./c_plus_plus_serializer
553 |
554 |
555 | To debug, uncomment this line in Makefile.base, and then rerun RUNME:
556 |
557 |
558 | #EXTRA_CFLAGS += -DDEBUG_C_PLUS_PLUS_SERIALIZER
559 |
560 |
561 | To use 64-bit size_t when saving vectors, uncomment in Makefile.base and then
562 | rerun RUNME:
563 |
564 |
565 | #EXTRA_CFLAGS += -DUSE_SIZE_T
566 |
567 |
568 | Note, no sanity checking is performed on the data when it is read back in, so
569 | make sure your serializer and deserializers match perfectly.
570 |
--------------------------------------------------------------------------------
/RUNME:
--------------------------------------------------------------------------------
1 | #!/bin/bash
2 | #
3 | # Copyright (C) 2014 Neil McGill
4 | #
5 | # This software is free software; you can redistribute it and/or
6 | # modify it under the terms of the GNU Library General Public
7 | # License as published by the Free Software Foundation; either
8 | # version 2 of the License, or (at your option) any later version.
9 | #
10 | # This software is distributed in the hope that it will be fun,
11 | # but WITHOUT ANY WARRANTY; without even the implied warranty of
12 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 | # Library General Public License for more details.
14 | #
15 | # You should have received a copy of the GNU Library General Public
16 | # License along with this software; if not, write to the Free
17 | # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18 | #
19 |
20 | . ./build/common.sh
21 |
22 | help()
23 | {
24 | cat << %%
25 | Build options:
26 |
27 | Usage: $0 [options]
28 |
29 | [--gcc] Prefer g++ over clang++
30 | [--clang] Prefer clang++
31 | %%
32 | }
33 |
34 | OPT_GCC=
35 | OPT_CLANG=
36 |
37 | read_opts()
38 | {
39 | while [ "$#" -ne 0 ];
40 | do
41 | local option=$1
42 |
43 | case $option in
44 | -*gcc)
45 | OPT_GCC="yes"
46 | export OPT_GCC
47 | shift
48 | ;;
49 | -*clang)
50 | OPT_CLANG="yes"
51 | export OPT_CLANG
52 | shift
53 | ;;
54 | *)
55 | help
56 | exit 1
57 | ;;
58 | esac
59 | done
60 | }
61 |
62 | read_opts $*
63 |
64 | rm -f Makefile
65 | cat Makefile.base | sed '/DO NOT DELETE/,$d' > Makefile.tmp
66 | mv Makefile.tmp Makefile
67 | makedepend *.cpp -p .o/ 2>/dev/null
68 |
69 | echo "COMPILER_FLAGS=-Werror -g -ggdb3 -O3 -fstack-protector-all -I . -I examples # AUTOGEN" > .Makefile
70 | echo " " >> .Makefile
71 | echo "CLANG_COMPILER_WARNINGS=-Wall # AUTOGEN" >> .Makefile
72 | echo "GCC_COMPILER_WARNINGS=-Wall # AUTOGEN" >> .Makefile
73 | echo "GXX_COMPILER_WARNINGS=-Wall # AUTOGEN" >> .Makefile
74 |
75 | if [[ $OPT_GCC = "yes" ]]; then
76 | echo "COMPILER_WARNINGS=\$(CLANG_COMPILER_WARNINGS) # AUTOGEN" >> .Makefile
77 | echo "COMPILER_WARNINGS=\$(GXX_COMPILER_WARNINGS) # AUTOGEN" >> .Makefile
78 | echo "COMPILER_WARNINGS=\$(GCC_COMPILER_WARNINGS) # AUTOGEN" >> .Makefile
79 | echo "CXX=g++ # AUTOGEN" >> .Makefile
80 | elif [[ $OPT_CLANG = "yes" ]]; then
81 | echo "COMPILER_WARNINGS=\$(CLANG_COMPILER_WARNINGS) # AUTOGEN" >> .Makefile
82 | echo "COMPILER_WARNINGS=\$(GXX_COMPILER_WARNINGS) # AUTOGEN" >> .Makefile
83 | echo "COMPILER_WARNINGS=\$(GCC_COMPILER_WARNINGS) # AUTOGEN" >> .Makefile
84 | echo "CXX=clang++ # AUTOGEN" >> .Makefile
85 | else
86 | `clang++ --version >/dev/null 2>/dev/null`
87 | if [ $? -eq 0 ]
88 | then
89 | echo "COMPILER_WARNINGS=\$(GCC_COMPILER_WARNINGS) # AUTOGEN" >> .Makefile
90 | echo "COMPILER_WARNINGS=\$(GXX_COMPILER_WARNINGS) # AUTOGEN" >> .Makefile
91 | echo "COMPILER_WARNINGS=\$(CLANG_COMPILER_WARNINGS) # AUTOGEN" >> .Makefile
92 | echo "CXX=clang++ # AUTOGEN" >> .Makefile
93 | else
94 | `gcc --version >/dev/null 2>/dev/null`
95 | if [ $? -eq 0 ]
96 | then
97 | echo "COMPILER_WARNINGS=\$(CLANG_COMPILER_WARNINGS) # AUTOGEN" >> .Makefile
98 | echo "COMPILER_WARNINGS=\$(GXX_COMPILER_WARNINGS) # AUTOGEN" >> .Makefile
99 | echo "COMPILER_WARNINGS=\$(GCC_COMPILER_WARNINGS) # AUTOGEN" >> .Makefile
100 | echo "# CXX=clang++ # AUTOGEN" >> .Makefile
101 | echo "CXX=gcc # AUTOGEN" >> .Makefile
102 | echo "# CXX=cc # AUTOGEN" >> .Makefile
103 | echo "# CXX=g++ # AUTOGEN" >> .Makefile
104 | else
105 | `g++ --version >/dev/null 2>/dev/null`
106 | if [ $? -eq 0 ]
107 | then
108 | echo "COMPILER_WARNINGS=\$(CLANG_COMPILER_WARNINGS) # AUTOGEN" >> .Makefile
109 | echo "COMPILER_WARNINGS=\$(GCC_COMPILER_WARNINGS) # AUTOGEN" >> .Makefile
110 | echo "COMPILER_WARNINGS=\$(GXX_COMPILER_WARNINGS) # AUTOGEN" >> .Makefile
111 | echo "# CXX=clang++ # AUTOGEN" >> .Makefile
112 | echo "# CXX=gcc # AUTOGEN" >> .Makefile
113 | echo "# CXX=cc # AUTOGEN" >> .Makefile
114 | echo "CXX=g++ # AUTOGEN" >> .Makefile
115 | else
116 | echo "COMPILER_WARNINGS=\$(CLANG_COMPILER_WARNINGS) # AUTOGEN" >> .Makefile
117 | echo "COMPILER_WARNINGS=\$(GXX_COMPILER_WARNINGS) # AUTOGEN" >> .Makefile
118 | echo "COMPILER_WARNINGS=\$(GCC_COMPILER_WARNINGS) # AUTOGEN" >> .Makefile
119 | echo "# CXX=clang++ # AUTOGEN" >> .Makefile
120 | echo "# CXX=gcc # AUTOGEN" >> .Makefile
121 | echo "# CXX=cc # AUTOGEN" >> .Makefile
122 | echo "CXX=g++ # AUTOGEN" >> .Makefile
123 | fi
124 | fi
125 | fi
126 | fi
127 |
128 | echo " " >> .Makefile
129 | echo "EXE=$EXE # AUTOGEN" >> .Makefile
130 | echo "LDLIBS=$LDLIBS # AUTOGEN" >> .Makefile
131 | echo "CFLAGS=\$(COMPILER_FLAGS) \$(COMPILER_WARNINGS) # AUTOGEN" >> .Makefile
132 |
133 | cat Makefile | grep -v AUTOGEN | grep -v "^ $" >> .Makefile
134 |
135 | if [ -s .Makefile ]
136 | then
137 | mv .Makefile Makefile
138 | if [ ! -f Makefile ]
139 | then
140 | log_err "No makefile?!"
141 | exit 1
142 | fi
143 | else
144 | log_err "Makefile create fail?!"
145 | exit 1
146 | fi
147 |
148 | log_info "Cleaning"
149 | make clobber | sed 's/^/ /g'
150 |
151 | #
152 | # How many cores?
153 | #
154 | CORES=""
155 |
156 | MY_OS_NAME=$(uname)
157 | case "$MY_OS_NAME" in
158 | *Darwin*)
159 | CORES=$(/usr/sbin/system_profiler -detailLevel full SPHardwareDataType | grep Cores | sed 's/.*: //g' | awk '{print $1}')
160 | ;;
161 | *inux*)
162 | CORES=$(grep -E -c "cpu cores|processor" /proc/cpuinfo)
163 | ;;
164 | *MING*|*MSYS*)
165 | CORES=$(grep -E -c "cpu cores|processor" /proc/cpuinfo)
166 | ;;
167 | esac
168 |
169 | if [ "$CORES" != "" ]
170 | then
171 | log_info "Compiling ($CORES cpus)"
172 |
173 | CORES="-j $CORES"
174 | else
175 | log_info "Compiling"
176 | fi
177 |
178 | make $CORES all
179 |
180 | if [ $? -eq 0 ]
181 | then
182 | log_info "Run ./c_plus_plus_serializer to start"
183 |
184 | rm -f Makefile.bak
185 | else
186 | log_die "Build failed"
187 | fi
188 |
--------------------------------------------------------------------------------
/build/common.sh:
--------------------------------------------------------------------------------
1 | #
2 | # common shell utilities
3 | #
4 |
5 | ESC=""
6 |
7 | DULL=0
8 | BRIGHT=1
9 |
10 | FG_BLACK=30
11 | FG_RED=31
12 | FG_GREEN=32
13 | FG_YELLOW=33
14 | FG_BLUE=34
15 | FG_MAGENTA=35
16 | FG_CYAN=36
17 | FG_WHITE=37
18 |
19 | FG_NULL=00
20 |
21 | BG_BLACK=40
22 | BG_RED=41
23 | BG_GREEN=42
24 | BG_YELLOW=43
25 | BG_BLUE=44
26 | BG_MAGENTA=45
27 | BG_CYAN=46
28 | BG_WHITE=47
29 |
30 | BG_NULL=00
31 |
32 | ESC="["
33 | NORMAL="${ESC}m"
34 | RESET="${ESC}${DULL};${FG_WHITE};${BG_NULL}m"
35 |
36 | # DULL TEXT
37 | BLACK="${ESC}${DULL};${FG_BLACK}m"
38 | RED="${ESC}${DULL};${FG_RED}m"
39 | GREEN="${ESC}${DULL};${FG_GREEN}m"
40 | YELLOW="${ESC}${DULL};${FG_YELLOW}m"
41 | BLUE="${ESC}${DULL};${FG_BLUE}m"
42 | MAGENTA="${ESC}${DULL};${FG_MAGENTA}m"
43 | CYAN="${ESC}${DULL};${FG_CYAN}m"
44 | WHITE="${ESC}${DULL};${FG_WHITE}m"
45 |
46 | ON_BLACK="${ESC}${DULL};${BG_BLACK}m"
47 | ON_RED="${ESC}${DULL};${BG_RED}m"
48 | ON_GREEN="${ESC}${DULL};${BG_GREEN}m"
49 | ON_YELLOW="${ESC}${DULL};${BG_YELLOW}m"
50 | ON_BLUE="${ESC}${DULL};${BG_BLUE}m"
51 | ON_MAGENTA="${ESC}${DULL};${BG_MAGENTA}m"
52 | ON_CYAN="${ESC}${DULL};${BG_CYAN}m"
53 | ON_WHITE="${ESC}${DULL};${BG_WHITE}m"
54 |
55 | # BRIGHT TEXT
56 | BRIGHT_BLACK="${ESC}${BRIGHT};${FG_BLACK}m"
57 | BRIGHT_RED="${ESC}${BRIGHT};${FG_RED}m"
58 | BRIGHT_GREEN="${ESC}${BRIGHT};${FG_GREEN}m"
59 | BRIGHT_YELLOW="${ESC}${BRIGHT};${FG_YELLOW}m"
60 | BRIGHT_BLUE="${ESC}${BRIGHT};${FG_BLUE}m"
61 | BRIGHT_MAGENTA="${ESC}${BRIGHT};${FG_MAGENTA}m"
62 | BRIGHT_CYAN="${ESC}${BRIGHT};${FG_CYAN}m"
63 | BRIGHT_WHITE="${ESC}${BRIGHT};${FG_WHITE}m"
64 |
65 | setenv() {
66 | eval "$1='$2'"; export $1;
67 | }
68 |
69 | log() {
70 | echo "${MAGENTA}$*${RESET}"
71 | }
72 |
73 | log_info() {
74 | echo "${GREEN}$*${RESET}"
75 | }
76 |
77 | log_echo() {
78 | echo "$*"
79 | }
80 |
81 | log_err() {
82 | echo "${RED}ERROR: $*${RESET}"
83 | }
84 |
85 | log_warn() {
86 | echo "${CYAN}WARN: $*${RESET}"
87 | }
88 |
89 | log_die() {
90 | echo ": ${RED}FATAL ERROR: $*${RESET}"
91 | echo "Mail goblinhack@gmail.com for help"
92 | exit 1
93 | }
94 |
95 | run() {
96 | echo " $*"
97 | $*
98 | }
99 |
--------------------------------------------------------------------------------
/c_plus_plus_serializer.h:
--------------------------------------------------------------------------------
1 | #ifndef C_PLUS_PLUS_SERIALIZER
2 | #define C_PLUS_PLUS_SERIALIZER
3 | #include
4 | #include
5 | #include
6 | #include
7 |
8 | #undef DEBUG_C_PLUS_PLUS_SERIALIZER
9 |
10 | //
11 | // 64 bits for serializing is a bit overkill for serializing, so use int
12 | //
13 | #ifdef USE_SIZE_T
14 | typedef size_t my_size_t;
15 | #else
16 | typedef int my_size_t;
17 | #endif
18 |
19 | template < typename TYPE > struct Bits {
20 | TYPE t;
21 | };
22 |
23 | template < typename TYPE > static inline Bits< TYPE & > bits(TYPE &t) { return Bits< TYPE & > {t}; }
24 |
25 | template < typename TYPE > static inline Bits< const TYPE & > bits(const TYPE &t) { return Bits< const TYPE & > {t}; }
26 |
27 | ////////////////////////////////////////////////////////////////////////////
28 | // Read/write POD types
29 | ////////////////////////////////////////////////////////////////////////////
30 | template < typename TYPE > static inline std::istream &operator>>(std::istream &in, Bits< TYPE & > b)
31 | {
32 | #ifdef DEBUG_C_PLUS_PLUS_SERIALIZER
33 | std::cout << "read " << sizeof(TYPE) << " bytes" << std::endl;
34 | #endif
35 | return in.read(reinterpret_cast< char * >(&b.t), sizeof(TYPE));
36 | }
37 |
38 | template < typename TYPE > static inline std::ostream &operator<<(std::ostream &out, Bits< TYPE & > const b)
39 | {
40 | #ifdef DEBUG_C_PLUS_PLUS_SERIALIZER
41 | std::cout << "write " << sizeof(TYPE) << " bytes" << std::endl;
42 | #endif
43 | // reinterpret_cast is for pointer conversion
44 | // static_cast is for compatible pointer conversion
45 | return out.write(reinterpret_cast< const char * >(&(b.t)), sizeof(TYPE));
46 | }
47 |
48 | ////////////////////////////////////////////////////////////////////////////
49 | // Read/write std::string
50 | ////////////////////////////////////////////////////////////////////////////
51 | static inline std::istream &operator>>(std::istream &in, Bits< std::string & > v)
52 | {
53 | my_size_t sz = 0;
54 | in >> bits(sz);
55 | if (in && sz) {
56 | std::vector< char > tmp(sz);
57 | in.read(tmp.data(), sz);
58 | v.t.assign(tmp.data(), sz);
59 | #ifdef DEBUG_C_PLUS_PLUS_SERIALIZER
60 | std::cout << "read '" << v.t << "'" << std::endl;
61 | #endif
62 | }
63 |
64 | return in;
65 | }
66 |
67 | static inline std::ostream &operator<<(std::ostream &out, Bits< const std::string & > const v)
68 | {
69 | #ifdef DEBUG_C_PLUS_PLUS_SERIALIZER
70 | std::cout << "write const '" << v.t << "'" << std::endl;
71 | #endif
72 | my_size_t sz = v.t.size();
73 | return out << bits(sz) << v.t;
74 | }
75 |
76 | static inline std::ostream &operator<<(std::ostream &out, Bits< std::string & > const v)
77 | {
78 | #ifdef DEBUG_C_PLUS_PLUS_SERIALIZER
79 | std::cout << "write '" << v.t << "'" << std::endl;
80 | #endif
81 | my_size_t sz = v.t.size();
82 | return out << bits(sz) << v.t;
83 | }
84 |
85 | ////////////////////////////////////////////////////////////////////////////
86 | // Read/write std::wstring
87 | ////////////////////////////////////////////////////////////////////////////
88 | static inline std::istream &operator>>(std::istream &in, Bits< std::wstring & > v)
89 | {
90 | my_size_t sz = 0;
91 | in >> bits(sz);
92 | if (in && sz) {
93 | while (sz--) {
94 | wchar_t tmp;
95 | in >> bits(tmp);
96 | #ifdef DEBUG_C_PLUS_PLUS_SERIALIZER
97 | std::cout << "read '" << tmp << "'" << std::endl;
98 | #endif
99 | v.t += tmp;
100 | }
101 | }
102 |
103 | return in;
104 | }
105 |
106 | static inline std::ostream &operator<<(std::ostream &out, Bits< const std::wstring & > const v)
107 | {
108 | my_size_t sz = v.t.size();
109 | out << bits(sz);
110 | for (auto tmp : v.t) {
111 | out << bits(tmp);
112 | #ifdef DEBUG_C_PLUS_PLUS_SERIALIZER
113 | std::cout << "write const '" << tmp << "'" << std::endl;
114 | #endif
115 | }
116 | return out;
117 | }
118 |
119 | static inline std::ostream &operator<<(std::ostream &out, Bits< std::wstring & > const v)
120 | {
121 | my_size_t sz = v.t.size();
122 | out << bits(sz);
123 | for (auto tmp : v.t) {
124 | out << bits(tmp);
125 | #ifdef DEBUG_C_PLUS_PLUS_SERIALIZER
126 | std::cout << "write '" << tmp << "'" << std::endl;
127 | #endif
128 | }
129 | return out;
130 | }
131 |
132 | ////////////////////////////////////////////////////////////////////////////
133 | // Read/write wchar_t
134 | ////////////////////////////////////////////////////////////////////////////
135 | static inline std::istream &operator>>(std::istream &in, Bits< wchar_t & > v)
136 | {
137 | if (sizeof(wchar_t) == 4) {
138 | unsigned char _a, _b, _c, _d;
139 | in >> bits(_a);
140 | in >> bits(_b);
141 | in >> bits(_c);
142 | in >> bits(_d);
143 | v.t = (_a << 24) | (_b << 16) | (_c << 8) | _d;
144 | #ifdef DEBUG_C_PLUS_PLUS_SERIALIZER
145 | std::cout << "read '" << _a << "'" << std::endl;
146 | std::cout << "read '" << _b << "'" << std::endl;
147 | std::cout << "read '" << _c << "'" << std::endl;
148 | std::cout << "read '" << _d << "'" << std::endl;
149 | #endif
150 | } else if (sizeof(wchar_t) == 2) {
151 | unsigned char _a, _b;
152 | in >> bits(_a);
153 | in >> bits(_b);
154 | v.t = (_a << 8) | _b;
155 | #ifdef DEBUG_C_PLUS_PLUS_SERIALIZER
156 | std::cout << "read '" << _a << "'" << std::endl;
157 | std::cout << "read '" << _b << "'" << std::endl;
158 | #endif
159 | } else {
160 | static_assert(sizeof(wchar_t) <= 4, "wchar_t is greater that 32 bit");
161 | }
162 |
163 | return in;
164 | }
165 |
166 | static inline std::ostream &operator<<(std::ostream &out, Bits< const wchar_t & > const v)
167 | {
168 | #ifdef DEBUG_C_PLUS_PLUS_SERIALIZER
169 | std::cout << "write const '" << v.t << "'" << std::endl;
170 | #endif
171 | if (sizeof(wchar_t) == 4) {
172 | unsigned char _a, _b, _c, _d;
173 | _a = (v.t & (0xff000000)) >> 24;
174 | out << bits(_a);
175 | _b = (v.t & (0x00ff0000)) >> 16;
176 | out << bits(_b);
177 | _c = (v.t & (0x0000ff00)) >> 8;
178 | out << bits(_c);
179 | _d = (v.t & (0x000000ff)) >> 0;
180 | out << bits(_d);
181 | #ifdef DEBUG_C_PLUS_PLUS_SERIALIZER
182 | std::cout << "write '" << _a << "'" << std::endl;
183 | std::cout << "write '" << _b << "'" << std::endl;
184 | std::cout << "write '" << _c << "'" << std::endl;
185 | std::cout << "write '" << _d << "'" << std::endl;
186 | #endif
187 | } else if (sizeof(wchar_t) == 2) {
188 | unsigned char _a, _b;
189 | _a = (v.t & (0xff00)) >> 8;
190 | out << bits(_a);
191 | _b = (v.t & (0x00ff)) >> 0;
192 | out << bits(_b);
193 | #ifdef DEBUG_C_PLUS_PLUS_SERIALIZER
194 | std::cout << "write '" << _a << "'" << std::endl;
195 | std::cout << "write '" << _b << "'" << std::endl;
196 | #endif
197 | } else {
198 | static_assert(sizeof(wchar_t) <= 4, "wchar_t is greater that 32 bit");
199 | }
200 | return (out);
201 | }
202 |
203 | static inline std::ostream &operator<<(std::ostream &out, Bits< wchar_t & > const v)
204 | {
205 | #ifdef DEBUG_C_PLUS_PLUS_SERIALIZER
206 | std::cout << "write const '" << v.t << "'" << std::endl;
207 | #endif
208 | if (sizeof(wchar_t) == 4) {
209 | unsigned char _a, _b, _c, _d;
210 | _a = (v.t & (0xff000000)) >> 24;
211 | out << bits(_a);
212 | _b = (v.t & (0x00ff0000)) >> 16;
213 | out << bits(_b);
214 | _c = (v.t & (0x0000ff00)) >> 8;
215 | out << bits(_c);
216 | _d = (v.t & (0x000000ff)) >> 0;
217 | out << bits(_d);
218 | #ifdef DEBUG_C_PLUS_PLUS_SERIALIZER
219 | std::cout << "write '" << _a << "'" << std::endl;
220 | std::cout << "write '" << _b << "'" << std::endl;
221 | std::cout << "write '" << _c << "'" << std::endl;
222 | std::cout << "write '" << _d << "'" << std::endl;
223 | #endif
224 | } else if (sizeof(wchar_t) == 2) {
225 | unsigned char _a, _b;
226 | _a = (v.t & (0xff00)) >> 8;
227 | out << bits(_a);
228 | _b = (v.t & (0x00ff)) >> 0;
229 | out << bits(_b);
230 | #ifdef DEBUG_C_PLUS_PLUS_SERIALIZER
231 | std::cout << "write '" << _a << "'" << std::endl;
232 | std::cout << "write '" << _b << "'" << std::endl;
233 | #endif
234 | } else {
235 | static_assert(sizeof(wchar_t) <= 4, "wchar_t is greater that 32 bit");
236 | }
237 | return (out);
238 | }
239 |
240 | ////////////////////////////////////////////////////////////////////////////
241 | // Read/write simple container
242 | ////////////////////////////////////////////////////////////////////////////
243 | template < class T, template < typename ELEM, typename ALLOC = std::allocator< ELEM > > class C >
244 | static inline std::ostream &operator<<(std::ostream &out, Bits< C< T > & > const v)
245 | {
246 | #ifdef DEBUG_C_PLUS_PLUS_SERIALIZER
247 | std::cout << "write container " << v.t.size() << " elems" << std::endl;
248 | #endif
249 | my_size_t sz = v.t.size();
250 | out << bits(sz);
251 | for (auto i : v.t) {
252 | out << bits(i);
253 | }
254 | return (out);
255 | }
256 |
257 | template < class T, template < typename ELEM, typename ALLOC = std::allocator< ELEM > > class C >
258 | static inline std::ostream &operator<<(std::ostream &out, Bits< const C< T > & > const v)
259 | {
260 | #ifdef DEBUG_C_PLUS_PLUS_SERIALIZER
261 | std::cout << "write container " << v.t.size() << " elems" << std::endl;
262 | #endif
263 | my_size_t sz = v.t.size();
264 | out << bits(sz);
265 | for (auto i : v.t) {
266 | out << bits(i);
267 | }
268 | return (out);
269 | }
270 |
271 | template < class T, template < typename ELEM, typename ALLOC = std::allocator< ELEM > > class C >
272 | static inline std::istream &operator>>(std::istream &in, Bits< C< T > & > v)
273 | {
274 | my_size_t sz = 0;
275 | in >> bits(sz);
276 | #ifdef DEBUG_C_PLUS_PLUS_SERIALIZER
277 | std::cout << "read container " << sz << " elems" << std::endl;
278 | #endif
279 | if (in && sz) {
280 | while (sz--) {
281 | T s;
282 | in >> bits(s);
283 | v.t.push_back(s);
284 | }
285 | }
286 |
287 | return in;
288 | }
289 |
290 | ////////////////////////////////////////////////////////////////////////////
291 | // Read/write std::array
292 | ////////////////////////////////////////////////////////////////////////////
293 | template < class T, std::size_t N, template < typename ELEM, std::size_t > class C >
294 | static inline std::ostream &operator<<(std::ostream &out, Bits< C< T, N > & > const v)
295 | {
296 | #ifdef DEBUG_C_PLUS_PLUS_SERIALIZER
297 | std::cout << "write array container " << v.t.size() << " elems" << std::endl;
298 | #endif
299 | my_size_t sz = v.t.size();
300 | out << bits(sz);
301 | for (auto i : v.t) {
302 | out << bits(i);
303 | }
304 | return (out);
305 | }
306 |
307 | template < class T, std::size_t N, template < typename ELEM, std::size_t > class C >
308 | static inline std::ostream &operator<<(std::ostream &out, Bits< const C< T, N > & > const v)
309 | {
310 | #ifdef DEBUG_C_PLUS_PLUS_SERIALIZER
311 | std::cout << "write array container " << v.t.size() << " elems" << std::endl;
312 | #endif
313 | my_size_t sz = v.t.size();
314 | out << bits(sz);
315 | for (auto i : v.t) {
316 | out << bits(i);
317 | }
318 | return (out);
319 | }
320 |
321 | template < class T, std::size_t N, template < typename ELEM, std::size_t > class C >
322 | static inline std::istream &operator>>(std::istream &in, Bits< C< T, N > & > v)
323 | {
324 | my_size_t sz = 0;
325 | in >> bits(sz);
326 | #ifdef DEBUG_C_PLUS_PLUS_SERIALIZER
327 | std::cout << "read array container " << sz << " elems" << std::endl;
328 | #endif
329 | if (in && sz) {
330 | for (auto n = 0; n < sz; n++) {
331 | T s;
332 | in >> bits(s);
333 | v.t[ n ] = s;
334 | }
335 | }
336 |
337 | return in;
338 | }
339 |
340 | ////////////////////////////////////////////////////////////////////////////
341 | // Read/write map
342 | ////////////////////////////////////////////////////////////////////////////
343 |
344 | template < template < class K, class V, class Compare = std::less< K >,
345 | class Alloc = std::allocator< std::pair< const K, V > > >
346 | class M,
347 | class K, class V >
348 |
349 | static inline std::ostream &operator<<(std::ostream &out, Bits< M< K, V > & > const m)
350 | {
351 | #ifdef DEBUG_C_PLUS_PLUS_SERIALIZER
352 | std::cout << "write map " << m.t.size() << " elems" << std::endl;
353 | #endif
354 | my_size_t sz = m.t.size();
355 | out << bits(sz);
356 | for (auto i : m.t) {
357 | out << bits(i.first) << bits(i.second);
358 | }
359 | return (out);
360 | }
361 |
362 | template < template < class K, class V, class Compare = std::less< K >,
363 | class Alloc = std::allocator< std::pair< const K, V > > >
364 | class M,
365 | class K, class V >
366 |
367 | static inline std::ostream &operator<<(std::ostream &out, Bits< M< K, const V > & > const m)
368 | {
369 | #ifdef DEBUG_C_PLUS_PLUS_SERIALIZER
370 | std::cout << "write map " << m.t.size() << " elems" << std::endl;
371 | #endif
372 | my_size_t sz = m.t.size();
373 | out << bits(sz);
374 | for (auto i : m.t) {
375 | out << bits(i.first) << bits(i.second);
376 | }
377 | return (out);
378 | }
379 |
380 | template < template < class K, class V, class Compare = std::less< K >,
381 | class Alloc = std::allocator< std::pair< const K, V > > >
382 | class M,
383 | class K, class V >
384 |
385 | static inline std::istream &operator>>(std::istream &in, Bits< M< K, V > & > m)
386 | {
387 | my_size_t sz = 0;
388 | in >> bits(sz);
389 | #ifdef DEBUG_C_PLUS_PLUS_SERIALIZER
390 | std::cout << "read map " << sz << " elems" << std::endl;
391 | #endif
392 | if (in && sz) {
393 | while (sz--) {
394 | K k;
395 | V v;
396 | in >> bits(k) >> bits(v);
397 | m.t.insert(std::make_pair(k, v));
398 | }
399 | }
400 |
401 | return in;
402 | }
403 |
404 | ////////////////////////////////////////////////////////////////////////////
405 | // Read/write unordered_map
406 | ////////////////////////////////////////////////////////////////////////////
407 |
408 | template < template < class K, class T, class Hash = std::hash< K >, class Pred = std::equal_to< K >,
409 | class Alloc = std::allocator< std::pair< const K, T > > >
410 | class M,
411 | class K, class V >
412 |
413 | static inline std::ostream &operator<<(std::ostream &out, Bits< M< K, V > & > const m)
414 | {
415 | #ifdef DEBUG_C_PLUS_PLUS_SERIALIZER
416 | std::cout << "write unordered_map " << m.t.size() << " elems" << std::endl;
417 | #endif
418 | my_size_t sz = m.t.size();
419 | out << bits(sz);
420 | for (auto i : m.t) {
421 | out << bits(i.first) << bits(i.second);
422 | }
423 | return (out);
424 | }
425 |
426 | template < template < class K, class T, class Hash = std::hash< K >, class Pred = std::equal_to< K >,
427 | class Alloc = std::allocator< std::pair< const K, T > > >
428 | class M,
429 | class K, class V >
430 |
431 | static inline std::ostream &operator<<(std::ostream &out, Bits< M< K, const V > & > const m)
432 | {
433 | #ifdef DEBUG_C_PLUS_PLUS_SERIALIZER
434 | std::cout << "write unordered_map " << m.t.size() << " elems" << std::endl;
435 | #endif
436 | my_size_t sz = m.t.size();
437 | out << bits(sz);
438 | for (auto i : m.t) {
439 | out << bits(i.first) << bits(i.second);
440 | }
441 | return (out);
442 | }
443 |
444 | template < template < class K, class T, class Hash = std::hash< K >, class Pred = std::equal_to< K >,
445 | class Alloc = std::allocator< std::pair< const K, T > > >
446 | class M,
447 | class K, class V >
448 |
449 | static inline std::istream &operator>>(std::istream &in, Bits< M< K, V > & > m)
450 | {
451 | my_size_t sz = 0;
452 | in >> bits(sz);
453 | #ifdef DEBUG_C_PLUS_PLUS_SERIALIZER
454 | std::cout << "read unordered_map " << sz << " elems" << std::endl;
455 | #endif
456 | if (in && sz) {
457 | while (sz--) {
458 | K k;
459 | V v;
460 | in >> bits(k) >> bits(v);
461 | m.t.insert(std::make_pair(k, v));
462 | }
463 | }
464 |
465 | return in;
466 | }
467 |
468 | ////////////////////////////////////////////////////////////////////////////
469 | // Read/write set
470 | ////////////////////////////////////////////////////////////////////////////
471 |
472 | template <
473 | template<
474 | class K,
475 | class Compare = std::less,
476 | class Allocator = std::allocator
477 | > class M, class K >
478 |
479 | static inline std::ostream &operator<<(std::ostream &out, Bits< M< K > & > const m)
480 | {
481 | #ifdef DEBUG_C_PLUS_PLUS_SERIALIZER
482 | std::cout << "write set " << m.t.size() << " elems" << std::endl;
483 | #endif
484 | my_size_t sz = m.t.size();
485 | out << bits(sz);
486 | for (auto i : m.t) {
487 | out << bits(i);
488 | }
489 | return (out);
490 | }
491 |
492 | template <
493 | template<
494 | class K,
495 | class Compare = std::less,
496 | class Allocator = std::allocator
497 | > class M, class K >
498 |
499 | static inline std::ostream &operator<<(std::ostream &out, Bits< M< K > & > const m)
500 | {
501 | #ifdef DEBUG_C_PLUS_PLUS_SERIALIZER
502 | std::cout << "write set " << m.t.size() << " elems" << std::endl;
503 | #endif
504 | my_size_t sz = m.t.size();
505 | out << bits(sz);
506 | for (auto i : m.t) {
507 | out << bits(i);
508 | }
509 | return (out);
510 | }
511 |
512 | template <
513 | template<
514 | class K,
515 | class Compare = std::less,
516 | class Allocator = std::allocator
517 | > class M, class K >
518 |
519 | static inline std::istream &operator>>(std::istream &in, Bits< M< K > & > m)
520 | {
521 | my_size_t sz = 0;
522 | in >> bits(sz);
523 | #ifdef DEBUG_C_PLUS_PLUS_SERIALIZER
524 | std::cout << "read set " << sz << " elems" << std::endl;
525 | #endif
526 | if (in && sz) {
527 | while (sz--) {
528 | K k;
529 | in >> bits(k);
530 | m.t.insert(k);
531 | }
532 | }
533 |
534 | return in;
535 | }
536 |
537 | ////////////////////////////////////////////////////////////////////////////
538 | // Read/write pair
539 | ////////////////////////////////////////////////////////////////////////////
540 |
541 | template < typename K, typename V >
542 | static inline std::ostream &operator<<(std::ostream &out, Bits< std::pair< K, V > & > const wrapped)
543 | {
544 | #ifdef DEBUG_C_PLUS_PLUS_SERIALIZER
545 | std::cout << "read pair" << std::endl;
546 | #endif
547 | out << bits(wrapped.t.first);
548 | out << bits(wrapped.t.second);
549 | return (out);
550 | }
551 |
552 | template < typename K, typename V >
553 | static inline std::istream &operator>>(std::istream &in, Bits< std::pair< K, V > & > wrapped)
554 | {
555 | #ifdef DEBUG_C_PLUS_PLUS_SERIALIZER
556 | std::cout << "write pair" << std::endl;
557 | #endif
558 | in >> bits(wrapped.t.first);
559 | in >> bits(wrapped.t.second);
560 | return in;
561 | }
562 |
563 | template < typename K, typename V >
564 | static inline std::istream &operator>>(std::istream &in, Bits< const std::pair< K, V > & > wrapped)
565 | {
566 | #ifdef DEBUG_C_PLUS_PLUS_SERIALIZER
567 | std::cout << "const write pair" << std::endl;
568 | #endif
569 | in >> bits(wrapped.t.first);
570 | in >> bits(wrapped.t.second);
571 | return in;
572 | }
573 | #endif /* C_PLUS_PLUS_SERIALIZER */
574 |
--------------------------------------------------------------------------------
/examples/.clang-format:
--------------------------------------------------------------------------------
1 | ---
2 | Language: Cpp
3 | # BasedOnStyle: LLVM
4 | AccessModifierOffset: -2
5 | AlignAfterOpenBracket: Align
6 | AlignConsecutiveMacros: true
7 | AlignConsecutiveAssignments: true
8 | AlignConsecutiveBitFields: true
9 | AlignConsecutiveDeclarations: true
10 | AlignEscapedNewlines: Right
11 | AlignOperands: Align
12 | AlignTrailingComments: true
13 | AllowAllArgumentsOnNextLine: true
14 | AllowAllConstructorInitializersOnNextLine: true
15 | AllowAllParametersOfDeclarationOnNextLine: true
16 | AllowShortEnumsOnASingleLine: true
17 | AllowShortBlocksOnASingleLine: Never
18 | AllowShortCaseLabelsOnASingleLine: true
19 | AllowShortFunctionsOnASingleLine: All
20 | AllowShortLambdasOnASingleLine: All
21 | AllowShortIfStatementsOnASingleLine: Never
22 | AllowShortLoopsOnASingleLine: false
23 | AlwaysBreakAfterDefinitionReturnType: None
24 | AlwaysBreakAfterReturnType: None
25 | AlwaysBreakBeforeMultilineStrings: true
26 | AlwaysBreakTemplateDeclarations: MultiLine
27 | AttributeMacros:
28 | - __capability
29 | BinPackArguments: true
30 | BinPackParameters: true
31 | BraceWrapping:
32 | AfterCaseLabel: true
33 | AfterClass: true
34 | AfterControlStatement: Never
35 | AfterEnum: true
36 | AfterFunction: true
37 | AfterNamespace: true
38 | AfterObjCDeclaration: true
39 | AfterStruct: true
40 | AfterUnion: true
41 | AfterExternBlock: true
42 | BeforeCatch: true
43 | BeforeElse: true
44 | BeforeLambdaBody: true
45 | BeforeWhile: true
46 | IndentBraces: true
47 | SplitEmptyFunction: true
48 | SplitEmptyRecord: true
49 | SplitEmptyNamespace: true
50 | BreakBeforeBinaryOperators: None
51 | BreakBeforeConceptDeclarations: true
52 | BreakBeforeBraces: Linux
53 | BreakBeforeInheritanceComma: false
54 | BreakInheritanceList: BeforeColon
55 | BreakBeforeTernaryOperators: true
56 | BreakConstructorInitializersBeforeComma: false
57 | BreakConstructorInitializers: BeforeColon
58 | BreakAfterJavaFieldAnnotations: false
59 | BreakStringLiterals: true
60 | ColumnLimit: 118
61 | CommentPragmas: '^ IWYU pragma:'
62 | CompactNamespaces: false
63 | ConstructorInitializerAllOnOneLineOrOnePerLine: false
64 | ConstructorInitializerIndentWidth: 4
65 | ContinuationIndentWidth: 4
66 | Cpp11BracedListStyle: true
67 | DeriveLineEnding: true
68 | DerivePointerAlignment: false
69 | DisableFormat: false
70 | EmptyLineBeforeAccessModifier: LogicalBlock
71 | ExperimentalAutoDetectBinPacking: false
72 | FixNamespaceComments: true
73 | ForEachMacros:
74 | - foreach
75 | - Q_FOREACH
76 | - BOOST_FOREACH
77 | StatementAttributeLikeMacros:
78 | - Q_EMIT
79 | IncludeBlocks: Preserve
80 | IncludeCategories:
81 | - Regex: '^"(llvm|llvm-c|clang|clang-c)/'
82 | Priority: 2
83 | SortPriority: 0
84 | CaseSensitive: false
85 | - Regex: '^(<|"(gtest|gmock|isl|json)/)'
86 | Priority: 3
87 | SortPriority: 0
88 | CaseSensitive: false
89 | - Regex: '.*'
90 | Priority: 1
91 | SortPriority: 0
92 | CaseSensitive: false
93 | IncludeIsMainRegex: '(Test)?$'
94 | IncludeIsMainSourceRegex: ''
95 | IndentCaseLabels: true
96 | IndentCaseBlocks: true
97 | IndentGotoLabels: true
98 | IndentPPDirectives: None
99 | IndentExternBlock: AfterExternBlock
100 | IndentRequires: false
101 | IndentWidth: 2
102 | IndentWrappedFunctionNames: true
103 | InsertTrailingCommas: None
104 | JavaScriptQuotes: Leave
105 | JavaScriptWrapImports: true
106 | KeepEmptyLinesAtTheStartOfBlocks: true
107 | MacroBlockBegin: ''
108 | MacroBlockEnd: ''
109 | MaxEmptyLinesToKeep: 1
110 | NamespaceIndentation: None
111 | ObjCBinPackProtocolList: Auto
112 | ObjCBlockIndentWidth: 2
113 | ObjCBreakBeforeNestedBlockParam: true
114 | ObjCSpaceAfterProperty: false
115 | ObjCSpaceBeforeProtocolList: true
116 | PenaltyBreakAssignment: 2
117 | PenaltyBreakBeforeFirstCallParameter: 19
118 | PenaltyBreakComment: 300
119 | PenaltyBreakFirstLessLess: 120
120 | PenaltyBreakString: 1000
121 | PenaltyBreakTemplateDeclaration: 10
122 | PenaltyExcessCharacter: 1000000
123 | PenaltyReturnTypeOnItsOwnLine: 60
124 | PenaltyIndentedWhitespace: 0
125 | PointerAlignment: Right
126 | ReflowComments: true
127 | SortIncludes: true
128 | SortJavaStaticImport: Before
129 | SortUsingDeclarations: true
130 | SpaceAfterCStyleCast: true
131 | SpaceAfterLogicalNot: true
132 | SpaceAfterTemplateKeyword: true
133 | SpaceBeforeAssignmentOperators: true
134 | SpaceBeforeCaseColon: true
135 | SpaceBeforeCpp11BracedList: true
136 | SpaceBeforeCtorInitializerColon: true
137 | SpaceBeforeInheritanceColon: true
138 | SpaceBeforeParens: ControlStatements
139 | SpaceAroundPointerQualifiers: Default
140 | SpaceBeforeRangeBasedForLoopColon: true
141 | SpaceInEmptyBlock: false
142 | SpaceInEmptyParentheses: false
143 | SpacesBeforeTrailingComments: 1
144 | SpacesInAngles: true
145 | SpacesInConditionalStatement: false
146 | SpacesInContainerLiterals: true
147 | SpacesInCStyleCastParentheses: false
148 | SpacesInParentheses: false
149 | SpacesInSquareBrackets: true
150 | SpaceBeforeSquareBrackets: false
151 | BitFieldColonSpacing: Both
152 | Standard: Latest
153 | StatementMacros:
154 | - Q_UNUSED
155 | - QT_REQUIRE_VERSION
156 | TabWidth: 2
157 | UseCRLF: false
158 | UseTab: Never
159 | WhitespaceSensitiveMacros:
160 | - STRINGIZE
161 | - PP_STRINGIZE
162 | - BOOST_PP_STRINGIZE
163 | - NS_SWIFT_NAME
164 | - CF_SWIFT_NAME
165 | ...
166 |
167 |
--------------------------------------------------------------------------------
/examples/basic_example.cpp:
--------------------------------------------------------------------------------
1 | #include "c_plus_plus_serializer.h"
2 | #include
3 |
4 | static void save_simple(const std::string filename)
5 | {
6 | std::cout << "save to " << filename << std::endl;
7 | std::ofstream out(filename, std::ios::binary);
8 |
9 | char a = 42;
10 | unsigned short b = 65535;
11 | int c = 123456;
12 | float d = std::numeric_limits< float >::max();
13 | double e = std::numeric_limits< double >::max();
14 | std::string f("hello");
15 | wchar_t g = L'💩';
16 | std::wstring h(L"wide string 💩");
17 | std::pair< int, std::string > p(42, "life");
18 |
19 | std::cout << std::endl;
20 | std::cout << "write:" << std::endl;
21 | std::cout << " a: char " << a << std::endl;
22 | std::cout << " b: unsigned short " << b << std::endl;
23 | std::cout << " c: int " << c << std::endl;
24 | std::cout << " d: float " << d << std::endl;
25 | std::cout << " e: double " << e << std::endl;
26 | std::cout << " f: std::string " << f << std::endl;
27 | std::wcout << " g: wchar_t " << g << std::endl;
28 | std::wcout << " h: std::wstring " << h << std::endl;
29 | std::cout << " p: std::pair " << p.first << " " << p.second << std::endl;
30 |
31 | std::cout << std::endl;
32 |
33 | out << bits(a) << bits(b) << bits(c) << bits(d);
34 | out << bits(e) << bits(f) << bits(g) << bits(h);
35 | out << bits(p);
36 | }
37 |
38 | static void load_simple(const std::string filename)
39 | {
40 | std::cout << "read from " << filename << std::endl;
41 | std::ifstream in(filename);
42 |
43 | char a;
44 | unsigned short b;
45 | int c;
46 | float d;
47 | double e;
48 | std::string f;
49 | wchar_t g;
50 | std::wstring h;
51 | std::pair< int, std::string > p;
52 |
53 | in >> bits(a) >> bits(b) >> bits(c) >> bits(d);
54 | in >> bits(e) >> bits(f) >> bits(g) >> bits(h);
55 | in >> bits(p);
56 |
57 | std::cout << std::endl;
58 | std::cout << "read:" << std::endl;
59 | std::cout << " a: char " << a << std::endl;
60 | std::cout << " b: unsigned short " << b << std::endl;
61 | std::cout << " c: int " << c << std::endl;
62 | std::cout << " d: float " << d << std::endl;
63 | std::cout << " e: double " << e << std::endl;
64 | std::cout << " f: std::string " << f << std::endl;
65 | std::wcout << " g: wchar_t " << g << std::endl;
66 | std::wcout << " h: std::wstring " << h << std::endl;
67 | std::cout << " p: std::pair " << p.first << " " << p.second << std::endl;
68 | std::cout << std::endl;
69 | }
70 |
71 | void basic_example(void)
72 | {
73 | //
74 | // Need this to get the poop emoji printed! :)
75 | //
76 | std::locale loc("");
77 | std::ios_base::sync_with_stdio(false);
78 | std::wcout.imbue(loc);
79 |
80 | std::cout << "basic_example" << std::endl;
81 | std::cout << "=============" << std::endl;
82 | save_simple(std::string("basic_example.bin"));
83 | load_simple(std::string("basic_example.bin"));
84 | }
85 |
--------------------------------------------------------------------------------
/examples/bitfields_in_class_example.cpp:
--------------------------------------------------------------------------------
1 | #include "c_plus_plus_serializer.h"
2 | #include
3 |
4 | class BitsetClass
5 | {
6 | public:
7 | std::bitset< 1 > a;
8 | std::bitset< 2 > b;
9 | std::bitset< 3 > c;
10 |
11 | unsigned int d : 1;
12 | unsigned int e : 2;
13 | unsigned int f : 3;
14 |
15 | BitsetClass(void)
16 | {
17 | d = 0;
18 | e = 0;
19 | f = 0;
20 | }
21 |
22 | friend std::ostream &operator<<(std::ostream &out, Bits< const class BitsetClass & > const my)
23 | {
24 | #ifdef DEBUG_C_PLUS_PLUS_SERIALIZER
25 | std::cout << "write custom bitset class" << std::endl;
26 | #endif
27 | out << bits(my.t.a);
28 | out << bits(my.t.b);
29 | out << bits(my.t.c);
30 |
31 | std::bitset< 6 > s(my.t.d | my.t.e << 1 | my.t.f << 3);
32 | out << bits(s);
33 |
34 | return (out);
35 | }
36 |
37 | friend std::istream &operator>>(std::istream &in, Bits< class BitsetClass & > my)
38 | {
39 | #ifdef DEBUG_C_PLUS_PLUS_SERIALIZER
40 | std::cout << "read custom bitset class" << std::endl;
41 | #endif
42 | std::bitset< 1 > a;
43 | in >> bits(a);
44 | my.t.a = a;
45 |
46 | in >> bits(my.t.b);
47 | in >> bits(my.t.c);
48 | std::bitset< 6 > s;
49 | in >> bits(s);
50 |
51 | unsigned long raw_bits = static_cast< unsigned long >(s.to_ulong());
52 | my.t.d = raw_bits & 0b000001;
53 | my.t.e = (raw_bits & 0b000110) >> 1;
54 | my.t.f = (raw_bits & 0b111000) >> 3;
55 |
56 | return (in);
57 | }
58 |
59 | friend std::ostream &operator<<(std::ostream &out, const class BitsetClass &my)
60 | {
61 | out << "a(1bit):" << my.a << std::endl;
62 | out << "b(2bit):" << my.b << std::endl;
63 | out << "c(3bit):" << my.c << std::endl;
64 | out << "d(1bit):" << std::bitset< 1 >(my.d) << std::endl;
65 | out << "e(2bit):" << std::bitset< 2 >(my.e) << std::endl;
66 | out << "f(3bit):" << std::bitset< 3 >(my.f) << std::endl;
67 |
68 | return (out);
69 | }
70 | };
71 |
72 | static void save(const std::string filename, const class BitsetClass &c)
73 | {
74 | std::cout << "save to " << filename << std::endl;
75 | std::ofstream out(filename, std::ios::binary);
76 |
77 | out << bits(c);
78 | }
79 |
80 | static void load(const std::string filename, class BitsetClass &c)
81 | {
82 | std::cout << "read from " << filename << std::endl;
83 | std::ifstream in(filename);
84 |
85 | in >> bits(c);
86 | }
87 |
88 | static void save_custom_bitset_class_example(void)
89 | {
90 | auto c = BitsetClass();
91 |
92 | c.a = 1;
93 | c.b = 3;
94 | c.c = 7;
95 | c.d = 1;
96 | c.e = 3;
97 | c.f = 7;
98 |
99 | save(std::string("custom_bitset_class.bin"), c);
100 | }
101 |
102 | static void load_custom_bitset_class_example(void)
103 | {
104 | auto c = BitsetClass();
105 |
106 | load(std::string("custom_bitset_class.bin"), c);
107 | std::cout << std::endl;
108 | std::cout << c;
109 | std::cout << std::endl;
110 | }
111 |
112 | void custom_bitset_class_example(void)
113 | {
114 | std::cout << "custom_bitset_class_example" << std::endl;
115 | std::cout << "===========================" << std::endl;
116 | save_custom_bitset_class_example();
117 | load_custom_bitset_class_example();
118 | }
119 |
--------------------------------------------------------------------------------
/examples/container_example.cpp:
--------------------------------------------------------------------------------
1 | #include "c_plus_plus_serializer.h"
2 | #include
3 | #include
4 | #include
5 | #include