1 /*
2  * hunt-proton: AMQP Protocol library for D programming language.
3  *
4  * Copyright (C) 2018-2019 HuntLabs
5  *
6  * Website: https://www.huntlabs.net/
7  *
8  * Licensed under the Apache-2.0 License.
9  *
10  */
11 
12 
13 module hunt.proton.amqp.transport.SenderSettleMode;
14 
15 import hunt.proton.amqp.UnsignedByte;
16 import hunt.logging;
17 
18 import std.concurrency : initOnce;
19 class SenderSettleMode
20 {
21     //static SenderSettleMode UNSETTLED;
22     //static SenderSettleMode SETTLED;
23     //static SenderSettleMode MIXED;
24 
25     private UnsignedByte value;
26     private int likeEnum ;
27 
28 
29     this(int likeEnum)
30     {
31         this.likeEnum = likeEnum;
32         this.value = UnsignedByte.valueOf(cast(byte)likeEnum);
33     }
34 
35     static SenderSettleMode  UNSETTLED() {
36         __gshared SenderSettleMode  inst;
37         return initOnce!inst(new SenderSettleMode(0));
38     }
39 
40     static SenderSettleMode  SETTLED() {
41         __gshared SenderSettleMode  inst;
42         return initOnce!inst(new SenderSettleMode(1));
43     }
44 
45     static SenderSettleMode  MIXED() {
46         __gshared SenderSettleMode  inst;
47         return initOnce!inst(new SenderSettleMode(2));
48     }
49 
50     //static this ()
51     //{
52     //    UNSETTLED = new SenderSettleMode(0);
53     //    SETTLED = new SenderSettleMode(1);
54     //    MIXED = new SenderSettleMode(2);
55     //}
56     override
57     bool opEquals (Object o)
58     {
59         SenderSettleMode other = cast(SenderSettleMode)o;
60         if (other !is null)
61         {
62             return this.getValue == other.getValue;
63         }
64         return false;
65     }
66 
67     int getEnum()
68     {
69         return likeEnum;
70     }
71 
72     public static SenderSettleMode valueOf(UnsignedByte value) {
73 
74         switch (value.intValue()) {
75 
76             case 0:
77                 return SenderSettleMode.UNSETTLED;
78             case 1:
79                 return SenderSettleMode.SETTLED;
80             case 2:
81                 return SenderSettleMode.MIXED;
82             default:
83             {
84                 logError("The value can be only 0 (for UNSETTLED), 1 (for SETTLED) and 2 (for MIXED)");
85                 return null;
86             }
87 
88         }
89     }
90 
91     public UnsignedByte getValue() {
92         return this.value;
93     }
94 }