void CommandLineTestBase::testWriteHelp(ICommandLineModule *module) { StringOutputStream stream; CommandLineHelpContext context(&stream, eHelpOutputFormat_Console, nullptr, "test"); context.setModuleDisplayName(formatString("%s %s", "test", module->name())); module->writeHelp(context); TestReferenceChecker checker(rootChecker()); checker.checkTextBlock(stream.toString(), "HelpOutput"); }
void testWrite() { report(0,"testing writing..."); StringOutputStream sos; char txt[] = "Hello my friend"; Bytes b(txt,ACE_OS::strlen(txt)); sos.write(b); checkEqual(txt,sos.toString(),"single write"); StringOutputStream sos2; sos2.write('y'); sos2.write('o'); checkEqual("yo",sos2.toString(),"multiple writes"); }
void Selection_SnapToGrid (void) { StringOutputStream command; command << "snapSelected -grid " << GlobalGrid().getGridSize(); UndoableCommand undo(command.toString()); if (GlobalSelectionSystem().Mode() == SelectionSystem::eComponent) { GlobalSceneGraph().traverse(ComponentSnappableSnapToGridSelected(GlobalGrid().getGridSize())); } else { GlobalSceneGraph().traverse(SnappableSnapToGridSelected(GlobalGrid().getGridSize())); } }
std::string MaterialSystem::getBlock (const std::string& texture) { if (texture.empty()) return ""; const std::string textureDir = GlobalTexturePrefix_get(); std::string skippedTextureDirectory = texture.substr(textureDir.length()); if (skippedTextureDirectory.empty()) return ""; MaterialBlockMap::iterator i = _blocks.find(skippedTextureDirectory); if (i != _blocks.end()) return i->second; if (!_materialLoaded) loadMaterials(); if (!_materialLoaded) return ""; StringOutputStream outputStream; StringInputStream inputStream(_material); AutoPtr<Tokeniser> tokeniser(GlobalScriptLibrary().createSimpleTokeniser(inputStream)); int depth = 0; bool found = false; std::string token = tokeniser->getToken(); while (token.length()) { if (token == "{") { depth++; } else if (token == "}") { depth--; } if (depth >= 1) { if (depth == 1 && token == "material") { token = tokeniser->getToken(); if (token == skippedTextureDirectory) { found = true; outputStream << "{ material "; } } if (found) outputStream << token << " "; } else if (found) { outputStream << "}"; break; } token = tokeniser->getToken(); } return outputStream.toString(); }
// End the move, this freezes the current transforms void RadiantSelectionSystem::endMove() { freezeTransforms(); // greebo: Deselect all faces if we are in brush and drag mode if (Mode() == ePrimitive) { if (ManipulatorMode() == eDrag) { GlobalSceneGraph().traverse(SelectAllComponentWalker(false, SelectionSystem::eFace)); //Scene_SelectAll_Component(false, SelectionSystem::eFace); } } // Remove all degenerated brushes from the scene graph (should emit a warning) GlobalSceneGraph().traverse(RemoveDegenerateBrushWalker()); _pivotMoving = false; pivotChanged(); // Update the views SceneChangeNotify(); // If we started an undoable operation, end it now and tell the console what happened if (_undoBegun) { StringOutputStream command; if (ManipulatorMode() == eTranslate) { command << "translateTool"; outputTranslation(command); } else if (ManipulatorMode() == eRotate) { command << "rotateTool"; outputRotation(command); } else if (ManipulatorMode() == eScale) { command << "scaleTool"; outputScale(command); } else if (ManipulatorMode() == eDrag) { command << "dragTool"; } // Finish the undo move GlobalUndoSystem().finish(command.toString()); } }
bool WireTwiddler::write(yarp::os::Bottle& bot, yarp::os::ManagedBytes& data) { StringOutputStream sos; if (!writer) { writer = ConnectionWriter::createBufferedConnectionWriter(); } if (!writer) { return false; } SizedWriter *buf = writer->getBuffer(); if (!buf) { return false; } buf->clear(); bot.write(*writer); WireTwiddlerWriter twiddled_output(*buf,*this); twiddled_output.write(sos); std::string result = sos.toString(); data = ManagedBytes(Bytes((char*)result.c_str(),result.length()),false); data.copy(); return true; }
bool XmlRpcCarrier::write(Protocol& proto, SizedWriter& writer) { //XmlRpc::setVerbosity(10); StringOutputStream sos; StringInputStream sis; writer.write(sos); sis.reset(sos.toString()); String header; if (sender) { header = NetType::readLine(sis); } String body = NetType::readLine(sis); //printf("Asked to write: hdr %s body %s\n", // header.c_str(), body.c_str()); Value v; //printf("HEADER %s\n", header.c_str()); if (header[0]=='q') { body = "yarp.quit"; // XMLRPC does not need a quit message, this should get stripped return false; } Bottle *bot = v.asList(); //Bottle aux; bot->fromString(body.c_str()); ConstString methodName; if (sender) { methodName = bot->get(0).toString(); *bot = bot->tail(); } XmlRpcValue args; if (bot->size()==1) { toXmlRpcValue(bot->get(0),args); } else { toXmlRpcValue(v,args); } //printf("xmlrpc block to write is %s\n", args.toXml().c_str()); std::string req; if (sender) { const Address& addr = host.isValid()?host:proto.getStreams().getRemoteAddress(); XmlRpcClient c(addr.getName().c_str(),(addr.getPort()>0)?addr.getPort():80); c.generateRequest(methodName.c_str(),args); req = c.getRequest(); } else { XmlRpcServerConnection c(0,NULL); c.generateResponse(args.toXml()); req = c.getResponse(); } int start = 0; //printf("converts to %s\n", req.c_str()); if (sender) { if (req.length()<8) { fprintf(stderr, "XmlRpcCarrier fail, %s:%d\n", __FILE__, __LINE__); return false; } for (int i=0; i<(int)req.length(); i++) { if (req[i] == '\n') { start++; break; } start++; } if (!firstRound) { Bytes b((char*)http.c_str(),http.length()); proto.os().write(b); } firstRound = false; } Bytes b((char*)req.c_str()+start,req.length()-start); //printf("WRITING [%s]\n", req.c_str()+start); proto.os().write(b); return proto.os().isOk(); }
bool XmlRpcCarrier::write(ConnectionState& proto, SizedWriter& writer) { StringOutputStream sos; StringInputStream sis; writer.write(sos); sis.reset(sos.toString()); ConstString header; if (sender) { header = sis.readLine(); } ConstString body = sis.readLine(); Value v; if (header.length()>0 && header[0]=='q') { body = "yarp.quit"; // XMLRPC does not need a quit message, this should get stripped return false; } Bottle *bot = v.asList(); bot->fromString(body.c_str()); ConstString methodName; if (sender) { methodName = bot->get(0).toString(); *bot = bot->tail(); } XmlRpcValue args; if (bot->size()==1) { toXmlRpcValue(bot->get(0),args); } else { toXmlRpcValue(v,args); } std::string req; if (sender) { const Contact& addr = host.isValid()?host:proto.getStreams().getRemoteAddress(); XmlRpcClient c(addr.getHost().c_str(),(addr.getPort()>0)?addr.getPort():80); c.generateRequest(methodName.c_str(),args); req = c.getRequest(); } else { XmlRpcServerConnection c(0,NULL); c.generateResponse(args.toXml()); req = c.getResponse(); } int start = 0; if (sender) { if (req.length()<8) { fprintf(stderr, "XmlRpcCarrier fail, %s:%d\n", __FILE__, __LINE__); return false; } for (int i=0; i<(int)req.length(); i++) { if (req[i] == '\n') { start++; break; } start++; } if (!firstRound) { Bytes b((char*)http.c_str(),http.length()); proto.os().write(b); } firstRound = false; } Bytes b((char*)req.c_str()+start,req.length()-start); proto.os().write(b); return proto.os().isOk(); }