1 /**
2     Boxed Types
3 
4     Copyright:
5         Copyright © 2023-2025, Kitsunebi Games
6         Copyright © 2023-2025, Inochi2D Project
7     
8     License:   $(LINK2 http://www.boost.org/LICENSE_1_0.txt, Boost License 1.0)
9     Authors:   Luna Nielsen
10 */
11 module nulib.io.boxed;
12 import numem;
13 import nulib.io.serialize;
14 
15 /**
16     A boxed D base type.
17 */
18 class Boxed(T) : NuObject, ISerializable, IDeserializable {
19 private:
20     T value;
21 
22 public:
23 
24     // Destructor
25     ~this() { nogc_delete(value); }
26 
27     /**
28         Constructor
29     */
30     this(T value) { this.value = value; }
31 
32     /**
33         The name of the boxed type.
34     */
35     final
36     @property string typeName() { return T.stringof; }
37 
38     /**
39         Unboxes the value in the type.
40     */
41     final
42     T unbox() { return value; }
43 
44     /**
45         Called on the object to serialize it using the 
46         given (de)serializer.
47 
48         Params:
49             serde = the (de)serializer to use.
50     */
51     void serialize(ref Serde serde) {
52         return serde.serialize!T(value);
53     }
54 
55     /**
56         Called on the object to deserialize it using the 
57         given (de)serializer.
58 
59         Params:
60             serde = the (de)serializer to use.
61     */
62     void deserialize(ref Serde serde) {
63         return serde.deserialize!T(value);
64     }
65 }