本文整理汇总了C++中JSONNode::ToString方法的典型用法代码示例。如果您正苦于以下问题:C++ JSONNode::ToString方法的具体用法?C++ JSONNode::ToString怎么用?C++ JSONNode::ToString使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类JSONNode
的用法示例。
在下文中一共展示了JSONNode::ToString方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: AddNewClient
void SharedDaemon::AddNewClient(const std::string &host, const stringVector &args, void *cbdata)
{
/// Send appropriate message for TCP or WebConnection
void** data = (void**)cbdata;
ConnectionType typeOfConnection = *((ConnectionType*)(data[0]));
QAbstractSocket* socket = static_cast<QAbstractSocket*>(data[1]);
ViewerState* viewerState = static_cast<ViewerState*>(data[2]);
JSONNode node;
QString hostname = typeOfConnection == TcpConnection ? socket->localAddress().toString():
dynamic_cast<QWsSocket*>(socket)->internalSocket()->localAddress().toString();
if(hostMap.contains(hostname)) hostname = hostMap[hostname];
node["host"] = hostname.toStdString(); //host
node["port"] = args[7]; //port
node["version"] = args[2]; //version
node["securityKey"] = args[9]; //key
node["numStates"] = viewerState->GetNumStateObjects(); //number of states
JSONNode::JSONArray rpc_array = JSONNode::JSONArray();
for(size_t i = 0; i < ViewerRPC::MaxRPC; ++i) {
rpc_array.push_back(ViewerRPC::ViewerRPCType_ToString((ViewerRPC::ViewerRPCType)i));
}
node["rpc_array"] = rpc_array;
if(typeOfConnection == TcpConnection)
{
QTcpSocket *tsocket = dynamic_cast<QTcpSocket*>(socket);
std::string message = node.ToString();
tsocket->write(message.c_str(),message.length());
if(tsocket->state() != QAbstractSocket::UnconnectedState)
tsocket->waitForBytesWritten();
tsocket->disconnectFromHost();
if(tsocket->state() != QAbstractSocket::UnconnectedState)
tsocket->waitForDisconnected();
//HKTODO: Do not delete connection (test fix for ORNL machines)
//tsocket->deleteLater();
}
else
{
QWsSocket *wsocket = dynamic_cast<QWsSocket*>(socket);
wsocket->write(QString(node.ToString().c_str()));
wsocket->flush();
if(wsocket->internalSocket()->state() != QAbstractSocket::UnconnectedState)
wsocket->internalSocket()->waitForBytesWritten();
wsocket->close("");
wsocket->internalSocket()->disconnectFromHost();
if(wsocket->internalSocket()->state() != QAbstractSocket::UnconnectedState)
wsocket->internalSocket()->waitForDisconnected();
wsocket->deleteLater();
}
}
示例2: defined
// ****************************************************************************
// Method: SocketConnection::Flush
//
// Purpose:
// Writes the entire contents of the connection's buffer onto the
// socket file descriptor in chunks. It then clears the buffer.
//
//
// Programmer: Brad Whitlock
// Creation: Tue Aug 29 12:17:37 PDT 2000
//
// Modifications:
// Brad Whitlock, Tue Mar 26 13:29:20 PST 2002
// Made it use socket functions so it is more portable.
//
// Brad Whitlock, Thu Jan 25 18:42:50 PST 2007
// I made it use MSG_NOSIGNAL so we don't get a signal in the event that
// we can't write to the socket.
//
// Eric Brugger, Tue Mar 13 09:18:48 PDT 2007
// I made the use of MSG_NOSIGNAL conditional on its definition.
//
// ****************************************************************************
void
SocketConnection::Flush(AttributeSubject *subject)
{
if(destFormat.Format == TypeRepresentation::BINARYFORMAT)
Connection::Flush(subject);
else
{
// std::cout << subject->TypeName() << " "
// << subject->CalculateMessageSize(*this)
// << std::endl;
if(subject->GetSendMetaInformation())
{
MapNode meta;
JSONNode node;
subject->WriteMeta(meta);
node["id"] = subject->GetGuido();
node["typename"] = subject->TypeName();
node["api"] = meta.ToJSONNode(false,false);
const std::string& output = node.ToString().c_str();
#if defined(_WIN32)
send(descriptor, (const char FAR *)output.c_str(), output.size(), 0);
#else
#ifdef MSG_NOSIGNAL
send(descriptor, (const void *)output.c_str(), output.size(), MSG_NOSIGNAL);
#else
send(descriptor, (const void *)output.c_str(), output.size(), 0);
#endif
#endif
}
MapNode child;
JSONNode node;
subject->Write(child);
node["id"] = subject->GetGuido();
node["typename"] = subject->TypeName();
node["contents"] = child.ToJSONNode(false);
const std::string& output = node.ToString();
#if defined(_WIN32)
send(descriptor, (const char FAR *)output.c_str(), output.size(), 0);
#else
#ifdef MSG_NOSIGNAL
send(descriptor, (const void *)output.c_str(), output.size(), MSG_NOSIGNAL);
#else
send(descriptor, (const void *)output.c_str(), output.size(), 0);
#endif
#endif
buffer.clear();
}
}
示例3: dims
/// we are always returning true unless the script
/// itself is failing not the inquiry..
bool
avtProgrammableOperation::avtVisItGetVarInfo::func(ProgrammableOpArguments& args, Variant& result)
{
std::string varName = args.getArg(0).AsString();
vtkDataSet* dataset = args.GetInputDataSet();
bool pointData = true;
vtkDataArray* array = dataset->GetPointData()->GetScalars(varName.c_str());
if(!array) {
array = dataset->GetCellData()->GetScalars(varName.c_str());
pointData = false;
}
/// for now just deal with scalars..
if(array == NULL)
{
result = "";
return true;
}
/// now extract information from the array..
/// through in mesh dimensions to help inquiring class reshape
/// information correctly..
JSONNode resultNode;
resultNode["type"] = pointData ? "pointdata" : "celldata";
JSONNode::JSONArray dims(3,-1);
resultNode["dims"] = dims;
result = resultNode.ToString();
return true;
}