void PointerMetaClass::initialize( const ObjectWrapper &obj, InputStream* inputStream ) const { Address address = obj.get_address(); kernel_assert(obj.get_meta_class() == this); // debugit("initializing pointer ",address); if ( _pre_init ) { _pre_init( obj, true, inputStream ); } Address objectAddress = *(Address*)address; // test for whether it's already there if ( _is_static || ( _pointer_owns_object && inputStream->exists_in_input_stream( objectAddress ) && (!inputStream->was_already_visited( objectAddress ) ) ) ) { if ( !_is_static ) { inputStream->set_already_visited( objectAddress ); } const MetaClass *mc = get_base_type()->get_meta_class( (Byte*)objectAddress ); mc->initialize( ObjectWrapper(*(Address*)address, mc), inputStream ); } if ( _post_init ) { _post_init( obj, true, inputStream ); } }
PointerWrapper::PointerWrapper(const ObjectWrapper &obj) : _meta_class(NULL), _address(0) { kernel_assert_message(is_pointer(obj), ("Attempt to pointer object with non-pointer")); _meta_class = to<PointerMetaClass>(obj.get_meta_class()); _address = obj.get_address(); }
Address UnionIterator::current() const { if (!_is_valid) return(0); AggregateWrapper agg_obj(_address, _metaClass); ObjectWrapper obj = _current_field_description->build_object(agg_obj); return(obj.get_address()); // return _is_valid ? (((Byte*) _address)+_current_field_description->offset) // : 0; }
bool GridClientObjectWrapperConvertor::wrapSimpleType(const GridClientVariant& var, ObjectWrapper& objWrapper) { objWrapper.set_type(NONE); GridClientVariantVisitorImpl visitor(objWrapper); objWrapper.set_binary((void*) NULL, 0); var.accept(visitor); return objWrapper.type() != NONE; }
/* bool SuifPrinterModule::print2(ostream& output, const ObjectWrapper &obj, const LString &name, int _indent, int deref) { return(print2(output, obj.get_address(), obj.get_meta_class(), name, _indent, deref)); } */ bool //SuifPrinterModule::print2(ostream& output, const Address what, const MetaClass* type, // //const LString &name = emptyLString, int _indent = 2, int deref = 0) // const LString &name, int _indent, int deref) SuifPrinterModule::print2(ostream& output, const ObjectWrapper &obj, const LString &name, int _indent, int deref) { if (!start_of_object(output,obj,deref)) { return false; } // MetaClassId id = type->get_meta_class_id(); String str = get_print_string(obj.get_meta_class()->get_instance_name()); // This is NOT always a suifobject. It is only // a suifobject if the metaclass is a child of the SuifObject metaclass. SuifObject *o = NULL; if (is_kind_of_suif_object_meta_class(obj.get_meta_class())) { o = (SuifObject *) obj.get_address(); } // length is at least 1 (for the \0 at the end) //output << "p2:deref = " << deref << endl; if (use_print_string() && str != emptyString) { bool b = parse_and_print(output, obj, name, str, _indent, deref); end_of_object(output,obj); return b; } // No print string registered. const MetaClass *type = obj.get_meta_class(); bool b = false; if (type->is_elementary()) { b = print_elementary(output, obj, name, _indent, deref); } else if (type->isKindOf(AggregateMetaClass::get_class_name())) { b = print_aggregate(output, AggregateWrapper(obj), name, _indent, deref); } else if (type->isKindOf(PointerMetaClass::get_class_name())) { b = print_pointer(output, PointerWrapper(obj), name, _indent, deref); } else if (type->isKindOf(ListMetaClass::get_class_name())) { b = print_list(output, obj, name, _indent, deref); } else if (type->isKindOf(STLMetaClass::get_class_name())) { b = print_stl(output, obj, name, _indent, deref); } else { b = print_catchall(output, obj, name, _indent, deref); } end_of_object(output,obj); return b; }
void CPrintStyleModule::print_dispatch(Module *module, ostream &str, const ObjectWrapper &obj) { CPrintStyleModule *pm = (CPrintStyleModule*)module; String result; if (is_kind_of_suif_object_meta_class(obj.get_meta_class())) { result = pm->print_to_string((const SuifObject*)obj.get_address()); } str << result.c_str(); }
Walker::ApplyStatus UnionMetaClass::walk(const Address instance,Walker &walk) const { AggregateWrapper agg_obj(instance, this); AggregateMetaClass::walk_fields(instance,walk); int index = get_tag_num( instance ); if ( index == -1 ) { return Walker::Continue; } FieldDescription* field_description = (*_union_fields)[ index ]; ObjectWrapper obj = field_description->build_object(agg_obj); return field_description->get_meta_class()->walk(obj.get_address(), walk); }
void* JavaScriptObject::getUserObject() { CefRefPtr<CefBase> data = m_pObject->GetUserData(); ObjectWrapper* ow = (ObjectWrapper*)data.get(); if (ow) return ow->getData(); return NULL; }
template<class T> void unwrapCollection(const ObjectWrapper& objWrapper, std::vector<T>& res) { assert(objWrapper.type() == COLLECTION); assert(objWrapper.has_binary()); res.clear(); ::Collection coll; unmarshalMsg(objWrapper.binary().c_str(), objWrapper.binary().size(), coll); unwrapCollection(coll, res); }
static bool doUnwrapSimpleType(const ObjectWrapper& objWrapper, GridClientVariant& var) { assert(objWrapper.has_binary()); GG_LOG_DEBUG("Unwrap simple type: %s", objWrapper.DebugString().c_str()); string binary = objWrapper.binary(); bool unwrapRes = false; switch (objWrapper.type()) { case NONE: return true; case BOOL: return getBoolValue(binary, var); case BYTE: return getByteValue(binary, var); case BYTES: return getBytesValue(binary, var); case INT32: return getInt32Value(binary, var); case INT64: return getInt64Value(binary, var); case SHORT: return getInt16Value(binary, var); case STRING: var.set(binary); return true; case DOUBLE: return getDoubleValue(binary, var); case FLOAT: return getFloatValue(binary, var); case TASK_BEAN: return getTaskTesult(binary, var); default: // Non-simple type break; } return unwrapRes; }
template<class K, class V> void unwrapMap(ObjectWrapper objWrapper, std::map<K, V>& res) { assert(objWrapper.type() == MAP); assert(objWrapper.has_binary()); res.clear(); ::Map map; unmarshalMsg((int8_t*) objWrapper.binary().c_str(), objWrapper.binary().size(), map); const ::google::protobuf::RepeatedPtrField< ::KeyValue >& repFileds = map.entry(); std::for_each(repFileds.begin(), repFileds.end(), MapInserter<K, V, ::KeyValue>(res)); }
size_t ObjectTags::retrieve_tag(const ObjectWrapper &obj) { TagMap::iterator iter = _tags->find(obj.get_address()); if (iter == _tags->end()) { // (*_tags)[obj.get_address()] = _next_tag; _tags->enter_value(obj.get_address(), _next_tag); _next_tag++; return(_next_tag-1); } else { return((*iter).second); } }
size_t ObjectTags::get_tag(const ObjectWrapper &obj) { TagMap::iterator iter = _tags->find(obj.get_address()); suif_assert_message(iter != _tags->end(), ("invalid tag retrieval")); return((*iter).second); }
void GridClientProtobufMarshaller::unwrap(const ObjectWrapper& objWrapper, GridClientMessageLogResult& logRslt) { ProtoResponse resp; GG_LOG_DEBUG("Unwrap: %s", objWrapper.DebugString().c_str()); unwrapResponse(objWrapper, resp); GG_LOG_DEBUG("Unwrap result: %s", resp.DebugString().c_str()); fillResponseHeader(resp, logRslt); std::vector<std::string> lines; if (resp.has_resultbean()) { assert(resp.resultbean().type() == COLLECTION); const std::string& binary = resp.resultbean().binary(); ::Collection coll; unmarshalMsg((int8_t*) binary.c_str(), binary.size(), coll); for (auto it = coll.item().begin(); it != coll.item().end(); ++it) { const ObjectWrapper& el = (*it); lines.push_back(el.binary()); } } logRslt.lines(lines); }
void STLMetaClass::destruct( const ObjectWrapper &obj, bool called_from_destructor ) const { kernel_assert(obj.get_meta_class() == this); // an stl object is never destroyed from the destructor kernel_assert( !called_from_destructor ); _stl_descriptor->get_destructor_function()( obj ); }
void PointerMetaClass::destruct( const ObjectWrapper &obj, bool called_from_destructor ) const { Address address = obj.get_address(); kernel_assert(obj.get_meta_class() == this); // is never called from a destructor kernel_assert( !called_from_destructor ); if ( _pointer_owns_object ) { Address object_address = *(Address*)address; if ( object_address ) { const MetaClass *mc = _base_type -> get_meta_class( object_address ); mc-> destruct( ObjectWrapper(object_address, mc), false ); delete (char*)object_address; *(Address*)address = 0; // just to be nice } } }
//---------------------------------------------------------------------------- //---------------------------------------------------------------------------- bool SuifPrinterModule::print_catchall(ostream& output, const ObjectWrapper &obj, const LString &name, int _indent,int deref = 0) { const Address what = obj.get_address(); const MetaClass* type = obj.get_meta_class(); int field_deref = deref?deref-1:0; output << type->get_instance_name() << '(' << type->get_meta_class_id() << ") "; if (name) output << ' ' << name << ' '; output << " (un-implemented) "; Iterator* it = type->get_iterator(what); if (it) { if (it->current()) { //output << "{\n"; output << endl; //while (it->is_valid()) { for (; it->is_valid(); it->next()) { ObjectWrapper obj(it->current(), it->current_meta_class()); // const MetaClass* currentMetaClass = it->current_meta_class(); // const Address curAddr = it->current(); if(!obj.is_null()) { // if (curAddr) { indent(output, _indent+istep); print2(output, obj, it->current_name(), _indent+istep, field_deref); } // it->next(); //} }// while (it->is_valid()); indent(output, _indent); //output << "}\n"; } else output <<" {0x0}\n"; } if (it) delete it; return true; }
void GridClientProtobufMarshaller::unwrap(const ObjectWrapper& objWrapper, GridClientMessageAuthenticationResult& authRslt) { ProtoResponse resp; GG_LOG_DEBUG("Unwrap: %s", objWrapper.DebugString().c_str()); unwrapResponse(objWrapper, resp); GG_LOG_DEBUG("Unwrap result: %s", resp.DebugString().c_str()); fillResponseHeader(resp, authRslt); }
void UnionMetaClass::initialize( const ObjectWrapper &obj, InputStream* inputStream ) const { Address address = obj.get_address(); kernel_assert(obj.get_meta_class() == this); // debugit("initializing union ",address); AggregateWrapper agg_obj(address, this); AggregateMetaClass::initialize( obj, inputStream ); int index = get_tag_num( address ); if (index < 0) zero_field(address); else { FieldDescription* field_description = (*_union_fields)[ index ]; ObjectWrapper field = field_description->build_object(agg_obj); //Address instance_address = (Address)( ( (Byte*)address ) + field_description->offset ); field.initialize(inputStream); // field_description->get_meta_class()->initialize( field.get_address() ,inputStream ); } }
void PointerMetaClass::read( const ObjectWrapper &obj, InputStream* inputStream ) const { Address instance = obj.get_address(); kernel_assert(obj.get_meta_class() == this); PointerWrapper ptr_obj(instance, this); if (_needs_cloning) { inputStream->read_defining_pointer( ptr_obj ); } else if ( _pointer_owns_object ) { if ( _is_static ) { inputStream->read_static_pointer( ptr_obj ); } else { inputStream->read_owning_pointer( ptr_obj ); } } else { inputStream->read_reference( ptr_obj ); } }
void UnionMetaClass::write( const ObjectWrapper &obj, OutputStream* outputStream ) const { Address instance = obj.get_address(); kernel_assert(obj.get_meta_class() == this); AggregateWrapper agg_obj(instance, this); AggregateMetaClass::write( obj, outputStream ); int index = get_tag_num( instance ); // if the tag number is not stored in a field that was already // written out => write out the tag number if ( _tag_offset == -1 ) { outputStream->write_unsigned_int( index ); } if ( index >= 0 ) { FieldDescription* field_description = (*_union_fields)[ index ]; ObjectWrapper field = field_description->build_object(agg_obj); outputStream->write( field, false ); } }
void UnionMetaClass::read( const ObjectWrapper &obj, InputStream* inputStream ) const { Address instance = obj.get_address(); kernel_assert(obj.get_meta_class() == this); AggregateWrapper agg_obj(instance, this); AggregateMetaClass::read( obj, inputStream ); int index; if ( _tag_offset != -1 ) { index = *(int *) ((Byte*)instance + _tag_offset); } else { index = inputStream->read_unsigned_int(); } if ( index >= 0 ) { FieldDescription* field_description = (*_union_fields)[ index ]; ObjectWrapper field = field_description->build_object(agg_obj); inputStream->read( field, false ); } else { // works for now as only Union is a Union of pointers zero_field(instance); } }
void OutputStream::writeSchema( std::ostream& fout ) { // Write to external ascii stream const ObjectWrapperManager::WrapperMap& wrappers = Registry::instance()->getObjectWrapperManager()->getWrapperMap(); for ( ObjectWrapperManager::WrapperMap::const_iterator itr=wrappers.begin(); itr!=wrappers.end(); ++itr ) { ObjectWrapper* wrapper = itr->second.get(); fout << itr->first << " ="; StringList properties; wrapper->writeSchema( properties ); if ( properties.size()>0 ) { for ( StringList::iterator sitr=properties.begin(); sitr!=properties.end(); ++sitr ) { fout << ' ' << *sitr; } } fout << std::endl; } }
Address Object::get_member( const LString& name, Address& return_address, const MetaClass*& return_meta_class ) const { kernel_assert_message( _meta_class, ("Empty MetaClass") ); FieldDescription* field_description = _meta_class->get_field_description( (void*)address, name ); if ( field_description ) { // return_address = ((const Object *)this) + field_description->offset; AggregateWrapper agg_obj((Address)this, _meta_class); ObjectWrapper obj = field_description->build_object(agg_obj); obj = obj.update_meta_class(); return_address = obj.get_address(); return_meta_class = obj.get_meta_class(); //return_address = ((Byte*)this) + field_description->offset; // return_meta_class = field_description-> // metaClass->get_meta_class( return_address ); } else { return_address = 0; return_meta_class = 0; } return return_address; }
void OutputStream::writeSchema( std::ostream& fout ) { // Write to external ascii stream const ObjectWrapperManager::WrapperMap& wrappers = Registry::instance()->getObjectWrapperManager()->getWrapperMap(); for ( ObjectWrapperManager::WrapperMap::const_iterator itr=wrappers.begin(); itr!=wrappers.end(); ++itr ) { ObjectWrapper* wrapper = itr->second.get(); fout << itr->first << " ="; StringList properties; std::vector<int> types; wrapper->writeSchema( properties, types ); std::string propertiesString; unsigned int size = osg::minimum( properties.size(), types.size() ); for ( unsigned int i=0; i<size; ++i ) { fout << " " << properties[i] << ":" << types[i]; } fout << std::endl; } }
//---------------------------------------------------------------------------- //---------------------------------------------------------------------------- bool SuifPrinterModule::print_elementary(ostream& output, const ObjectWrapper &obj, const LString &name, int _indent,int deref = 0) { const Address what = obj.get_address(); const MetaClass* type = obj.get_meta_class(); //output << "elem:deref = " << deref << endl; if (!deref) { output << type->get_instance_name() << '(' << type->get_meta_class_id() << ')'; if (name) output << ' ' << name << ' '; } if (what) { if (type->isKindOf("String")) output <<'[' << *(String*)what <<"] "; else output <<'[' << *(int*)what <<"] "; } return true; }
static void wrapRequest(const GridClientMessageCommand& cmd, const ObjectWrapperType& type, const ::google::protobuf::Message& src, ObjectWrapper& objWrapper) { GG_LOG_DEBUG("Wrapping request: %s", src.DebugString().c_str()); ProtoRequest req; fillRequestHeader(cmd, req); objWrapper.set_type(type); int8_t * pBuffer; unsigned long bufferLength; GridClientProtobufMarshaller::marshalMsg(src, pBuffer, bufferLength); req.set_body(pBuffer, bufferLength); delete[] pBuffer; GridClientProtobufMarshaller::marshalMsg(req, pBuffer, bufferLength); objWrapper.set_binary(pBuffer, bufferLength); delete[] pBuffer; }
void OutputStream::writeObjectFields( const osg::Object* obj ) { std::string name = obj->libraryName(); name += std::string("::") + obj->className(); ObjectWrapper* wrapper = Registry::instance()->getObjectWrapperManager()->findWrapper( name ); if ( !wrapper ) { OSG_INFO << "OutputStream::writeObject(): Unsupported wrapper class " << name << std::endl; return; } _fields.push_back( name ); const StringList& associates = wrapper->getAssociates(); for ( StringList::const_iterator itr=associates.begin(); itr!=associates.end(); ++itr ) { const std::string& assocName = *itr; ObjectWrapper* assocWrapper = Registry::instance()->getObjectWrapperManager()->findWrapper(assocName); if ( !assocWrapper ) { OSG_INFO << "OutputStream::writeObject(): Unsupported associated class " << assocName << std::endl; continue; } else if ( _useSchemaData ) { if ( _inbuiltSchemaMap.find(assocName)==_inbuiltSchemaMap.end() ) { StringList properties; std::vector<int> types; assocWrapper->writeSchema( properties, types ); unsigned int size = osg::minimum( properties.size(), types.size() ); if ( size>0 ) { std::stringstream propertiesStream; for ( unsigned int i=0; i<size; ++i ) { propertiesStream << properties[i] << ":" << types[i] << " "; } _inbuiltSchemaMap[assocName] = propertiesStream.str(); } } } _fields.push_back( assocWrapper->getName() ); assocWrapper->write( *this, *obj ); if ( getException() ) return; _fields.pop_back(); } _fields.pop_back(); }
void OutputStream::writeObjectFields( const osg::Object* obj ) { std::string name = obj->libraryName(); name += std::string("::") + obj->className(); ObjectWrapper* wrapper = Registry::instance()->getObjectWrapperManager()->findWrapper( name ); if ( !wrapper ) { OSG_WARN << "OutputStream::writeObject(): Unsupported wrapper class " << name << std::endl; return; } _fields.push_back( name ); const StringList& associates = wrapper->getAssociates(); for ( StringList::const_iterator itr=associates.begin(); itr!=associates.end(); ++itr ) { const std::string& assocName = *itr; ObjectWrapper* assocWrapper = Registry::instance()->getObjectWrapperManager()->findWrapper(assocName); if ( !assocWrapper ) { OSG_WARN << "OutputStream::writeObject(): Unsupported associated class " << assocName << std::endl; continue; } else if ( _useSchemaData ) { if ( _inbuiltSchemaMap.find(assocName)==_inbuiltSchemaMap.end() ) { StringList properties; assocWrapper->writeSchema( properties ); if ( properties.size()>0 ) { std::string propertiesString; for ( StringList::iterator sitr=properties.begin(); sitr!=properties.end(); ++sitr ) { propertiesString += *sitr; propertiesString += ' '; } _inbuiltSchemaMap[assocName] = propertiesString; } } } _fields.push_back( assocWrapper->getName() ); assocWrapper->write( *this, *obj ); if ( getException() ) return; _fields.pop_back(); } _fields.pop_back(); }
//ModifyObject will do all the work in a full modifier //This includes casting objects to their correct form, doing modifications //changing their parameters, etc void ProjectionHolderUVW::ModifyObject(TimeValue t, ModContext &mc, ObjectState * os, INode *node) { ObjectWrapper object; object.Init(t,*os,false, ObjectWrapper::allEnable, ObjectWrapper::triObject); if( object.IsEmpty() ) return; // Check topology if( object.NumFaces() != mData.mFaces.Count() ) return; for( int i=0; i<object.NumFaces(); i++ ) { GenFace face = object.GetFace(i); if( face.numVerts != mData.mFaces[i].numVerts ) return; } if( mData.miMapChannel != VERTEX_CHANNEL_NUM ) { // Check Channel Support if( !object.GetChannelSupport(mData.miMapChannel) ) object.SetChannelSupport( mData.miMapChannel, true ); object.SetNumMapVerts( mData.miMapChannel, mData.mP3Data.Count() ); for( int i=0; i<mData.mP3Data.Count(); i++ ) object.SetMapVert( mData.miMapChannel, i, mData.mP3Data[i] ); for( int i=0; i<mData.mFaces.Count(); i++ ) { object.SetMapFace( mData.miMapChannel, i, mData.mFaces[i] ); // Material ID Support if( mData.mDoMaterialIDs ) object.SetMtlID(i, mData.mMatID[i] ); } os->obj->PointsWereChanged(); } else { object.SetNumVerts( mData.mP3Data.Count() ); for( int i=0; i<mData.mP3Data.Count(); i++ ) object.SetVert( i, mData.mP3Data[i] ); for( int i=0; i<mData.mFaces.Count(); i++ ) { object.SetFace( i, mData.mFaces[i] ); // Material ID Support if( mData.mDoMaterialIDs ) object.SetMtlID(i, mData.mMatID[i] ); } os->obj->PointsWereChanged(); if( object.Type() == ObjectWrapper::polyObject ) { MNMesh *poly = object.GetPolyMesh(); if( poly ) poly->FillInMesh(); } else if( object.Type() == ObjectWrapper::triObject ) { Mesh *mesh = object.GetTriMesh(); if( mesh ) mesh->InvalidateTopologyCache(); } } Interval iv; iv = FOREVER; iv &= mData.mSrcInterval; if( mData.miMapChannel > 0 ) iv &= os->obj->ChannelValidity (t, TEXMAP_CHAN_NUM); else if( mData.miMapChannel == VERTEX_CHANNEL_NUM ) { iv &= os->obj->ChannelValidity(t,GEOM_CHAN_NUM); iv &= os->obj->ChannelValidity(t,TOPO_CHAN_NUM); } else iv &= os->obj->ChannelValidity(t,VERT_COLOR_CHAN_NUM); if( mData.miMapChannel > 0 ) os->obj->UpdateValidity(TEXMAP_CHAN_NUM,iv); else if( mData.miMapChannel == VERTEX_CHANNEL_NUM ) { os->obj->UpdateValidity(GEOM_CHAN_NUM,iv); os->obj->UpdateValidity(TOPO_CHAN_NUM,iv); } else os->obj->UpdateValidity(VERT_COLOR_CHAN_NUM,iv); }