TiXmlElement* ObjectBase::SerializeObject() { TiXmlElement *element = new TiXmlElement("object"); element->SetAttribute("class", _STDSTR( GetClassName() )); for (unsigned int i=0; i< GetPropertyCount(); i++) { shared_ptr<Property> prop = GetProperty(i); TiXmlElement *prop_element = new TiXmlElement("property"); prop_element->SetAttribute("name", _STDSTR(prop->GetName() )); TiXmlText* prop_value = new TiXmlText( _STDSTR(prop->GetValue())); prop_element->LinkEndChild(prop_value); element->LinkEndChild(prop_element); } for (unsigned int i=0 ; i < GetChildCount() ; i++) { shared_ptr<ObjectBase> child = GetChild(i); TiXmlElement * child_element = child->SerializeObject(); element->LinkEndChild(child_element); } return element; }
void CEntityPropertyHandler::LoadEntityXMLProperties(IEntity *pEntity, const XmlNodeRef& xml) { if(auto properties = xml->findChild("Properties")) { for(int i = 0; i < properties->getNumAttributes(); i++) { const char *name; const char *value; properties->getAttributeByIndex(i, &name, &value); int index = 0; bool exists = false; for(; index < GetPropertyCount(); index++) { SPropertyInfo info; GetPropertyInfo(index, info); if(!strcmp(info.name, name)) { exists = true; break; } } if(exists) SetProperty(pEntity, index, value); else MonoWarning("Could not set property %s because it did not exist", name); } } }
void ObjectBase::SerializeObject( ticpp::Element* serializedElement ) { ticpp::Element element( "object" ); element.SetAttribute( "class", _STDSTR( GetClassName() ) ); element.SetAttribute( "expanded", GetExpanded() ); for ( unsigned int i = 0; i < GetPropertyCount(); i++ ) { PProperty prop = GetProperty( i ); ticpp::Element prop_element( "property" ); prop_element.SetAttribute( "name", _STDSTR( prop->GetName() ) ); prop_element.SetText( _STDSTR( prop->GetValue() ) ); element.LinkEndChild( &prop_element ); } for ( unsigned int i = 0; i < GetEventCount(); i++ ) { PEvent event = GetEvent( i ); ticpp::Element event_element( "event" ); event_element.SetAttribute( "name", _STDSTR( event->GetName() ) ); event_element.SetText( _STDSTR( event->GetValue() ) ); element.LinkEndChild( &event_element ); } for ( unsigned int i = 0 ; i < GetChildCount(); i++ ) { PObjectBase child = GetChild( i ); ticpp::Element child_element; child->SerializeObject( &child_element ); element.LinkEndChild( &child_element ); } *serializedElement = element; }
/*! \brief Get primary key \return property name or NULL */ const char *VFKDataBlockSQLite::GetKey() const { if( GetPropertyCount() > 1 ) { const VFKPropertyDefn *poPropDefn = GetProperty(0); const char *pszKey = poPropDefn->GetName(); if( EQUAL(pszKey, "ID") ) return pszKey; } return NULL; }
void DynamicTypeHandler::InvalidateInlineCachesForAllProperties(ScriptContext* requestContext) { int count = GetPropertyCount(); if (count < 128) // Invalidate a propertyId involves dictionary lookups. Only do this when the number is relatively small. { for (int i = 0; i < count; i++) { PropertyId propertyId = GetPropertyId(requestContext, static_cast<PropertyIndex>(i)); if (propertyId != Constants::NoProperty) { isStoreField ? requestContext->InvalidateStoreFieldCaches(propertyId) : requestContext->InvalidateProtoCaches(propertyId); } } } else { isStoreField ? requestContext->InvalidateAllStoreFieldCaches() : requestContext->InvalidateAllProtoCaches(); } }
void CMonoEntityExtension::FullSerialize(TSerialize ser) { IEntity *pEntity = GetEntity(); ser.BeginGroup("Properties"); auto pPropertyHandler = static_cast<CEntityPropertyHandler *>(pEntity->GetClass()->GetPropertyHandler()); for(int i = 0; i < pPropertyHandler->GetPropertyCount(); i++) { if(ser.IsWriting()) { IEntityPropertyHandler::SPropertyInfo propertyInfo; pPropertyHandler->GetPropertyInfo(i, propertyInfo); ser.Value(propertyInfo.name, pPropertyHandler->GetProperty(pEntity, i)); } else { IEntityPropertyHandler::SPropertyInfo propertyInfo; pPropertyHandler->GetPropertyInfo(i, propertyInfo); char *propertyValue = nullptr; ser.ValueChar(propertyInfo.name, propertyValue, 0); pPropertyHandler->SetProperty(pEntity, i, propertyValue); } } ser.EndGroup(); ser.BeginGroup("ManagedEntity"); IMonoArray *pArgs = CreateMonoArray(1); pArgs->InsertNativePointer(&ser); m_pScript->GetClass()->InvokeArray(m_pScript->GetManagedObject(), "InternalFullSerialize", pArgs); pArgs->Release(); ser.EndGroup(); }
/*++ duPropertyGroup::GetPropertyName Routine Description: 获得属性名称. Arguments: nNameIndex - 属性索引 Return Value: 如果成功,属性名称字符串.如果失败,返回空(NULL). Revision History: Jan-17-95 Davepl Created --*/ const TCHAR * duPropertyGroup::GetPropertyName(int nNameIndex) { int propCount = GetPropertyCount(); if (nNameIndex >= 0 && nNameIndex < propCount) { duPropertyList::iterator Iter = m_duPropertyList.begin(); int i = 0; for (; Iter != m_duPropertyList.end(); Iter++) { if (i == nNameIndex) { duProperty *pProp = *Iter; if (pProp) { return pProp->duPropertyName; } } i++; } } return NULL; }
CPLXMLNode *GMLFeatureClass::SerializeToXML() { CPLXMLNode *psRoot; int iProperty; /* -------------------------------------------------------------------- */ /* Set feature class and core information. */ /* -------------------------------------------------------------------- */ psRoot = CPLCreateXMLNode( NULL, CXT_Element, "GMLFeatureClass" ); CPLCreateXMLElementAndValue( psRoot, "Name", GetName() ); CPLCreateXMLElementAndValue( psRoot, "ElementPath", GetElementName() ); if( GetGeometryElement() != NULL && strlen(GetGeometryElement()) > 0 ) CPLCreateXMLElementAndValue( psRoot, "GeometryElementPath", GetGeometryElement() ); if( GetGeometryType() != 0 /* wkbUnknown */ ) { char szValue[128]; sprintf( szValue, "%d", GetGeometryType() ); CPLCreateXMLElementAndValue( psRoot, "GeometryType", szValue ); } /* -------------------------------------------------------------------- */ /* Write out dataset specific information. */ /* -------------------------------------------------------------------- */ CPLXMLNode *psDSI; if( m_bHaveExtents || m_nFeatureCount != -1 || m_pszExtraInfo != NULL ) { psDSI = CPLCreateXMLNode( psRoot, CXT_Element, "DatasetSpecificInfo" ); if( m_nFeatureCount != -1 ) { char szValue[128]; sprintf( szValue, "%d", m_nFeatureCount ); CPLCreateXMLElementAndValue( psDSI, "FeatureCount", szValue ); } if( m_bHaveExtents ) { char szValue[128]; sprintf( szValue, "%.5f", m_dfXMin ); CPLCreateXMLElementAndValue( psDSI, "ExtentXMin", szValue ); sprintf( szValue, "%.5f", m_dfXMax ); CPLCreateXMLElementAndValue( psDSI, "ExtentXMax", szValue ); sprintf( szValue, "%.5f", m_dfYMin ); CPLCreateXMLElementAndValue( psDSI, "ExtentYMin", szValue ); sprintf( szValue, "%.5f", m_dfYMax ); CPLCreateXMLElementAndValue( psDSI, "ExtentYMax", szValue ); } if( m_pszExtraInfo ) CPLCreateXMLElementAndValue( psDSI, "ExtraInfo", m_pszExtraInfo ); } /* -------------------------------------------------------------------- */ /* emit property information. */ /* -------------------------------------------------------------------- */ for( iProperty = 0; iProperty < GetPropertyCount(); iProperty++ ) { GMLPropertyDefn *poPDefn = GetProperty( iProperty ); CPLXMLNode *psPDefnNode; const char *pszTypeName = "Unknown"; psPDefnNode = CPLCreateXMLNode( psRoot, CXT_Element, "PropertyDefn" ); CPLCreateXMLElementAndValue( psPDefnNode, "Name", poPDefn->GetName() ); CPLCreateXMLElementAndValue( psPDefnNode, "ElementPath", poPDefn->GetSrcElement() ); switch( poPDefn->GetType() ) { case GMLPT_Untyped: pszTypeName = "Untyped"; break; case GMLPT_String: pszTypeName = "String"; break; case GMLPT_Integer: pszTypeName = "Integer"; break; case GMLPT_Real: pszTypeName = "Real"; break; case GMLPT_Complex: pszTypeName = "Complex"; break; case GMLPT_IntegerList: pszTypeName = "IntegerList"; break; case GMLPT_RealList: pszTypeName = "RealList"; break; case GMLPT_StringList: pszTypeName = "StringList"; break; } CPLCreateXMLElementAndValue( psPDefnNode, "Type", pszTypeName ); if( EQUAL(pszTypeName,"String") ) { char szMaxLength[48]; sprintf(szMaxLength, "%d", poPDefn->GetWidth()); CPLCreateXMLElementAndValue ( psPDefnNode, "Width", szMaxLength ); } if( poPDefn->GetWidth() > 0 && EQUAL(pszTypeName,"Integer") ) { char szLength[48]; sprintf(szLength, "%d", poPDefn->GetWidth()); CPLCreateXMLElementAndValue ( psPDefnNode, "Width", szLength ); } if( poPDefn->GetWidth() > 0 && EQUAL(pszTypeName,"Real") ) { char szLength[48]; sprintf(szLength, "%d", poPDefn->GetWidth()); CPLCreateXMLElementAndValue ( psPDefnNode, "Width", szLength ); char szPrecision[48]; sprintf(szPrecision, "%d", poPDefn->GetPrecision()); CPLCreateXMLElementAndValue ( psPDefnNode, "Precision", szPrecision ); } } return psRoot; }
CPLXMLNode *GMLFeatureClass::SerializeToXML() { CPLXMLNode *psRoot; int iProperty; /* -------------------------------------------------------------------- */ /* Set feature class and core information. */ /* -------------------------------------------------------------------- */ psRoot = CPLCreateXMLNode( NULL, CXT_Element, "GMLFeatureClass" ); CPLCreateXMLElementAndValue( psRoot, "Name", GetName() ); CPLCreateXMLElementAndValue( psRoot, "ElementPath", GetElementName() ); if( m_nGeometryPropertyCount > 1 ) { for(int i=0; i < m_nGeometryPropertyCount; i++) { GMLGeometryPropertyDefn* poGeomFDefn = m_papoGeometryProperty[i]; CPLXMLNode *psPDefnNode; psPDefnNode = CPLCreateXMLNode( psRoot, CXT_Element, "GeomPropertyDefn" ); if( strlen(poGeomFDefn->GetName()) > 0 ) CPLCreateXMLElementAndValue( psPDefnNode, "Name", poGeomFDefn->GetName() ); if( poGeomFDefn->GetSrcElement() != NULL && strlen(poGeomFDefn->GetSrcElement()) > 0 ) CPLCreateXMLElementAndValue( psPDefnNode, "ElementPath", poGeomFDefn->GetSrcElement() ); if( poGeomFDefn->GetType() != 0 /* wkbUnknown */ ) { char szValue[128]; OGRwkbGeometryType eType = (OGRwkbGeometryType)poGeomFDefn->GetType(); CPLString osStr(OGRToOGCGeomType(eType)); if( wkbHasZ(eType) ) osStr += "Z"; CPLCreateXMLNode( psPDefnNode, CXT_Comment, osStr.c_str() ); sprintf( szValue, "%d", eType ); CPLCreateXMLElementAndValue( psPDefnNode, "Type", szValue ); } } } else if( m_nGeometryPropertyCount == 1 ) { GMLGeometryPropertyDefn* poGeomFDefn = m_papoGeometryProperty[0]; if( strlen(poGeomFDefn->GetName()) > 0 ) CPLCreateXMLElementAndValue( psRoot, "GeometryName", poGeomFDefn->GetName() ); if( poGeomFDefn->GetSrcElement() != NULL && strlen(poGeomFDefn->GetSrcElement()) > 0 ) CPLCreateXMLElementAndValue( psRoot, "GeometryElementPath", poGeomFDefn->GetSrcElement() ); if( poGeomFDefn->GetType() != 0 /* wkbUnknown */ ) { char szValue[128]; OGRwkbGeometryType eType = (OGRwkbGeometryType)poGeomFDefn->GetType(); CPLString osStr(OGRToOGCGeomType(eType)); if( wkbHasZ(eType) ) osStr += "Z"; CPLCreateXMLNode( psRoot, CXT_Comment, osStr.c_str() ); sprintf( szValue, "%d", eType ); CPLCreateXMLElementAndValue( psRoot, "GeometryType", szValue ); } } else { CPLCreateXMLElementAndValue( psRoot, "GeometryType", "100" ); } const char* pszSRSName = GetSRSName(); if( pszSRSName ) { CPLCreateXMLElementAndValue( psRoot, "SRSName", pszSRSName ); } /* -------------------------------------------------------------------- */ /* Write out dataset specific information. */ /* -------------------------------------------------------------------- */ CPLXMLNode *psDSI; if( m_bHaveExtents || m_nFeatureCount != -1 || m_pszExtraInfo != NULL ) { psDSI = CPLCreateXMLNode( psRoot, CXT_Element, "DatasetSpecificInfo" ); if( m_nFeatureCount != -1 ) { char szValue[128]; sprintf( szValue, CPL_FRMT_GIB, m_nFeatureCount ); CPLCreateXMLElementAndValue( psDSI, "FeatureCount", szValue ); } if( m_bHaveExtents && fabs(m_dfXMin) < 1e100 && fabs(m_dfXMax) < 1e100 && fabs(m_dfYMin) < 1e100 && fabs(m_dfYMax) < 1e100 ) { char szValue[128]; CPLsnprintf( szValue, sizeof(szValue), "%.5f", m_dfXMin ); CPLCreateXMLElementAndValue( psDSI, "ExtentXMin", szValue ); CPLsnprintf( szValue, sizeof(szValue), "%.5f", m_dfXMax ); CPLCreateXMLElementAndValue( psDSI, "ExtentXMax", szValue ); CPLsnprintf( szValue, sizeof(szValue), "%.5f", m_dfYMin ); CPLCreateXMLElementAndValue( psDSI, "ExtentYMin", szValue ); CPLsnprintf( szValue, sizeof(szValue), "%.5f", m_dfYMax ); CPLCreateXMLElementAndValue( psDSI, "ExtentYMax", szValue ); } if( m_pszExtraInfo ) CPLCreateXMLElementAndValue( psDSI, "ExtraInfo", m_pszExtraInfo ); } /* -------------------------------------------------------------------- */ /* emit property information. */ /* -------------------------------------------------------------------- */ for( iProperty = 0; iProperty < GetPropertyCount(); iProperty++ ) { GMLPropertyDefn *poPDefn = GetProperty( iProperty ); CPLXMLNode *psPDefnNode; const char *pszTypeName = "Unknown"; psPDefnNode = CPLCreateXMLNode( psRoot, CXT_Element, "PropertyDefn" ); CPLCreateXMLElementAndValue( psPDefnNode, "Name", poPDefn->GetName() ); CPLCreateXMLElementAndValue( psPDefnNode, "ElementPath", poPDefn->GetSrcElement() ); switch( poPDefn->GetType() ) { case GMLPT_Untyped: pszTypeName = "Untyped"; break; case GMLPT_String: case GMLPT_Boolean: pszTypeName = "String"; break; case GMLPT_Integer: case GMLPT_Short: case GMLPT_Integer64: pszTypeName = "Integer"; break; case GMLPT_Real: case GMLPT_Float: pszTypeName = "Real"; break; case GMLPT_Complex: pszTypeName = "Complex"; break; case GMLPT_IntegerList: case GMLPT_Integer64List: pszTypeName = "IntegerList"; break; case GMLPT_RealList: pszTypeName = "RealList"; break; case GMLPT_StringList: case GMLPT_BooleanList: pszTypeName = "StringList"; break; /* should not happen in practise for now because this is not */ /* autodetected */ case GMLPT_FeatureProperty: pszTypeName = "FeatureProperty"; break; /* should not happen in practise for now because this is not */ /* autodetected */ case GMLPT_FeaturePropertyList: pszTypeName = "FeaturePropertyList"; break; } CPLCreateXMLElementAndValue( psPDefnNode, "Type", pszTypeName ); if( poPDefn->GetType() == GMLPT_Boolean || poPDefn->GetType() == GMLPT_BooleanList ) CPLCreateXMLElementAndValue( psPDefnNode, "Subtype", "Boolean" ); else if( poPDefn->GetType() == GMLPT_Short ) CPLCreateXMLElementAndValue( psPDefnNode, "Subtype", "Short" ); else if( poPDefn->GetType() == GMLPT_Float ) CPLCreateXMLElementAndValue( psPDefnNode, "Subtype", "Float" ); else if( poPDefn->GetType() == GMLPT_Integer64 || poPDefn->GetType() == GMLPT_Integer64List ) CPLCreateXMLElementAndValue( psPDefnNode, "Subtype", "Integer64" ); if( EQUAL(pszTypeName,"String") ) { char szMaxLength[48]; sprintf(szMaxLength, "%d", poPDefn->GetWidth()); CPLCreateXMLElementAndValue ( psPDefnNode, "Width", szMaxLength ); } if( poPDefn->GetWidth() > 0 && EQUAL(pszTypeName,"Integer") ) { char szLength[48]; sprintf(szLength, "%d", poPDefn->GetWidth()); CPLCreateXMLElementAndValue ( psPDefnNode, "Width", szLength ); } if( poPDefn->GetWidth() > 0 && EQUAL(pszTypeName,"Real") ) { char szLength[48]; sprintf(szLength, "%d", poPDefn->GetWidth()); CPLCreateXMLElementAndValue ( psPDefnNode, "Width", szLength ); char szPrecision[48]; sprintf(szPrecision, "%d", poPDefn->GetPrecision()); CPLCreateXMLElementAndValue ( psPDefnNode, "Precision", szPrecision ); } } return psRoot; }
void ScriptEngine::generateReference() { if (!m_engine) return; std::ofstream out("AngelScript reference.txt"); out << "*** Globals ***" << std::endl << std::endl; int nb = m_engine->GetGlobalFunctionCount(); for (int i = 0; i < nb; ++i) { auto func = m_engine->GetGlobalFunctionByIndex(i); out << "\t" << func->GetDeclaration(true, false, true) << std::endl; } out << std::endl << "*** Types ***" << std::endl << std::endl; nb = m_engine->GetObjectTypeCount(); for (int i = 0; i < nb; ++i) { auto info = m_engine->GetObjectTypeByIndex(i); out << " * " << info->GetName() << std::endl; int nb2 = info->GetPropertyCount(); for (int j = 0; j < nb2; ++j) { const char* name; int typeId; bool isPrivate, isProtected, isReference; auto prop = info->GetProperty(j, &name, &typeId, &isPrivate, &isProtected, nullptr, &isReference); out << "\t"; if (isProtected) out << "protected "; if (isPrivate) out << "private "; out << m_engine->GetTypeDeclaration(typeId); if (isReference) out << "&"; out << " "; out << name << std::endl; } if (nb2 != 0) out << std::endl; nb2 = info->GetBehaviourCount(); bool hasBehaviour = false; for (int j = 0; j < nb2; ++j) { asEBehaviours behaviour; auto func = info->GetBehaviourByIndex(j, &behaviour); if (behaviour == asBEHAVE_CONSTRUCT || behaviour == asBEHAVE_DESTRUCT) { hasBehaviour = true; out << "\t" << func->GetDeclaration(false, false, true) << std::endl; } } if (hasBehaviour) out << std::endl; nb2 = info->GetFactoryCount(); for (int j = 0; j < nb2; ++j) { auto func = info->GetFactoryByIndex(j); out << "\t" << func->GetDeclaration(false, false, true) << std::endl; } if (nb2 != 0) out << std::endl; nb2 = info->GetMethodCount(); for (int j = 0; j < nb2; ++j) { auto func = info->GetMethodByIndex(j); out << "\t" << func->GetDeclaration(false, false, true) << std::endl; } out << std::endl; } }