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.ReceiverSettleMode;
14 
15 import hunt.proton.amqp.UnsignedByte;
16 import hunt.logging;
17 import std.concurrency : initOnce;
18 
19 class ReceiverSettleMode
20 {
21     //static ReceiverSettleMode FIRST;
22     //static ReceiverSettleMode SECOND;
23 
24     static ReceiverSettleMode  FIRST() {
25         __gshared ReceiverSettleMode  inst;
26         return initOnce!inst(new ReceiverSettleMode(0));
27     }
28     static ReceiverSettleMode  SECOND() {
29         __gshared ReceiverSettleMode  inst;
30         return initOnce!inst(new ReceiverSettleMode(1));
31     }
32 
33     private UnsignedByte value;
34     private int likeEnum ;
35 
36 
37     this(int likeEnum)
38     {
39         this.likeEnum = likeEnum;
40         this.value = UnsignedByte.valueOf(cast(byte)likeEnum);
41     }
42 
43 
44     //static this()
45     //{
46     //    FIRST = new ReceiverSettleMode(0);
47     //    SECOND = new ReceiverSettleMode(1);
48     //}
49 
50     int getEnum()
51     {
52         return likeEnum;
53     }
54 
55     public static ReceiverSettleMode valueOf(UnsignedByte value) {
56 
57         switch (value.intValue()) {
58             case 0:
59                 return ReceiverSettleMode.FIRST;
60             case 1:
61                 return ReceiverSettleMode.SECOND;
62             default:
63             {
64                 logError("The value can be only 0 (for FIRST) and 1 (for SECOND)");
65                 return null;
66             }
67 
68         }
69     }
70 
71     override bool opEquals(Object o)
72     {
73         ReceiverSettleMode other = cast(ReceiverSettleMode)o;
74         if (other !is null)
75         {
76             return getEnum() == other.getEnum();
77         }
78         return false;
79     }
80 
81     public UnsignedByte getValue() {
82         return this.value;
83     }
84 }