1 /* Supporting different types and containers.
2  * Copyright (C) 2017  Marko Semet
3  *
4  * This program is free software: you can redistribute it and/or modify
5  * it under the terms of the GNU General Public License as published by
6  * the Free Software Foundation, either version 3 of the License, or
7  * (at your option) any later version.
8  *
9  * This program is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12  * GNU General Public License for more details.
13  *
14  * You should have received a copy of the GNU General Public License
15  * along with this program.  If not, see <https://www.gnu.org/licenses/>.
16  */
17 module structuresd.serialize;
18 
19 
20 private
21 {
22 	import std.traits;
23 	import structuresd.utils;
24 }
25 
26 
27 /**
28  * Mark attribute as serializable
29  */
30 public enum SERIALIZE;
31 
32 
33 /**
34  * Check if type is serialize.
35  * @tparam TYPE Type to check.
36  */
37 public template isSerialize(TYPE)
38 {
39 	static if(is(TYPE == struct))
40 	{
41 		enum bool isSerialize = listSerializeMembers!TYPE.length > 0;
42 	}
43 	else static if(__traits(isArithmetic, TYPE))
44 	{
45 		enum bool isSerialize = true;
46 	}
47 	else
48 	{
49 		enum bool isSerialize = false;
50 	}
51 }
52 
53 /**
54  * List members
55  */
56 public alias listSerializeMembers(TYPE) = membersWith!(_listSerializeMembers, TYPE);
57 private alias _listSerializeMembers(alias T) = hasAttribute!(SERIALIZE, T);