int WriteNode(struct TreeInfo *info, struct Node *n, FILE *sfile) { struct Property *p; save_chars_in_node = 0; save_eol_in_node = 0; saveputc(sfile, ';') p = n->prop; while(p) { if((sgf_token[p->id].flags & PVT_CPLIST) && !option_expandcpl && (info->GM == 1)) CompressPointList(p); if(!WriteProperty(info, p, sfile)) return(FALSE); p = p->next; } if(option_nodelinebreaks && ((save_eol_in_node && save_linelen > 0) || (!save_eol_in_node && save_linelen > MAX_PREDICTED_LINELEN - save_chars_in_node))) saveputc(sfile, '\n'); return(TRUE); }
void GwsBinaryFeatureWriter::WriteAssociationProperty(FdoAssociationPropertyDefinition* apd, FdoIFeatureReader* reader) { if( apd->GetIsReadOnly() ) return; FdoPtr<FdoDataPropertyDefinitionCollection> idents = apd->GetIdentityProperties(); if( idents->GetCount() == 0 ) { // Search for property values with names build from the association property name and the // associated class identity properties. For example if the associated class identifier is "Id" and the // association property name is "AssocProp", then we should search for a property value with // name: "AssocProp.Id". If that property value is found and set, then that means an association // exists between the new object(we are about to insert) and the object identified by the value // of the property value(AssocProp.Id) FdoPtr<FdoClassDefinition> cls = apd->GetAssociatedClass(); idents = cls->GetIdentityProperties(); } if( reader->IsNull( apd->GetName() ) ) return; FdoPtr<FdoIFeatureReader> loc_reader = reader->GetFeatureObject( apd->GetName() ); if( ! loc_reader->ReadNext() ) return; for(int i=0; i<idents->GetCount(); i++ ) { FdoPtr<FdoDataPropertyDefinition> prop = idents->GetItem( i ); if( ! loc_reader->IsNull( prop->GetName() ) ) WriteProperty( prop, loc_reader); } }
//////////////////////////////////////////////////////////////////// // Core PropertySet Functions // //////////////////////////////////////////////////////////////////// // OpenPropertyStorage // // Function takes a PropertySetStorage and returns the desired // PropertyStorage for the FMTID. The function will create a storage // if one does not exist (and flags allow). // STDAPI OpenPropertyStorage(IPropertySetStorage* pPropSS, REFFMTID fmtid, BOOL fReadOnly, DWORD dwFlags, IPropertyStorage** ppPropStg) { HRESULT hr; DWORD dwMode; BOOL fNoCreate = ((dwFlags & dsoOptionDontAutoCreate) == dsoOptionDontAutoCreate); BOOL fUseANSI = ((dwFlags & dsoOptionUseMBCStringsForNewSets) == dsoOptionUseMBCStringsForNewSets); ASSERT(pPropSS); ASSERT(ppPropStg); if ((pPropSS == NULL) || (ppPropStg == NULL)) return E_UNEXPECTED; *ppPropStg = NULL; // Set the access mode for read/write access... dwMode = (fReadOnly ? (STGM_READ | STGM_SHARE_EXCLUSIVE) : (STGM_READWRITE | STGM_SHARE_EXCLUSIVE)); // We try to open the property set. If this fails, it may be beacuse // it doesn't exist so we'll try to create the set... hr = pPropSS->Open(fmtid, dwMode, ppPropStg); if ((hr == STG_E_FILENOTFOUND) && !fReadOnly && !fNoCreate) { // FIX -- ADDED BY REQUEST - Feb 1, 2001 // Outlook 2000/XP doesn't handle Unicode property sets very well. So if we need to // create a propset for the caller, allow the caller the ability to set the // PROPSETFLAG_ANSI flag on the new set. // // The ANSI flag was the default in File 1.0, but this was changed to Unicode // for version 1.2 to meet request by ASIA/EMEA clients. Unicode should work // but there have been reported problems (in Outlook, Win2K SP2) that indicate // clients may want to use the ANSI flag (so it is passed here)... hr = pPropSS->Create(fmtid, NULL, (fUseANSI ? PROPSETFLAG_ANSI : 0), dwMode, ppPropStg); // If we created with ANSI flag, we must set the code page value to match ACP... if (SUCCEEDED(hr) && (fUseANSI) && (*ppPropStg)) { VARIANT vtT; PROPSPEC spc; spc.ulKind = PRSPEC_PROPID; spc.propid = PID_CODEPAGE; // FIX -- ADDED BY REQUEST - Oct 30, 2001 // Check for CodePage first. It appears certain configurations choke on modification // of the code page. This appears to be a change in OLE32 behavior. Workaround is to // check to see if OLE32 has added the code page already during the create, and if so // we can skip out on adding it ourselves... if (FAILED(ReadProperty(*ppPropStg, spc, 0, &vtT))) { // If not, we should add it... vtT.vt = VT_I4; vtT.lVal = GetACP(); WriteProperty(*ppPropStg, spc, 0, &vtT); } } } return hr; }
void JsnWriter::AddProperty( const JsnFragment& name, const JsnFragment& value ) { switch( value.m_Type ) { case kJsn_Int: case kJsn_Float: case kJsn_String: WriteProperty( name, value ); break; case kJsn_True: WriteProperty( name, "true" ); break; case kJsn_False: WriteProperty( name, "false" ); break; case kJsn_Null: WriteProperty( name, "null" ); break; default: break; } }
bool GwsBinaryFeatureWriter::WriteAssociationProperty(FdoAssociationPropertyDefinition* apd, FdoPropertyValueCollection* pvc) { bool errorIfSet = apd->GetIsReadOnly(); bool oneIdentIsNull = false; bool written = false; FdoPtr<FdoDataPropertyDefinitionCollection> idents = apd->GetIdentityProperties(); if( idents->GetCount() == 0 ) { // Search for property values with names build from the association property name and the // associated class identity properties. For example if the associated class identifier is "Id" and the // association property name is "AssocProp", then we should search for a property value with // name: "AssocProp.Id". If that property value is found and set, then that means an association // exists between the new object(we are about to insert) and the object identified by the value // of the property value(AssocProp.Id) FdoPtr<FdoClassDefinition> cls = apd->GetAssociatedClass(); idents = cls->GetIdentityProperties(); } for(int i=0; i<idents->GetCount(); i++ ) { FdoPtr<FdoDataPropertyDefinition> prop = idents->GetItem( i ); std::wstring wstr = apd->GetName(); wstr += L"."; wstr += prop->GetName(); FdoPtr<FdoPropertyValue> pv = pvc->FindItem( wstr.c_str() ); if(pv != NULL) { if( errorIfSet ) GWS_THROW(eGwsFailed); //cannot add readonly association property value if( oneIdentIsNull ) GWS_THROW(eGwsFailed); //one of the identity properties is null WriteProperty(prop, pv, true); written = true; oneIdentIsNull = false; } else { if( written ) // we already written one or more identity and this one is null GWS_THROW(eGwsFailed); oneIdentIsNull = true; } } return written; }
void WriteString(const std::string &name, const std::string &value) override { std::ostringstream buffer; buffer << '"'; for (char c : value) { if (c == '\\' || c == '"') { buffer << '\\'; } buffer << c; } buffer << '"'; WriteProperty(name, buffer.str()); }
void asCRestore::WriteObjectTypeDeclaration(asCObjectType *ot) { // name WriteString(&ot->name); // size int size = ot->size; WRITE_NUM(size); // properties[] size = ot->properties.GetLength(); WRITE_NUM(size); for( asUINT n = 0; n < ot->properties.GetLength(); n++ ) { WriteProperty(ot->properties[n]); } // TODO: // methods[] // behaviours }
void FileFormatImplementation::EndPropertyEmbedding() { for ( FileFormatPropertyArray::const_iterator i = m_data->properties.Begin(); i != m_data->properties.End(); ++i ) WriteProperty( i->id, i->value ); m_data->properties.Clear(); }
int asCRestore::Save() { unsigned long i, count; // structTypes[] count = module->structTypes.GetLength(); WRITE_NUM(count); for( i = 0; i < count; ++i ) { WriteObjectTypeDeclaration(module->structTypes[i]); } // usedTypeIndices[] count = module->usedTypes.GetLength(); WRITE_NUM(count); for( i = 0; i < count; ++i ) { WriteObjectType(module->usedTypes[i]); } // scriptGlobals[] count = module->scriptGlobals.GetLength(); WRITE_NUM(count); for( i = 0; i < count; ++i ) WriteProperty(module->scriptGlobals[i]); // globalMem size (can restore data using @init()) count = module->globalMem.GetLength(); WRITE_NUM(count); // globalVarPointers[] WriteGlobalVarPointers(); // initFunction WriteFunction(&module->initFunction); // scriptFunctions[] count = module->scriptFunctions.GetLength(); WRITE_NUM(count); for( i = 0; i < count; ++i ) WriteFunction(module->scriptFunctions[i]); // stringConstants[] count = module->stringConstants.GetLength(); WRITE_NUM(count); for( i = 0; i < count; ++i ) WriteString(module->stringConstants[i]); // importedFunctions[] and bindInformations[] count = module->importedFunctions.GetLength(); WRITE_NUM(count); for( i = 0; i < count; ++i ) { WriteFunction(module->importedFunctions[i]); WRITE_NUM(module->bindInformations[i].importFrom); } // usedTypeIds[] WriteUsedTypeIds(); return asSUCCESS; }
void CallJavascriptFunction(Handle<Context> context, Handle<Value> This, UFunction* SignatureFunction, Handle<Function> func, void* Parms) { SCOPE_CYCLE_COUNTER(STAT_JavascriptFunctionCallToJavascript); auto isolate = context->GetIsolate(); HandleScope handle_scope(isolate); auto Buffer = reinterpret_cast<uint8*>(Parms); enum { MaxArgs = 32 }; Handle<Value> argv[MaxArgs]; int argc = 0; TFieldIterator<UProperty> Iter(SignatureFunction); for (; Iter && argc < MaxArgs && (Iter->PropertyFlags & (CPF_Parm | CPF_ReturnParm)) == CPF_Parm; ++Iter) { UProperty* Param = *Iter; argv[argc++] = ReadProperty(isolate, Param, Buffer, FNoPropertyOwner()); } UProperty* ReturnParam = nullptr; for (; Iter; ++Iter) { UProperty* Param = *Iter; if (Param->GetPropertyFlags() & CPF_ReturnParm) { ReturnParam = Param; break; } } TryCatch try_catch; auto value = func->Call(This, argc, argv); if (try_catch.HasCaught()) { FV8Exception::Report(try_catch); } bool bHasAnyOutParams = false; if (SignatureFunction && SignatureFunction->HasAnyFunctionFlags(FUNC_HasOutParms)) { // Iterate over input parameters for (TFieldIterator<UProperty> It(SignatureFunction); It && (It->PropertyFlags & (CPF_Parm | CPF_ReturnParm)) == CPF_Parm; ++It) { // This is 'out ref'! if ((It->PropertyFlags & (CPF_ConstParm | CPF_OutParm)) == CPF_OutParm) { bHasAnyOutParams = true; break; } } } if (bHasAnyOutParams) { FIsolateHelper I(isolate); if (value.IsEmpty() || !value->IsObject()) { I.Throw(TEXT("...")); return; } auto Object = value->ToObject(); // Iterate over parameters again for (TFieldIterator<UProperty> It(SignatureFunction); It; ++It) { UProperty* Param = *It; auto PropertyFlags = Param->GetPropertyFlags(); // pass return parameter as '$' if (PropertyFlags & CPF_ReturnParm) { auto sub_value = Object->Get(I.Keyword("$")); WriteProperty(isolate, ReturnParam, Buffer, sub_value); } // rejects 'const T&' and pass 'T&' as its name else if ((PropertyFlags & (CPF_ConstParm | CPF_OutParm)) == CPF_OutParm) { auto sub_value = Object->Get(I.Keyword(Param->GetName())); if (!sub_value.IsEmpty()) { // value can be null if isolate is in trouble WriteProperty(isolate, Param, Buffer, sub_value); } } } } else { if (ReturnParam) { WriteProperty(isolate, ReturnParam, Buffer, value); } } }
JsnHandler* JsnWriter::BeginArray( const JsnFragment& name ) { WriteProperty( name, "[" ); return new JsnWriter( *this ); }
void WriteBoolean(const std::string &name, bool value) override { WriteProperty(name, value ? "true" : "false"); }
//serializes a collection of property values into a byte array //This function differs from WriteFeature() in that //it will merge property values specified in the given PropertyValueCollection //with property values in the given FeatureReader. The PropertyValueCollection //represents properties to be updated in an old feature record represented by //the given FeatureReader. void GwsBinaryFeatureWriter::WriteFeature(FdoClassDefinition* fc, FdoString* fcName, FdoPropertyValueCollection* pvc, FdoIFeatureReader* reader) { FdoPtr<FdoReadOnlyPropertyDefinitionCollection> bpdc = fc->GetBaseProperties(); FdoPtr<FdoPropertyDefinitionCollection> pdc = fc->GetProperties(); //find number of properties we will store into the data record //we will use this number to save an offset into the data records for each property //at the beginning of the data record int numProps = bpdc->GetCount() + pdc->GetCount();// - idpdc->GetCount(); //now generate the data value -- write all property values, except for the ones //we already wrote to the key -- we have to check if each one is in the ID prop //collection //write feature class ID m_wrtr.WriteString(fcName); int fcNameLen = m_wrtr.GetPosition(); //reserve space for offsets into property values in data record for (int i=0; i<numProps; i++) m_wrtr.WriteInt32(0); int index = 0; //base properties first for (int i=0; i<bpdc->GetCount(); i++) { FdoPtr<FdoPropertyDefinition> pd = (FdoPropertyDefinition*)bpdc->GetItem(i); //save offset of property data to the reserved position at the //beginning of the record //TODO: endian ((int*)(m_wrtr.GetData() + fcNameLen))[index++] = m_wrtr.GetPosition(); //if property is autogenerated, do not write //anything. We use the record number as autogen property value //so we can obtain it at read time //if (!pi->IsPropAutoGen(pd->GetName())) //{ if (pvc) { if( pd->GetPropertyType() == FdoPropertyType_AssociationProperty ) { if( ! WriteAssociationProperty((FdoAssociationPropertyDefinition*)pd.p, pvc) ) WriteAssociationProperty((FdoAssociationPropertyDefinition*)pd.p, reader); } else { FdoPtr<FdoPropertyValue> pv((FdoPropertyValue*)pvc->FindItem(pd->GetName())); if(pv != NULL) WriteProperty(pd, pv); else WriteProperty(pd, reader); } } else { WriteProperty(pd, reader); } //} } //class properties for (int i=0; i<pdc->GetCount(); i++) { FdoPtr<FdoPropertyDefinition> pd = (FdoPropertyDefinition*)pdc->GetItem(i); //save offset of property data to the reserved position at the //beginning of the record //TODO: endian ((int*)(m_wrtr.GetData() + fcNameLen))[index++] = m_wrtr.GetPosition(); //if property is autogenerated, do not write //anything. We use the record number as autogen property value //so we can obtain it at read time //if (!pi->IsPropAutoGen(pd->GetName())) //{ if (pvc) { if( pd->GetPropertyType() == FdoPropertyType_AssociationProperty ) { if( ! WriteAssociationProperty((FdoAssociationPropertyDefinition*)pd.p, pvc) ) WriteAssociationProperty((FdoAssociationPropertyDefinition*)pd.p, reader); } else { FdoPtr<FdoPropertyValue> pv((FdoPropertyValue*)pvc->GetItem(pd->GetName())); if(pv != NULL) WriteProperty(pd, pv); else WriteProperty(pd, reader); } } else { WriteProperty(pd, reader); } //} } }
void WriteSint32(const std::string &name, sint32 value) override { WriteProperty(name, std::to_string(value)); }
JsnHandler* JsnWriter::BeginObject( const JsnFragment& name ) { WriteProperty( name, "{" ); return new JsnWriter( *this ); }
void WriteEnum(const std::string &name, const std::string &key) override { WriteProperty(name, key); }
void WriteFloat(const std::string &name, float value) override { WriteProperty(name, std::to_string(value)); }