//-***************************************************************************** // With the compound property writer as an input. CpwImpl::CpwImpl( AbcA::CompoundPropertyWriterPtr iParent, hid_t iParentGroup, const std::string & iName, const AbcA::MetaData & iMeta ) : BaseCpwImpl( iParentGroup ) , m_parent( iParent ) , m_header( new AbcA::PropertyHeader(iName, iMeta) ) { // Check the validity of all inputs. ABCA_ASSERT( m_parent, "Invalid parent" ); ABCA_ASSERT( m_header, "Invalid property header" ); if ( m_header->getPropertyType() != AbcA::kCompoundProperty ) { ABCA_THROW( "Tried to create compound property with the wrong " "property type: " << m_header->getPropertyType() ); } // Set the object. AbcA::ObjectWriterPtr optr = m_parent->getObject(); ABCA_ASSERT( optr, "Invalid object" ); m_object = optr; // Write the property header. WritePropertyInfo( iParentGroup, m_header->getName(), m_header->getPropertyType(), m_header->getDataType(), false, 0, 0, 0, 0 ); WriteMetaData( iParentGroup, m_header->getName() + ".meta", m_header->getMetaData() ); }
// -------------------------------------------------------------------------------- // Writes out the meta-data section. // -------------------------------------------------------------------------------- void CodeGenerator::WriteMetaDataSection() { WriteLine(""); WriteLine(" ; ---------------------------------------------------"); WriteLine(" ; Metadata Section"); WriteLine(" ; ---------------------------------------------------"); WriteLine(""); WriteMetaData(_globalScope); }
bool CCheckpointSystem::SaveGame(EntityId checkpointId, const char* fileName) { CRY_ASSERT(fileName); if(!fileName || CHECKPOINT_SAVE_XML_NODE || CHECKPOINT_LOAD_XML_NODE) return false; //set extension FixedCheckpointString file(fileName); SetFilenameExtension(file); CryWarning(VALIDATOR_MODULE_GAME, VALIDATOR_COMMENT, "Saving checkpoint %s", file.c_str()); CHECKPOINT_SAVE_XML_NODE = GetISystem()->CreateXmlNode("Checkpoint"); //write checkpoint data SCheckpointData metaData; WriteMetaData(checkpointId, CHECKPOINT_SAVE_XML_NODE, metaData); //actor data // TODO For now, not saving actor info (AI) - If this happens later, support needs to be added for entity pools //WriteActorData(CHECKPOINT_SAVE_XML_NODE); //vehicle data WriteVehicleData(CHECKPOINT_SAVE_XML_NODE); //write game tokens WriteGameTokens(CHECKPOINT_SAVE_XML_NODE); //let game write if (m_pGameHandler) { m_pGameHandler->OnWriteData(CHECKPOINT_SAVE_XML_NODE); } //inform listeners UpdateListener(metaData, true); //write to file WriteXML(CHECKPOINT_SAVE_XML_NODE, file.c_str()); //draw text message on screen //static const ColorF color (0.0f, 0.85f, 0.2f, 1.0f); //g_pGame->GetIGameFramework()->GetIPersistantDebug()->Add2DText("Checkpoint saved", 2.5f, color, 2.0f); CHECKPOINT_SAVE_XML_NODE = NULL; return true; }
bool IODicom<T>::Write(PGCore::BaseDataObject *iDataObject, const IOParams &iParams, PGCore::BaseDataObject *iMetaDataObject/* = 0*/) { // write meta data first /* if (!iMetaDataObject) { LOG0("IO/IODicom::Write: metadata object null"); return false; } */ if (!WriteMetaData(iMetaDataObject, iParams)) { LOG0("IO/IODicom::Write: failed to read metadata."); return false; } if (iParams.SourceType()!=kPgIOSourceTypeFile) { LOG0("IO/IODicom::Write: Expecting single file path."); return false; } const std::vector<std::string>& iPaths = iParams.Source(); if (iPaths.empty()) { LOG0("IO/IODicom::Read: Invalid input filename vector."); return false; } const std::string &oFileName = iPaths[0]; if (oFileName.empty()) { LOG0("IO/IODicom::Write: Invalid input filename."); return false; } if (!iDataObject) { LOG0("IO/IODicom::Write: Invalid input image."); return false; } // cast to image type here PGCore::Image<T> *iImage = (static_cast<PGCore::Image < T > *>(iDataObject)); if (!iImage) { LOG0("IO/IODicom::Write: Invalid input image."); return false; } long ioRows=0, ioCols=0; iImage->GetDimensions((long &)ioRows, (long &)ioCols); if (ioRows*ioCols <=0) { LOG0("IO/IODicom::Write: Invalid image dimensions."); return false; } PGCore::GaussianKernel<double, T> gausskernel(1.0f); if (GetSmoothFlag()) { PGCore::Image<T> sImage; gausskernel.Convolve(*iImage, sImage); *iImage = sImage; LOG1("IO/IODicom::Smooth Image [%s] DONE.", oFileName.c_str()); } LOG1("IO/IODicom::Write: Image [%s] DONE.", oFileName.c_str()); T* iBuf = iImage->GetBuffer(); if (!iBuf) { LOG0("IO/IODicom::Write: Invalid image buffer."); return false; } FILE *fptr = fopen (oFileName.c_str(), "wb"); if (!fptr) { LOG1("IO/IODicom::Write: failed to open file %s to write.", oFileName.c_str()); return false; } try { long rv = fwrite((const void *)iBuf, sizeof(T), ioRows*ioCols, fptr); if (rv!= ioRows*ioCols) { fclose(fptr); LOG1("IO/IODicom::Write: failed to write file %s. Possible overrun.", oFileName.c_str()); return false; } } catch (...) { fclose(fptr); LOG1("IO/IODicom::Write: failed to write file %s. Possible overrun.", oFileName.c_str()); return false; } fclose(fptr); return true; }
//-***************************************************************************** void WritePropertyInfo( hid_t iGroup, const AbcA::PropertyHeader &iHeader, bool isScalarLike, uint32_t iTimeSamplingIndex, uint32_t iNumSamples, uint32_t iFirstChangedIndex, uint32_t iLastChangedIndex ) { uint32_t info[5] = {0, 0, 0, 0, 0}; uint32_t numFields = 1; // 0000 0000 0000 0000 0000 0000 0000 0011 static const uint32_t ptypeMask = 0x0003; // 0000 0000 0000 0000 0000 0000 0011 1100 static const uint32_t podMask = 0x003c; // 0000 0000 0000 0000 0000 0000 0100 0000 static const uint32_t hasTsidxMask = 0x0040; // 0000 0000 0000 0000 0000 0000 1000 0000 static const uint32_t noRepeatsMask = 0x0080; // 0000 0000 0000 0000 1111 1111 0000 0000 static const uint32_t extentMask = 0xff00; // compounds are treated differently if ( iHeader.getPropertyType() != AbcA::kCompoundProperty ) { // Slam the property type in there. info[0] |= ptypeMask & ( uint32_t )iHeader.getPropertyType(); // arrays may be scalar like, scalars are already scalar like info[0] |= ( uint32_t ) isScalarLike; uint32_t pod = ( uint32_t )iHeader.getDataType().getPod(); info[0] |= podMask & ( pod << 2 ); if (iTimeSamplingIndex != 0) { info[0] |= hasTsidxMask; } if (iFirstChangedIndex == 1 && iLastChangedIndex == iNumSamples - 1) { info[0] |= noRepeatsMask; } uint32_t extent = ( uint32_t )iHeader.getDataType().getExtent(); info[0] |= extentMask & ( extent << 8 ); ABCA_ASSERT( iFirstChangedIndex <= iNumSamples && iLastChangedIndex <= iNumSamples && iFirstChangedIndex <= iLastChangedIndex, "Illegal Sampling!" << std::endl << "Num Samples: " << iNumSamples << std::endl << "First Changed Index: " << iFirstChangedIndex << std::endl << "Last Changed Index: " << iLastChangedIndex << std::endl ); // Write the num samples. Only bother writing if // the num samples is greater than 1. Existence of name.smp0 // is used by the reader to determine if 0 or 1 sample. if ( iNumSamples > 1 ) { info[1] = iNumSamples; numFields ++; if ( iFirstChangedIndex > 1 || ( iLastChangedIndex != 0 && iLastChangedIndex != iNumSamples - 1 ) ) { info[2] = iFirstChangedIndex; info[3] = iLastChangedIndex; numFields += 2; } } // finally set time sampling index on the end if necessary if (iTimeSamplingIndex != 0) { info[numFields] = iTimeSamplingIndex; numFields ++; } } WriteSmallArray( iGroup, iHeader.getName() + ".info", H5T_STD_U32LE, H5T_NATIVE_UINT32, numFields, ( const void * ) info ); WriteMetaData( iGroup, iHeader.getName() + ".meta", iHeader.getMetaData()); }
// -------------------------------------------------------------------------------- // Writes the data out for a given symbol. // -------------------------------------------------------------------------------- void CodeGenerator::WriteMetaData(Symbol* symbol) { if (symbol->GeneratedSymbolData == false) { symbol->GeneratedSymbolData = true; // Write out the header. WriteLine(symbol->UniqueASMName + "_meta:"); // General information. switch (symbol->GetSymbolType()) { case ST_VARIABLE: WriteLine("\tdd " + StringHelper::IntToString(META_TYPE_VARIABLE)); break; case ST_FUNCTION: WriteLine("\tdd " + StringHelper::IntToString(META_TYPE_FUNCTION)); break; case ST_CLASS: WriteLine("\tdd " + StringHelper::IntToString(META_TYPE_CLASS)); break; case ST_NAMESPACE: WriteLine("\tdd " + StringHelper::IntToString(META_TYPE_NAMESPACE)); break; } // Source code declaration. WriteLine("\tdd " + FindStringLiteralLabel(symbol->DefinitionToken.Path, true)); WriteLine("\tdd " + StringHelper::IntToString(symbol->DefinitionToken.Line)); WriteLine("\tdd " + StringHelper::IntToString(symbol->DefinitionToken.Column)); // General properties. WriteLine("\tdd " + FindStringLiteralLabel(symbol->Identifier, true)); // Child properties. WriteLine("\tdd " + symbol->UniqueASMName + "_meta_children"); // Write in specific symbol information. switch (symbol->GetSymbolType()) { // Emit a namespace! case ST_NAMESPACE: { NamespaceSymbol* func = (NamespaceSymbol*)symbol; break; } // Emit metadata for a function. case ST_FUNCTION: { FunctionSymbol* func = (FunctionSymbol*)symbol; WriteLine("\tdd " + std::string(func->IsExtern == false ? func->UniqueASMName : "0")); WriteLine("\tdd " + StringHelper::IntToString((int)func->ReturnDataType->GetPrimitive())); WriteLine("\tdd " + StringHelper::IntToString(func->ReturnDataType->GetPrimitive() == PDT_CLASS ? ((ClassDataType*)func->ReturnDataType)->Class->ClassDefinitionIndex : 0)); WriteLine("\tdd " + StringHelper::IntToString(func->ParameterCount)); WriteLine("\tdd " + StringHelper::IntToString(func->ParameterSize)); WriteLine("\tdd " + StringHelper::IntToString(func->LocalCount)); WriteLine("\tdd " + StringHelper::IntToString(func->LocalSize)); WriteLine("\tdd " + StringHelper::IntToString((int)func->IsExtern)); WriteLine("\tdd " + StringHelper::IntToString((int)func->IsMethod)); WriteLine("\tdd " + StringHelper::IntToString((int)func->IsGenerator)); WriteLine("\tdd " + StringHelper::IntToString((int)func->IsVirtual)); WriteLine("\tdd " + StringHelper::IntToString((int)func->IsBase)); WriteLine("\tdd " + StringHelper::IntToString((int)func->VirtualFunctionTableOffset)); WriteLine("\tdd " + StringHelper::IntToString((int)func->AccessModifier)); break; } // Emit metadata for a variable. case ST_VARIABLE: { VariableSymbol* var = (VariableSymbol*)symbol; WriteLine("\tdd " + std::string(var->Scope == _globalScope ? var->UniqueASMName : "0")); WriteLine("\tdd " + StringHelper::IntToString((int)var->VariableType)); WriteLine("\tdd " + StringHelper::IntToString((int)var->DataType->GetPrimitive())); WriteLine("\tdd " + StringHelper::IntToString(var->DataType->GetPrimitive() == PDT_CLASS ? ((ClassDataType*)var->DataType)->Class->ClassDefinitionIndex : 0)); WriteLine("\tdd " + StringHelper::IntToString(var->StackOffset)); WriteLine("\tdd " + StringHelper::IntToString(var->ParamStackOffset)); WriteLine("\tdd " + StringHelper::IntToString(var->ClassOffset)); WriteLine("\tdd " + StringHelper::IntToString((int)var->IsConst)); WriteLine("\tdd " + StringHelper::IntToString((int)var->IsBase)); WriteLine("\tdd " + StringHelper::IntToString((int)var->AccessModifier)); break; } // Emit metadata for a class. case ST_CLASS: { ClassSymbol* classSymbol = (ClassSymbol*)symbol; WriteLine("\tdd " + classSymbol->UniqueASMName + "_vftable"); WriteLine("\tdd " + StringHelper::IntToString(classSymbol->VirtualFunctionTableSize)); WriteLine("\tdd " + StringHelper::IntToString(classSymbol->MemoryDataSize)); if (classSymbol->SuperClass != NULL) WriteLine("\tdd " + StringHelper::IntToString(classSymbol->SuperClass->ClassDefinitionIndex)); else WriteLine("\tdd -1"); WriteLine("\tdd " + StringHelper::IntToString(classSymbol->ClassDefinitionIndex)); WriteLine("\tdd " + (classSymbol->InternalConstructMethod == NULL ? "0" : classSymbol->InternalConstructMethod->UniqueASMName)); WriteLine("\tdd " + (classSymbol->InternalDisposeMethod == NULL ? "0" : classSymbol->InternalDisposeMethod->UniqueASMName)); // Write out the virtual-table. WriteLine(classSymbol->UniqueASMName + "_vftable:"); for (int i = 0; i < classSymbol->VirtualFunctionTableSize; i++) { // Emit dat virtual functions in order. for (int j = 0; j < classSymbol->Children.size(); j++) { FunctionSymbol* func = dynamic_cast<FunctionSymbol*>(classSymbol->Children.at(j)); if (func != NULL && func->VirtualFunctionTableOffset == i) { //printf("%i = %s\n", i, func->Identifier.c_str()); WriteLine("\tdd " + func->UniqueASMName); } } } break; } } WriteLine(""); // Define the list of children. WriteLine(symbol->UniqueASMName + "_meta_children:"); for (int i = 0; i < (int)symbol->Children.size(); i++) { Symbol* child = symbol->Children.at(i); if (child->GetSymbolType() == ST_CLASS || child->GetSymbolType() == ST_VARIABLE || child->GetSymbolType() == ST_FUNCTION || child->GetSymbolType() == ST_NAMESPACE) WriteLine("\tdd " + child->UniqueASMName + "_meta"); } WriteLine("\tdd 0"); WriteLine(""); // Emit the children! for (int i = 0; i < (int)symbol->Children.size(); i++) { Symbol* child = symbol->Children.at(i); if (child->GetSymbolType() == ST_CLASS || child->GetSymbolType() == ST_VARIABLE || child->GetSymbolType() == ST_FUNCTION || child->GetSymbolType() == ST_NAMESPACE) WriteMetaData(child); } } // Emit all sub symbols. // for (int i = 0; i < (int)symbol->Children.size(); i++) // WriteMetaData(symbol->Children.at(i)); }