virtual WriteResult writeObject(const osg::Object& object,const std::string& fileName, const osgDB::ReaderWriter::Options* options) const { std::string ext = osgDB::getFileExtension(fileName); if (!acceptsExtension(ext)) return WriteResult::FILE_NOT_HANDLED; osgDB::ofstream fout(fileName.c_str()); if(!fout) return WriteResult::ERROR_IN_WRITING_FILE; return writeObject(object, fout, options); }
//--------------------------------------------------------------------- void SkeletonSerializer::writeKeyFrame(const Skeleton* pSkel, const TransformKeyFrame* key) { writeChunkHeader(SKELETON_ANIMATION_TRACK_KEYFRAME, calcKeyFrameSize(pSkel, key)); // float time : The time position (seconds) float time = key->getTime(); writeFloats(&time, 1); // Quaternion rotate : Rotation to apply at this keyframe writeObject(key->getRotation()); // Vector3 translate : Translation to apply at this keyframe writeObject(key->getTranslate()); // Vector3 scale : Scale to apply at this keyframe if (key->getScale() != Vector3::UNIT_SCALE) { writeObject(key->getScale()); } }
//--------------------------------------------------------------------- void SkeletonSerializer::writeBone(const Skeleton* pSkel, const Bone* pBone) { writeChunkHeader(SKELETON_BONE, calcBoneSize(pSkel, pBone)); unsigned short handle = pBone->getHandle(); // char* name writeString(pBone->getName()); // unsigned short handle : handle of the bone, should be contiguous & start at 0 writeShorts(&handle, 1); // Vector3 position : position of this bone relative to parent writeObject(pBone->getPosition()); // Quaternion orientation : orientation of this bone relative to parent writeObject(pBone->getOrientation()); // Vector3 scale : scale of this bone relative to parent if (pBone->getScale() != Vector3::UNIT_SCALE) { writeObject(pBone->getScale()); } }
void writeDatabase(ObjectDB *odb, const char *dbname) { FILE *f=fopen(dbname, "w"); int i; if (f == NULL) { fprintf(stderr, "unable to write database\n"); return; } for (i=0; i < odb->nObjects; ++i) writeObject(f, &odb->objs[i]); fclose(f); }
void FltExportVisitor::apply( osg::Group& node ) { ScopedStatePushPop guard( this, node.getStateSet() ); if (_firstNode) { // On input, a FLT header creates a Group node. // On export, we always write a Header record, but then the first Node // we export is the Group that was created from the original input Header. // On successive roundtrips, this results in increased redundant top-level Group nodes/records. // Avoid this by NOT outputting anything for a top-level Group node. _firstNode = false; traverse( node ); return; } // A Group node could indicate one of many possible records. // Header record -- Don't need to support this here. We always output a header. // Group record -- HIGH // Child of an LOD node -- HIGH Currently write out a Group record regardless. // InstanceDefinition/InstanceReference -- MED -- multiparented Group is an instance // Extension record -- MED // Object record -- MED // LightPointSystem record (if psgSim::MultiSwitch) -- LOW osgSim::MultiSwitch* multiSwitch = dynamic_cast<osgSim::MultiSwitch*>( &node ); if (multiSwitch) { writeSwitch( multiSwitch ); } else { osgSim::ObjectRecordData* ord = dynamic_cast< osgSim::ObjectRecordData* >( node.getUserData() ); if (ord) { // This Group should write an Object Record. writeObject( node, ord ); } else { // Handle other cases here. // For now, just output a Group record. writeGroup( node ); } } writeMatrix( node.getUserData() ); writeComment( node ); writePushTraverseWritePop( node ); }
//--------------------------------------------------------------------- void SkeletonSerializer::writeBone(const Skeleton* pSkel, const Bone* pBone) { writeChunkHeader(SKELETON_BONE, calcBoneSize(pSkel, pBone)); unsigned short handle = pBone->getHandle(); // char* name writeString(pBone->getName()); #if OGRE_SERIALIZER_VALIDATE_CHUNKSIZE // Hack to fix chunk size validation: mChunkSizeStack.back() += calcStringSize(pBone->getName()); #endif // unsigned short handle : handle of the bone, should be contiguous & start at 0 writeShorts(&handle, 1); // Vector3 position : position of this bone relative to parent writeObject(pBone->getPosition()); // Quaternion orientation : orientation of this bone relative to parent writeObject(pBone->getOrientation()); // Vector3 scale : scale of this bone relative to parent if (pBone->getScale() != Vector3::UNIT_SCALE) { writeObject(pBone->getScale()); } }
//------------------------------------------------------------------------------ void IFile::saveAs(const char *fileName) throw (std::ios_base::failure) { std::ofstream file; file.open(fileName, std::ofstream::binary); if (file.fail()) { file.close(); throw std::ios_base::failure("Cant write to file: \"" + std::string(fileName) + "\""); } else writeObject(file); file.close(); }
/** * @brief Writes the specified JSON element to `writer`. * @param writer The JSONWriter. * @param obj The JSON element to write. */ static void writeElement(JSONWriter *writer, const ident obj) { const Object *object = cast(Object, obj); if (object) { if ($(object, isKindOfClass, _Dictionary())) { writeObject(writer, (Dictionary *) object); } else if ($(object, isKindOfClass, _Array())) { writeArray(writer, (Array *) object); } else if ($(object, isKindOfClass, _String())) { writeString(writer, (String *) object); } else if ($(object, isKindOfClass, _Number())) { writeNumber(writer, (Number *) object); } else if ($(object, isKindOfClass, _Boole())) { writeBoole(writer, (Boole *) object); } else if ($(object, isKindOfClass, _Null())) { writeNull(writer, (Null *) object); } } }
void Save::writePlanet(Planet* mPlanet, int i) { writeObject("planet" + to_string(i), mPlanet); writeLine("planet" + to_string(i) + "-circleTrajectory", to_string(mPlanet->isCircletrajectory())); writeLine("planet" + to_string(i) + "-orbitRadius", to_string(mPlanet->getOrbitRadius())); writeLine("planet" + to_string(i) + "-timer", to_string(mPlanet->getTimer())); writeLine("planet" + to_string(i) + "-shootingFrequency", to_string(mPlanet->getShootingFrequency())); for (vector<Bullet*>::iterator it = mPlanet->getBullets().begin(); it != mPlanet->getBullets().end(); ++it) { // So far a bullet does not have any additional properties compared to an Object writeBullet("planet" + to_string(i) + "-bullet" + to_string(it - mPlanet->getBullets().begin()), *it); } for (vector<Satellite*>::iterator it = mPlanet->getSatellites().begin(); it != mPlanet->getSatellites().end(); ++it) { // it - mPlanet->getSatellites().begin() // equals the serial id of the satellite writeSatellite("planet" + to_string(i) + "-satellite" + to_string(it - mPlanet->getSatellites().begin()), *it); } }
osgDB::ReaderWriter::WriteResult ReaderWriterCURLEX::writeObject(const osg::Object& object, const std::string& fileName, const osgDB::ReaderWriter::Options* options) const { std::string ext = osgDB::getFileExtension(fileName); if (options != NULL && acceptsExtension(options->getPluginStringData("VIRTUALDATASCENE_DEFINE_PLUGIN")) && acceptsExtension(ext)) { const VirtualDataSceneBase::StreamObject* curlexObject = dynamic_cast<const VirtualDataSceneBase::StreamObject*>(&object); if (curlexObject) { std::string sFileName = fileName; #if _WIN32 tryConvertStringFromUTF8ToGB2312(fileName, sFileName); #endif std::ofstream out(sFileName.c_str(), std::ios::binary | std::ios::out); return writeObject(object, out, options); } } return osgDB::ReaderWriter::WriteResult::FILE_NOT_HANDLED; }
void Writer::write(Appender& appender, const Value& value, Size indent) { switch (value.getType()) { case Value::Type::Null: writeNull(appender); break; case Value::Type::Boolean: writeBoolean(appender, value.asBoolean()); break; case Value::Type::Number: writeNumber(appender, value.asDouble()); break; case Value::Type::String: writeString(appender, value.asString()); break; case Value::Type::Array: writeArray(appender, value, indent); break; case Value::Type::Object: writeObject(appender, value, indent); break; } }
void check(refChar message, refObject object) { if (maxDebugLevel >= 0) { fprintf(stream(debug), "[%i] %s\n", level, message); writeObject(debug, object); getc(stdin); }}
void Save::writeSatellite(string name, Satellite* mSatellite) { writeObject(name, mSatellite); writeLine(name + "-orbitRadius", to_string(mSatellite->getOrbitRadius())); }
void Save::writeBullet(string name, Bullet* mBullet) { writeObject(name, mBullet); writeLine(name + "-speedXY", to_string(mBullet->getSpeedXY())); }
Packet* ManagedObjectAdapter::invokeMethod(uint32 methid, DistributedMethod* inv) { Packet* resp = new MethodReturnMessage(0); switch (methid) { case 6: lock(inv->getBooleanParameter()); break; case 7: lock((ManagedObject*) inv->getObjectParameter()); break; case 8: rlock(inv->getBooleanParameter()); break; case 9: wlock(inv->getBooleanParameter()); break; case 10: wlock((ManagedObject*) inv->getObjectParameter()); break; case 11: unlock(inv->getBooleanParameter()); break; case 12: runlock(inv->getBooleanParameter()); break; case 13: setLockName(inv->getAsciiParameter(_param0_setLockName__String_)); break; case 14: resp->insertBoolean(notifyDestroy()); break; case 15: writeObject(inv->getAsciiParameter(_param0_writeObject__String_)); break; case 16: readObject(inv->getAsciiParameter(_param0_readObject__String_)); break; case 17: initializeTransientMembers(); break; case 18: updateToDatabase(); break; case 19: queueUpdateToDatabaseTask(); break; case 20: clearUpdateToDatabaseTask(); break; case 21: resp->insertInt(getLastCRCSave()); break; case 22: setLastCRCSave(inv->getUnsignedIntParameter()); break; case 23: resp->insertBoolean(isPersistent()); break; case 24: resp->insertSignedInt(getPersistenceLevel()); break; case 25: setPersistent(inv->getSignedIntParameter()); break; default: return NULL; } return resp; }
bool XSAppBuilder::packProject() { if(projectPath.isEmpty()) { return false; } bool ret = false; QDir dir(projectPath); QFileInfoList infoList = dir.entryInfoList(); for(int i = 0; i < infoList.size(); i++) { if(infoList.at(i).isDir()) { QDir jsDir = QDir(infoList.at(i).absoluteFilePath()); QFileInfoList jsInforList = jsDir.entryInfoList(); if(jsDir.dirName() == "scripts") { for(int j = 0; j < jsInforList.size(); j++) { if(jsInforList.at(j).suffix() == "js") { QString prefix = jsDir.dirName() + "_"; ret = compileScript(jsInforList.at(j), prefix); break; } } } continue; } if(infoList.at(i).suffix() == "xpk") { continue; } else if(infoList.at(i).suffix() == "xml" || infoList.at(i).suffix() == "json") { ret = compileObject(infoList.at(i)); } else if(infoList.at(i).suffix() == "js") { ret = compileScript(infoList.at(i), ""); } else { ret = compileBinary(infoList.at(i)); } if(ret == false) { return ret; } } ret = writeObject(); return ret; }
JGatewayOutputStream::JGatewayOutputStream(JOutputStream* out,JRoute* route):JObjectOutputStream(out){ this->route=route; writeObject(route); flush(); }
/** * @fn Data *JSONSerialization::dataFromObject(const ident obj, int options) * @memberof JSONSerialization */ static Data *dataFromObject(const ident obj, int options) { if (obj) { JSONWriter writer = { .data = $(alloc(MutableData), init), .options = options }; writeObject(&writer, obj); return (Data *) writer.data; } return NULL; } /** * @brief A reader for parsing JSON Data. */ typedef struct { const Data *data; int options; uint8_t *b; } JSONReader; static ident readElement(JSONReader *reader); /** * @param reader The JSONReader. * @return The next byte in `reader`, or `-1` if `reader` is exhausted. */ static int readByte(JSONReader *reader) { if (reader->b) { if (reader->b - reader->data->bytes < reader->data->length) { return (int) *(++(reader->b)); } } else { if (reader->data->bytes) { return (int) *(reader->b = reader->data->bytes); } } return -1; } /** * @brief Consume bytes from `reader` until a byte from `stop` is found. * @param reader The JSONReader. * @param stop A sequence of stop characters. * @return The `stop` byte found, or `-1` if `reader` is exhausted. */ static int readByteUntil(JSONReader *reader, const char *stop) { int b; while (true) { b = readByte(reader); if (b == -1 || strchr(stop, b)) { break; } } return b; }
int main(int argc, const char** argv) { if (argc < 7 or argc > 10) { usageAndExit(argv[0]); } unsigned alignment = 1; if (argc > 7) { alignment = atoi(argv[7]); } bool writable = false; bool executable = false; for (int i = 8; i < argc; ++i) { if (strcmp("writable", argv[i]) == 0) { writable = true; } else if (strcmp("executable", argv[i]) == 0) { executable = true; } else { usageAndExit(argv[0]); } } uint8_t* data = 0; unsigned size; int fd = open(argv[1], O_RDONLY); if (fd != -1) { struct stat s; int r = fstat(fd, &s); if (r != -1) { #ifdef WIN32 HANDLE fm; HANDLE h = (HANDLE) _get_osfhandle (fd); fm = CreateFileMapping( h, NULL, PAGE_READONLY, 0, 0, NULL); data = static_cast<uint8_t*>(MapViewOfFile( fm, FILE_MAP_READ, 0, 0, s.st_size)); CloseHandle(fm); #else data = static_cast<uint8_t*> (mmap(0, s.st_size, PROT_READ, MAP_PRIVATE, fd, 0)); #endif size = s.st_size; } close(fd); } bool success = false; if (data) { FileOutputStream out(argv[2]); if (out.isValid()) { success = writeObject (data, size, &out, argv[3], argv[4], argv[5], argv[6], alignment, writable, executable); } else { fprintf(stderr, "unable to open %s\n", argv[2]); } #ifdef WIN32 UnmapViewOfFile(data); #else munmap(data, size); #endif } else { perror(argv[0]); } return (success ? 0 : -1); }