1 /*
2  * hunt-amqp: AMQP library for D programming language, based on hunt-net.
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 module hunt.amqp.ProtonQoS;
12 
13 import hunt.Enum;
14 import hunt.Exceptions;
15 import hunt.util.Common;
16 import hunt.util.Comparator;
17 
18 struct ProtonQoS {
19     enum ProtonQoS AT_MOST_ONCE = ProtonQoS("AT_MOST_ONCE", 0);
20     enum ProtonQoS AT_LEAST_ONCE = ProtonQoS("AT_LEAST_ONCE", 1);
21 
22     /**
23      * Sole constructor.  Programmers cannot invoke this constructor.
24      * It is for use by code emitted by the compiler in response to
25      * enum type declarations.
26      *
27      * @param name - The name of this enum constant, which is the identifier
28      *               used to declare it.
29      * @param ordinal - The ordinal of this enumeration constant (its position
30      *         in the enum declaration, where the initial constant is assigned
31      *         an ordinal of zero).
32      */
33     this(string name, int ordinal) {
34         this._name = name;
35         this._ordinal = ordinal;
36     }
37 
38     /**
39      * The name of this enum constant, as declared in the enum declaration.
40      * Most programmers should use the {@link #toString} method rather than
41      * accessing this field.
42      */
43     protected string _name;
44 
45     /**
46      * Returns the name of this enum constant, exactly as declared in its
47      * enum declaration.
48      *
49      * <b>Most programmers should use the {@link #toString} method in
50      * preference to this one, as the toString method may return
51      * a more user-friendly name.</b>  This method is designed primarily for
52      * use in specialized situations where correctness depends on getting the
53      * exact name, which will not vary from release to release.
54      *
55      * @return the name of this enum constant
56      */
57     final string name() {
58         return _name;
59     }
60 
61     /**
62      * The ordinal of this enumeration constant (its position
63      * in the enum declaration, where the initial constant is assigned
64      * an ordinal of zero).
65      *
66      * Most programmers will have no use for this field.  It is designed
67      * for use by sophisticated enum-based data structures, such as
68      * {@link java.util.EnumSet} and {@link java.util.EnumMap}.
69      */
70     protected int _ordinal;
71 
72     /**
73      * Returns the ordinal of this enumeration constant (its position
74      * in its enum declaration, where the initial constant is assigned
75      * an ordinal of zero).
76      *
77      * Most programmers will have no use for this method.  It is
78      * designed for use by sophisticated enum-based data structures, such
79      * as {@link java.util.EnumSet} and {@link java.util.EnumMap}.
80      *
81      * @return the ordinal of this enumeration constant
82      */
83     int ordinal() {
84         return _ordinal;
85     }
86 
87     /**
88      * Returns the name of this enum constant, as contained in the
89      * declaration.  This method may be overridden, though it typically
90      * isn't necessary or desirable.  An enum type should override this
91      * method when a more "programmer-friendly" string form exists.
92      *
93      * @return the name of this enum constant
94      */
95     string toString() {
96         return _name;
97     }
98 
99     int opCmp(ref const ProtonQoS o) const {
100         return compare(_ordinal, o._ordinal);
101     }
102 
103 }