本文整理汇总了C++中json::Value类的典型用法代码示例。如果您正苦于以下问题:C++ Value类的具体用法?C++ Value怎么用?C++ Value使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Value类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: addOption
/// Adds the default connector options. Also updates the capabilities structure with the default options.
/// Besides the options addBasicConnectorOptions adds, this function also adds port and interface options.
void Util::Config::addConnectorOptions(int port, JSON::Value & capabilities){
JSON::Value option;
option.null();
option["long"] = "port";
option["short"] = "p";
option["arg"] = "integer";
option["help"] = "TCP port to listen on";
option["value"].append((long long)port);
addOption("listen_port", option);
capabilities["optional"]["port"]["name"] = "TCP port";
capabilities["optional"]["port"]["help"] = "TCP port to listen on - default if unprovided is "+option["value"][0u].asString();
capabilities["optional"]["port"]["type"] = "uint";
capabilities["optional"]["port"]["option"] = "--port";
capabilities["optional"]["port"]["default"] = option["value"][0u];
option.null();
option["long"] = "interface";
option["short"] = "i";
option["arg"] = "string";
option["help"] = "Interface address to listen on, or 0.0.0.0 for all available interfaces.";
option["value"].append("0.0.0.0");
addOption("listen_interface", option);
capabilities["optional"]["interface"]["name"] = "Interface";
capabilities["optional"]["interface"]["help"] = "Address of the interface to listen on - default if unprovided is all interfaces";
capabilities["optional"]["interface"]["option"] = "--interface";
capabilities["optional"]["interface"]["type"] = "str";
addBasicConnectorOptions(capabilities);
} //addConnectorOptions
示例2: getNext
void inputFLV::getNext(bool smart) {
static JSON::Value thisPack;
static AMF::Object amf_storage;
thisPack.null();
long long int lastBytePos = ftell(inFile);
FLV::Tag tmpTag;
while (!feof(inFile) && !FLV::Parse_Error){
if (tmpTag.FileLoader(inFile)){
thisPack = tmpTag.toJSON(myMeta, amf_storage);
thisPack["bpos"] = lastBytePos;
if ( !selectedTracks.count(thisPack["trackid"].asInt())){
getNext();
}
break;
}
}
if (FLV::Parse_Error){
FAIL_MSG("FLV error: %s", FLV::Error_Str.c_str());
thisPack.null();
thisPacket.null();
return;
}
std::string tmpStr = thisPack.toNetPacked();
thisPacket.reInit(tmpStr.data(), tmpStr.size());
}
示例3: readHeader
bool inputFLV::readHeader() {
JSON::Value lastPack;
if (!inFile) {
return false;
}
//See whether a separate header file exists.
DTSC::File tmp(config->getString("input") + ".dtsh");
if (tmp){
myMeta = tmp.getMeta();
return true;
}
//Create header file from FLV data
fseek(inFile, 13, SEEK_SET);
FLV::Tag tmpTag;
long long int lastBytePos = 13;
while (!feof(inFile) && !FLV::Parse_Error){
if (tmpTag.FileLoader(inFile)){
lastPack.null();
lastPack = tmpTag.toJSON(myMeta);
lastPack["bpos"] = lastBytePos;
myMeta.update(lastPack);
lastBytePos = ftell(inFile);
}
}
if (FLV::Parse_Error){
std::cerr << FLV::Error_Str << std::endl;
return false;
}
std::ofstream oFile(std::string(config->getString("input") + ".dtsh").c_str());
oFile << myMeta.toJSON().toNetPacked();
oFile.close();
return true;
}
示例4: ParseStageConnections
void CompositorLoader::ParseStageConnections(CompositeStageConnections& connections, const json::Value& stageJson)
{
if (stageJson.HasKey("input") && stageJson["input"].GetType() == ArrayVal)
{
Array inputArray = stageJson["input"].ToArray();
for (auto it = inputArray.begin(); it != inputArray.end(); ++it)
{
connections.AddRenderTargetInput(it->ToString(""));
}
}
if (stageJson.HasKey("output") && stageJson["output"].GetType() == ArrayVal)
{
Array inputArray = stageJson["output"].ToArray();
for (auto it = inputArray.begin(); it != inputArray.end(); ++it)
{
connections.AddRenderTarget(it->ToString(""));
}
}
if (stageJson.HasKey("depthBuffer") && stageJson["depthBuffer"].GetType() == StringVal)
{
connections.SetDepthBuffer(stageJson["depthBuffer"].ToString());
}
}
示例5: CompareJson
void CompareJson(json::Value& lhs, json::Value& rhs, json::Value& output) {
std::string lstr, rstr;
if (rhs.type() != lhs.type()) return;
switch (lhs.type()) {
case json::Value::tString:
lstr = lhs.getString();
rstr = rhs.getString();
if (!lstr.empty() && lstr[0] == '$' && lstr.back() == '$') {
size_t slash = lstr.find('/');
std::string cat = lstr.substr(1, slash - 1);
std::string name = lstr.substr(slash + 1, lstr.length() - slash - 2);
output[cat][name] = rstr;
}
break;
case json::Value::tArray:
for (size_t i = 0; i < lhs.length(); ++i) {
if (i < rhs.length()) {
CompareJson(lhs[i], rhs[i], output);
}
}
break;
case json::Value::tObject:
for (auto it = lhs.begin(); it != lhs.end(); ++it) {
if (rhs.has(it.key())) {
CompareJson(*it, rhs[it.key()], output);
}
}
break;
}
}
示例6: parsePrefab
void Animation::parsePrefab(json::Value& val)
{
if(val.isMember("sequences") && !val["sequences"].empty())
{
json::Value sequences = val["sequences"];
for(json::Value::iterator it = sequences.begin(); it != sequences.end(); ++it)
{
if(!(*it).isMember("start") || !(*it).isMember("end") || !(*it).isMember("fps"))
{
szerr << "Animation sequence definition must have start and end frame and fps value." << ErrorStream::error;
continue;
}
sf::Uint32 start = (*it)["start"].asUInt();
sf::Uint32 end = (*it)["end"].asUInt();
sf::Uint32 fps = (*it)["fps"].asUInt();
bool looping = (*it).get("looping", 0).asBool();
std::string next = (*it).get("next", "").asString();
defineAnimation(it.memberName(), start, end, fps, looping, next);
}
}
if(val.isMember("autoplay"))
{
if(val["autoplay"].isString())
{
play(val["autoplay"].asString());
}
}
}
示例7: couchLoadData
static void couchLoadData(PrintTextA &print) {
CouchDB db(getTestCouch());
db.use(DATABASENAME);
AutoArray<Document, SmallAlloc<50> > savedDocs;
Changeset chset(db.createChangeset());
natural id=10000;
JSON::Value data = db.json.factory->fromString(strdata);
for (JSON::Iterator iter = data->getFwIter(); iter.hasItems();) {
const JSON::KeyValue &kv= iter.getNext();
Document doc;
doc.edit(db.json)
("name",kv[0])
("age",kv[1])
("height",kv[2])
("_id",ToString<natural>(id,16));
id+=14823;
savedDocs.add(doc);
chset.update(doc);
}
chset.commit(false);
Set<StringA> uuidmap;
for (natural i = 0; i < savedDocs.length(); i++) {
StringA uuid = savedDocs[i]["_id"]->getStringUtf8();
// print("%1\n") << uuid;
uuidmap.insert(uuid);
}
print("%1") << uuidmap.size();
}
示例8: ParseStage
void CompositorLoader::ParseStage(ResourceManager& resourceManager, Compositor::Ptr& compositor, const json::Value& stageJson)
{
if (stageJson.HasKey("disabled") && stageJson["disabled"].ToBool(false))
{
return;
}
if (!stageJson.HasKey("stage") || stageJson["stage"].GetType() != StringVal)
{
throw FormatException("stages[].stage needs to be a string containing the relvative path to a CompositeStage");
}
CompositeStageConnections connections;
ParseStageConnections(connections, stageJson);
std::string stageFilename = stageJson["stage"].ToString();
CompositeStage::Ptr stage = resourceManager.LoadResource<CompositeStage>(stageFilename);
if (stageJson.HasKey("shaderValues"))
{
Array defaultValues = stageJson["shaderValues"].ToArray();
for (auto it = defaultValues.begin(); it != defaultValues.end(); ++it)
{
JsonTypeHelper::ParseValueIntoParameters(stage->GetStateParameters(), *it);
}
}
compositor->AddCompositeStage(stage, connections);
}
示例9: CheckAllStreams
void CheckAllStreams(JSON::Value & data){
long long int currTime = Util::epoch();
for (JSON::ObjIter jit = data.ObjBegin(); jit != data.ObjEnd(); jit++){
if ( !Util::Procs::isActive(jit->first)){
startStream(jit->first, jit->second);
}
if (currTime - lastBuffer[jit->first] > 5){
if (jit->second.isMember("error") && jit->second["error"].asString() != ""){
jit->second["online"] = jit->second["error"];
}else{
jit->second["online"] = 0;
}
}else{
jit->second["online"] = 1;
}
}
static JSON::Value strlist;
bool changed = false;
if (strlist["config"] != Storage["config"]){
strlist["config"] = Storage["config"];
changed = true;
}
if (strlist["streams"] != Storage["streams"]){
strlist["streams"] = Storage["streams"];
changed = true;
}
if (changed){
WriteFile("/tmp/mist/streamlist", strlist.toString());
}
}
示例10: numberToWide
static void numberToWide(PrintTextA &print) {
JSON::PFactory f = JSON::create();
JSON::Value v = f->newValue((natural)123);
String tst1 = v->getString();
String tst2 = v->getString();
print("%1,%2") << tst1 << tst2;
}
示例11: dynamicBootstrap
///\brief Builds a bootstrap for use in HTTP Dynamic streaming.
///\param streamName The name of the stream.
///\param metadata The current metadata, used to generate the index.
///\param fragnum The index of the current fragment
///\return The generated bootstrap.
std::string dynamicBootstrap(std::string & streamName, JSON::Value & metadata, int fragnum = 0){
std::string empty;
MP4::ASRT asrt;
asrt.setUpdate(false);
asrt.setVersion(1);
//asrt.setQualityEntry(empty, 0);
if (metadata.isMember("live")){
asrt.setSegmentRun(1, 4294967295ul, 0);
}else{
asrt.setSegmentRun(1, metadata["keytime"].size(), 0);
}
MP4::AFRT afrt;
afrt.setUpdate(false);
afrt.setVersion(1);
afrt.setTimeScale(1000);
//afrt.setQualityEntry(empty, 0);
MP4::afrt_runtable afrtrun;
if (metadata.isMember("live")){
// restrict data to last 2 fragments, unless an earlier fragment was expressly requested.
int count = 0;
unsigned int begin = std::max(0u, metadata["keynum"].size() - 3);
while (begin > 0 && fragnum && metadata["keynum"][begin].asInt() > fragnum){
begin--;
}
for (int i = begin; i < metadata["keynum"].size(); i++){
afrtrun.firstFragment = metadata["keynum"][i].asInt();
afrtrun.firstTimestamp = metadata["keytime"][i].asInt();
afrtrun.duration = metadata["keylen"][i].asInt();
afrt.setFragmentRun(afrtrun, count++);
}
}else{
for (int i = 0; i < metadata["keynum"].size(); i++){
afrtrun.firstFragment = metadata["keynum"][i].asInt();
afrtrun.firstTimestamp = metadata["keytime"][i].asInt();
afrtrun.duration = metadata["keylen"][i].asInt();
afrt.setFragmentRun(afrtrun, i);
}
}
MP4::ABST abst;
abst.setVersion(1);
abst.setBootstrapinfoVersion(1);
abst.setProfile(0);
abst.setUpdate(false);
abst.setTimeScale(1000);
abst.setLive(false);
abst.setCurrentMediaTime(metadata["lastms"].asInt());
abst.setSmpteTimeCodeOffset(0);
abst.setMovieIdentifier(streamName);
abst.setSegmentRunTable(asrt, 0);
abst.setFragmentRunTable(afrt, 0);
#if DEBUG >= 8
std::cout << "Sending bootstrap:" << std::endl << abst.toPrettyString(0) << std::endl;
#endif
return std::string((char*)abst.asBox(), (int)abst.boxedSize());
}
示例12: BuildManifest
/// Returns a Smooth-format manifest file
std::string BuildManifest(std::string & MovieId, JSON::Value & metadata){
std::stringstream Result;
Result << "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n";
Result << "<SmoothStreamingMedia MajorVersion=\"2\" MinorVersion=\"0\" TimeScale=\"10000000\" Duration=\"" << metadata["lastms"].asInt()
<< "\">\n";
if (metadata.isMember("audio")){
Result << " <StreamIndex Type=\"audio\" QualityLevels=\"1\" Name=\"audio\" Chunks=\"" << metadata["keytime"].size()
<< "\" Url=\"Q({bitrate})/A({start time})\">\n";
Result << " <QualityLevel Index=\"0\" Bitrate=\"" << metadata["audio"]["bps"].asInt() * 8 << "\" CodecPrivateData=\"";
Result << std::hex;
for (int i = 0; i < metadata["audio"]["init"].asString().size(); i++){
Result << std::setfill('0') << std::setw(2) << std::right << (int)metadata["audio"]["init"].asString()[i];
}
Result << std::dec;
Result << "\" SamplingRate=\"" << metadata["audio"]["rate"].asInt()
<< "\" Channels=\"2\" BitsPerSample=\"16\" PacketSize=\"4\" AudioTag=\"255\" FourCC=\"AACL\" />\n";
for (int i = 0; i < metadata["keytime"].size() - 1; i++){
Result << " <c ";
if (i == 0){
Result << "t=\"0\" ";
}
Result << "d=\"" << 10000 * (metadata["keytime"][i + 1].asInt() - metadata["keytime"][i].asInt()) << "\" />\n";
}
Result << " <c d=\"" << 10000 * (metadata["lastms"].asInt() - metadata["keytime"][metadata["keytime"].size() - 1].asInt()) << "\" />\n";
Result << " </StreamIndex>\n";
}
if (metadata.isMember("video")){
Result << " <StreamIndex Type=\"video\" QualityLevels=\"1\" Name=\"video\" Chunks=\"" << metadata["keytime"].size()
<< "\" Url=\"Q({bitrate})/V({start time})\" MaxWidth=\"" << metadata["video"]["width"].asInt() << "\" MaxHeight=\""
<< metadata["video"]["height"].asInt() << "\" DisplayWidth=\"" << metadata["video"]["width"].asInt() << "\" DisplayHeight=\""
<< metadata["video"]["height"].asInt() << "\">\n";
Result << " <QualityLevel Index=\"0\" Bitrate=\"" << metadata["video"]["bps"].asInt() * 8 << "\" CodecPrivateData=\"";
MP4::AVCC avccbox;
avccbox.setPayload(metadata["video"]["init"].asString());
std::string tmpString = avccbox.asAnnexB();
Result << std::hex;
for (int i = 0; i < tmpString.size(); i++){
Result << std::setfill('0') << std::setw(2) << std::right << (int)tmpString[i];
}
Result << std::dec;
Result << "\" MaxWidth=\"" << metadata["video"]["width"].asInt() << "\" MaxHeight=\"" << metadata["video"]["height"].asInt()
<< "\" FourCC=\"AVC1\" />\n";
for (int i = 0; i < metadata["keytime"].size() - 1; i++){
Result << " <c ";
if (i == 0){
Result << "t=\"0\" ";
}
Result << "d=\"" << 10000 * (metadata["keytime"][i + 1].asInt() - metadata["keytime"][i].asInt()) << "\" />\n";
}
Result << " <c d=\"" << 10000 * (metadata["lastms"].asInt() - metadata["keytime"][metadata["keytime"].size() - 1].asInt()) << "\" />\n";
Result << " </StreamIndex>\n";
}
Result << "</SmoothStreamingMedia>\n";
#if DEBUG >= 8
std::cerr << "Sending this manifest:" << std::endl << Result << std::endl;
#endif
return Result.str();
} //BuildManifest
示例13: serializeCycleError
static void serializeCycleError(PrintTextA &print) {
JSON::PFactory f = JSON::create();
JSON::Value v = f->fromString(jsonSrc);
JSON::Value arr = v["array"];
arr->add(v);
v->erase("text");
JSON::serialize(v, print.nxChain(), false);
v->erase("array");
}
示例14: resetStream
/// Adds a single DTSC packet to the stream, updating the internal metadata if needed.
void DTSC::Stream::addPacket(JSON::Value & newPack) {
livePos newPos;
newPos.trackID = newPack["trackid"].asInt();
newPos.seekTime = newPack["time"].asInt();
if (!metadata.tracks.count(newPos.trackID) && (!newPack.isMember("mark") || newPack["mark"].asStringRef() != "pause")) {
return;
}
if (buffercount > 1 && metadata.tracks[newPos.trackID].keys.size() > 1 && newPos.seekTime < (long long unsigned int)metadata.tracks[newPos.trackID].keys.rbegin()->getTime()) {
resetStream();
}
while (buffers.count(newPos) > 0) {
newPos.seekTime++;
}
while (buffercount == 1 && buffers.size() > 0) {
cutOneBuffer();
}
buffers[newPos] = newPack;
datapointertype = INVALID;
std::string tmp = "";
if (newPack.isMember("trackid") && newPack["trackid"].asInt() > 0) {
tmp = metadata.tracks[newPack["trackid"].asInt()].type;
}
if (newPack.isMember("datatype")) {
tmp = newPack["datatype"].asStringRef();
}
if (tmp == "video") {
datapointertype = VIDEO;
}
if (tmp == "audio") {
datapointertype = AUDIO;
}
if (tmp == "meta") {
datapointertype = META;
}
if (tmp == "pause_marker" || (newPack.isMember("mark") && newPack["mark"].asStringRef() == "pause")) {
datapointertype = PAUSEMARK;
}
if (buffercount > 1) {
metadata.update(newPack);
if (newPack.isMember("keyframe") || (long long unsigned int)metadata.tracks[newPos.trackID].keys.rbegin()->getTime() == newPos.seekTime) {
keyframes[newPos.trackID].insert(newPos);
}
metadata.live = true;
//throw away buffers if buffer time is met
int trid = buffers.begin()->first.trackID;
int firstTime = buffers.begin()->first.seekTime;
int lastTime = buffers.rbegin()->first.seekTime - buffertime;
while ((!metadata.tracks[trid].keys.size() && firstTime < lastTime) || (metadata.tracks[trid].keys.size() && metadata.tracks[trid].keys.rbegin()->getTime() < lastTime) || (metadata.tracks[trid].keys.size() > 2 && metadata.tracks[trid].keys.rbegin()->getTime() - firstTime > buffertime)) {
cutOneBuffer();
trid = buffers.begin()->first.trackID;
firstTime = buffers.begin()->first.seekTime;
}
metadata.bufferWindow = buffertime;
}
}
示例15: is_valid
bool AddressValidator::is_valid(const json::Value& value) {
if (!value.is_string()) {
return false;
}
const auto& val = value.as_string();
if ("localhost" == val) {
return true;
}
return std::regex_match(val, m_address_regex);
}