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/>.
17 #ifndef PROFILE_OWNER_H
18 #define PROFILE_OWNER_H
21 #include "alias_tree_owner.h"
24 //////////////////////////////////////////////////////////////////////////////
25 // CProfileParameters //
26 //////////////////////////////////////////////////////////////////////////////
28 class CProfileParameters
31 struct TProfileParameter
37 TProfileParameter(std::string name
, std::string valueStr
, float valueFloat
)
40 , ValueFloat(valueFloat
)
45 typedef std::vector
<TProfileParameter
> TProfileParameters
;
49 : public std::unary_function
<TProfileParameter
, bool>
52 TFindParameter(std::string
const& value
)
56 bool operator ()(TProfileParameter
const& param
) const
58 return param
.Name
==_Value
;
63 void setProfileParameters(std::vector
<std::string
> const& params
);
65 void setProfileParameters(TProfileParameters
const& parameters
) { _profileParameters
= parameters
; }
67 TProfileParameters
const& profileParameters() const { return _profileParameters
; }
69 /** Ask for a profile parameter.
70 * Return true if the parameter is found and fill 'value' with parameter value.
72 bool getProfileParameter(std::string
const& paramName
, std::string
& value
) const;
74 /** Ask for a profile parameter.
75 * Return true if the parameter is found and fill 'value' with parameter value.
77 bool getProfileParameter(std::string
const& paramName
, float& value
) const;
79 /** Ask for a profile parameter.
80 * Return true if the parameter is found.
82 bool checkProfileParameter(std::string
const& paramName
) const;
84 void addProfileParameter(std::string name
, std::string valueStr
, float valueFloat
);
86 void removeProfileParameter(std::string name
);
88 void mergeProfileParameter(const TProfileParameter
¶meter
);
90 void mergeProfileParameters(const TProfileParameters
¶meters
);
92 void parseParameters(std::vector
<std::string
> const& params
, TProfileParameters
& parsed
);
93 TProfileParameters _profileParameters
;
96 //////////////////////////////////////////////////////////////////////////////
98 //////////////////////////////////////////////////////////////////////////////
100 class CProfileInState
101 : public CProfileParameters
103 , public NLMISC::IDbgPtrData
110 _MoveProfile
.setData( this );
111 _ActivityProfile
.setData( this );
114 void setMoveProfile(IAIProfileFactory
* profile
) { _MoveProfile
= profile
; }
115 IAIProfileFactory
* moveProfile() const { return _MoveProfile
; }
116 void setActivityProfile(IAIProfileFactory
* profile
) { _ActivityProfile
= profile
; }
117 IAIProfileFactory
* activityProfile() const { return _ActivityProfile
; }
120 NLMISC::CDbgPtr
<IAIProfileFactory
> _MoveProfile
;
121 NLMISC::CDbgPtr
<IAIProfileFactory
> _ActivityProfile
;
124 /****************************************************************************/
125 /* Inlined methods */
126 /****************************************************************************/
128 //////////////////////////////////////////////////////////////////////////////
129 // CProfileParameters //
130 //////////////////////////////////////////////////////////////////////////////
133 void CProfileParameters::setProfileParameters(std::vector
<std::string
> const& params
)
135 parseParameters(params
, _profileParameters
);
139 bool CProfileParameters::getProfileParameter(std::string
const& paramName
, std::string
& value
) const
141 TProfileParameters::const_iterator
it(std::find_if(_profileParameters
.begin(), _profileParameters
.end(), TFindParameter(paramName
)));
142 if (it
!= _profileParameters
.end())
144 value
= it
->ValueStr
;
152 bool CProfileParameters::getProfileParameter(std::string
const& paramName
, float& value
) const
154 TProfileParameters::const_iterator
it(std::find_if(_profileParameters
.begin(), _profileParameters
.end(), TFindParameter(paramName
)));
155 if (it
== _profileParameters
.end())
158 value
= it
->ValueFloat
;
163 bool CProfileParameters::checkProfileParameter(std::string
const& paramName
) const
165 return std::find_if(_profileParameters
.begin(), _profileParameters
.end(), TFindParameter(paramName
)) != _profileParameters
.end();
169 void CProfileParameters::addProfileParameter(std::string name
, std::string valueStr
, float valueFloat
)
171 mergeProfileParameter(TProfileParameter(name
, valueStr
, valueFloat
));
175 void CProfileParameters::removeProfileParameter(std::string name
)
177 TProfileParameters::iterator
it(std::find_if(_profileParameters
.begin(), _profileParameters
.end(), TFindParameter(name
)));
178 if (it
!= _profileParameters
.end())
179 _profileParameters
.erase(it
);
183 void CProfileParameters::mergeProfileParameter(const TProfileParameter
¶meter
)
186 TProfileParameters::iterator it
= std::find_if(_profileParameters
.begin(), _profileParameters
.end(), TFindParameter(parameter
.Name
));
187 if (it
!= _profileParameters
.end())
188 _profileParameters
.erase(it
);
190 _profileParameters
.push_back(parameter
);
194 void CProfileParameters::mergeProfileParameters(const TProfileParameters
¶meters
)
196 for (uint i
=0; i
<parameters
.size(); ++i
)
199 _profileParameters
.erase(std::remove_if(_profileParameters
.begin(), _profileParameters
.end(), TFindParameter(parameters
[i
].Name
)), _profileParameters
.end());
202 _profileParameters
.insert(_profileParameters
.end(), parameters
.begin(), parameters
.end());
206 void CProfileParameters::parseParameters(std::vector
<std::string
> const& params
, TProfileParameters
& parsed
)
208 for (uint i
=0; i
<params
.size(); ++i
)
210 std::string key
, tail
;
211 if (AI_SHARE::stringToKeywordAndTail(params
[i
], key
, tail
))
213 parsed
.push_back(TProfileParameter(key
, tail
, float(atof(tail
.c_str()))));
217 if (AI_SHARE::stringToWordAndTail(params
[i
], key
, tail
))
219 parsed
.push_back(TProfileParameter(key
, "", 0.0f
));
225 #endif // PROFILE_OWNER_H