63 lines
2.3 KiB
C++
63 lines
2.3 KiB
C++
/*
|
|
PIP - Platform Independent Primitives
|
|
C++ code info structs
|
|
Ivan Pelipenko peri4ko@yandex.ru
|
|
|
|
This program is free software: you can redistribute it and/or modify
|
|
it under the terms of the GNU Lesser General Public License as published by
|
|
the Free Software Foundation, either version 3 of the License, or
|
|
(at your option) any later version.
|
|
|
|
This program is distributed in the hope that it will be useful,
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
GNU Lesser General Public License for more details.
|
|
|
|
You should have received a copy of the GNU Lesser General Public License
|
|
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
*/
|
|
|
|
#include "picodeinfo.h"
|
|
|
|
#include "pivariant.h"
|
|
|
|
|
|
PIString PICodeInfo::EnumInfo::memberName(int value_) const {
|
|
piForeachC(PICodeInfo::EnumeratorInfo & e, members)
|
|
if (e.value == value_) return e.name.toString();
|
|
return PIString();
|
|
}
|
|
|
|
|
|
int PICodeInfo::EnumInfo::memberValue(const PIString & name_) const {
|
|
piForeachC(PICodeInfo::EnumeratorInfo & e, members)
|
|
if (e.name.toString() == name_) return e.value;
|
|
return -1;
|
|
}
|
|
|
|
|
|
PIVariantTypes::Enum PICodeInfo::EnumInfo::toPIVariantEnum() {
|
|
PIVariantTypes::Enum en(name.toString());
|
|
for (auto m: members)
|
|
en << m.toPIVariantEnumerator();
|
|
if (!en.isEmpty()) en.selectValue(members.front().value);
|
|
return en;
|
|
}
|
|
|
|
|
|
PIMap<PIConstChars, PICodeInfo::ClassInfo *> * PICodeInfo::classesInfo;
|
|
PIMap<PIConstChars, PICodeInfo::EnumInfo *> * PICodeInfo::enumsInfo;
|
|
PIMap<PIConstChars, PICodeInfo::AccessValueFunction> * PICodeInfo::accessValueFunctions;
|
|
PIMap<PIConstChars, PICodeInfo::AccessTypeFunction> * PICodeInfo::accessTypeFunctions;
|
|
|
|
bool __PICodeInfoInitializer__::_inited_ = false;
|
|
|
|
|
|
PIVariant PICodeInfo::getMemberAsVariant(const void * p, const char * class_name, const char * member_name) {
|
|
if (!p || !class_name || !member_name || !accessTypeFunctions || !accessValueFunctions) return PIVariant();
|
|
AccessTypeFunction atf = accessTypeFunctions->value(class_name, (AccessTypeFunction)0);
|
|
AccessValueFunction avf = accessValueFunctions->value(class_name, (AccessValueFunction)0);
|
|
if (!atf || !avf) return PIVariant();
|
|
return PIVariant::fromValue(avf(p, member_name), PIStringAscii(atf(member_name)));
|
|
}
|