1 // Ryzom - MMORPG Framework <http://dev.ryzom.com/projects/ryzom/>
2 // Copyright (C) 2010 Winch Gate Property Limited
4 // This program is free software: you can redistribute it and/or modify
5 // it under the terms of the GNU Affero General Public License as
6 // published by the Free Software Foundation, either version 3 of the
7 // License, or (at your option) any later version.
9 // This program is distributed in the hope that it will be useful,
10 // but WITHOUT ANY WARRANTY; without even the implied warranty of
11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 // GNU Affero General Public License for more details.
14 // You should have received a copy of the GNU Affero General Public License
15 // along with this program. If not, see <http://www.gnu.org/licenses/>.
18 #include "cond_node.h"
22 _Name
= std::string("<unnamed>");
25 CField::CField(std::string name
)
30 const std::vector
<IValue
*> &CField::getPossibleValues() const
32 return _PossibleValues
;
35 void CField::addPossibleValue(IValue
*value
)
37 _PossibleValues
.push_back( value
);
42 std::vector
<IValue
*>::iterator it_val
= _PossibleValues
.begin();
43 while ( ! _PossibleValues
.empty() )
45 delete _PossibleValues
.front();
46 _PossibleValues
.erase( _PossibleValues
.begin() );
51 const std::string
&CField::getName() const
56 /////////////////////////////////////////////////////////////////////////////////////////////
58 CBoolField::CBoolField() : CField()
60 _PossibleValues
.push_back( new CValue
<bool>(true) );
61 _PossibleValues
.push_back( new CValue
<bool>(false) );
64 CBoolField::CBoolField(std::string name
) : CField( name
)
66 _PossibleValues
.push_back( new CValue
<bool>(true) );
67 _PossibleValues
.push_back( new CValue
<bool>(false) );
70 ICondNode
*CBoolField::createNode(int key
, int pos
, std::vector
<CRecord
*> &)
72 ICondNode
*node
= new CEqualNode
<bool>(this, pos
);
76 /////////////////////////////////////////////////////////////////////////////////////////////
78 CStringField::CStringField() : CField()
82 CStringField::CStringField(std::string name
, std::vector
<std::string
> &values
) : CField(name
)
84 std::vector
<std::string
>::iterator it_val
= values
.begin();
85 while ( it_val
!= values
.end() )
87 _PossibleValues
.push_back( new CValue
<std::string
>( *it_val
) );
92 ICondNode
*CStringField::createNode(int key
, int pos
, std::vector
<CRecord
*> &)
94 return new CEqualNode
<std::string
>(this, pos
);
98 /////////////////////////////////////////////////////////////////////////////////////////////
100 CIntField::CIntField() : CField()
104 CIntField::CIntField(std::string name
, std::vector
<int> &values
) : CField( name
)
106 std::vector
<int>::iterator it_val
= values
.begin();
107 while ( it_val
!= values
.end() )
109 _PossibleValues
.push_back( new CValue
<int>( *it_val
) );
114 ICondNode
*CIntField::createNode(int key
, int pos
, std::vector
<CRecord
*> &)
116 return new CEqualNode
<int>(this, pos
);
120 /////////////////////////////////////////////////////////////////////////////////////////////
123 CRealField::CRealField() : CField()
127 CRealField::CRealField(std::string name, std::vector<double> &values) : CField( name )
129 std::vector<double>::iterator it_val = values.begin();
130 while ( it_val != values.end() )
132 _PossibleValues.push_back( new CValue<double>( *it_val ) );
137 ICondNode *CRealField::createNode(int key, int pos, std::vector<CRecord *> &)
139 return new CEqualNode<int>(this, pos);
142 void CRealField::computeRanges(int key, int pos, std::vector<CRecord *> &records)
144 int max_gain_attrib = -1;
147 std::vector<CRecord *>::iterator it_r = records.begin();
148 while ( it_r != records.end() )