1 // $Id: ui_id.cpp,v 1.11 2011/03/07 06:08:53 bobgian Exp $
2 
3 /*
4  *  Copyright 2002  Peter Beerli, Mary Kuhner, Jon Yamato and Joseph Felsenstein
5  *
6  *  This software is distributed free of charge for non-commercial use
7  *  and is copyrighted.  Of course, we do not guarantee that the software
8  *  works, and are not responsible for any damage you may cause or have.
9  *
10  */
11 
12 #include <cassert>
13 
14 #include "ui_id.h"
15 #include "ui_constants.h"
16 
17 //------------------------------------------------------------------------------------
18 
19 // an ID expressing a doubly indexed quantity
UIId(long index1,long index2,long index3)20 UIId::UIId(long index1, long index2, long index3)
21     :
22     m_hasForce(false),
23     m_forceType(force_COAL),        // any force_type will do here as
24     // long as it's the same value for
25     // every UIId with m_hasForce == false
26     // We picked force_COAL 'cause it's first
27     m_index1(index1),
28     m_index2(index2),
29     m_index3(index3)
30 {
31     assert(IndexesAreOkay());
32 }
33 
34 // an ID expressing a force and a doubly indexed quantity
UIId(force_type force,long index1,long index2,long index3)35 UIId::UIId(force_type force, long index1, long index2, long index3)
36     :
37     m_hasForce(true),
38     m_forceType(force),
39     m_index1(index1),
40     m_index2(index2),
41     m_index3(index3)
42 {
43     assert(IndexesAreOkay());
44 }
45 
IndexesAreOkay() const46 bool UIId::IndexesAreOkay() const
47 {
48     if (!(m_index1 >= 0 ||
49           m_index1 == uiconst::NO_ID ||
50           m_index1 == uiconst::GLOBAL_ID ||
51           m_index1 == uiconst::GLOBAL_DATAMODEL_NUC_ID ||
52           m_index1 == uiconst::GLOBAL_DATAMODEL_MSAT_ID ||
53           m_index1 == uiconst::GLOBAL_DATAMODEL_KALLELE_ID))
54     {
55         return false;
56     }
57     if (!(m_index2 >= 0 || m_index2 == uiconst::NO_ID))
58     {
59         return false;
60     }
61     if (!(m_index3 >= 0 || m_index3 == uiconst::NO_ID))
62     {
63         return false;
64     }
65     return true;
66 }
67 
68 force_type
GetForceType() const69 UIId::GetForceType() const
70 {
71     assert(m_hasForce);
72     return m_forceType;
73 }
74 
75 long
GetIndex1() const76 UIId::GetIndex1() const
77 {
78     assert(HasIndex1());
79     return m_index1;
80 }
81 
82 long
GetIndex2() const83 UIId::GetIndex2() const
84 {
85     assert(HasIndex1() && HasIndex2());
86     return m_index2;
87 }
88 
89 long
GetIndex3() const90 UIId::GetIndex3() const
91 {
92     assert(HasIndex1() && HasIndex2() && HasIndex3());
93     return m_index3;
94 }
95 
96 bool
operator ==(const UIId & id) const97 UIId::operator==(const UIId& id) const
98 {
99     // note -- logically, the values of m_forceType shouldn't
100     // need to be identical when m_hasForce is false. BUT,
101     // we're always constructing UIId's to have m_forceType == force_COAL
102     // when m_hasForce == false
103     return (    m_hasForce  ==  id.m_hasForce
104                 &&  m_index1    ==  id.m_index1
105                 &&  m_index2    ==  id.m_index2
106                 &&  m_index3    ==  id.m_index3
107                 &&  m_forceType ==  id.m_forceType
108         );
109 }
110 
111 bool
HasForce() const112 UIId::HasForce() const
113 {
114     return m_hasForce;
115 }
116 
117 bool
HasIndex1() const118 UIId::HasIndex1() const
119 {
120     return (m_index1 != uiconst::NO_ID);
121 }
122 
123 bool
HasIndex2() const124 UIId::HasIndex2() const
125 {
126     return (m_index2 != uiconst::NO_ID);
127 }
128 
129 bool
HasIndex3() const130 UIId::HasIndex3() const
131 {
132     return (m_index3 != uiconst::NO_ID);
133 }
134 
NO_ID()135 UIId & NO_ID()
136 {
137     static UIId no_id = UIId();
138     return no_id;
139 };
140 
GLOBAL_ID()141 UIId & GLOBAL_ID()
142 {
143     static UIId global_id = UIId(uiconst::GLOBAL_ID);
144     return global_id;
145 };
146 
147 //____________________________________________________________________________________
148