int main(){
JSONNode n = read_formatted("input.json");
JSONNode n1 = read_formatted("input1.json");
test *tst = new test();
int status;
//n.set_name(abi::__cxa_demangle(typeid(*tst).name(), 0,0,&status ));
n.push_back(JSONNode("FF::Node_Subclass", abi::__cxa_demangle(typeid(*tst).name(), 0,0,&status )));
if(n1.type()==JSON_NULL){
   std::cout<<"null"<<std::endl; 
}
JSONNode n2 (JSON_NODE);
n2.set_name("Child1");
n2.push_back(JSONNode("id",1));
n.set_name("Parrent");
n.push_back(n2);
JSONNode::iterator it =n.find_nocase("String Node");
if(it->as_string()=="-1"){std::cout<<it->as_int()<<std::endl;}
it->as_int()!=-1 ? (std::cout<< "it is"<<std::endl) : (std::cout<<"Mapper Warning: processor id is -1"<<std::endl);
if (n.at("String Node")==""){
std::cout<<"ha ha ha"<<std::endl;
}
std::cout<< "This is the name: "<<n.name()<<std::endl;
n.at("String Node")="";
bool x =true;
n.push_back(JSONNode("MyBOOLNODE", x));
n["String Node"]=x;
//n.erase(n.find_nocase("String Node"));
write_formatted(n1, "out1.json");
write_formatted(n, "out.json");
JSONNode::const_iterator i =n.find_nocase("ArrayOfNumbers");
std::string strLowerCase= "ARRAYOfNUMbers"; 
std::string myTest= "ff::ff_farm<adaptive_loadbalancer, ff::ff_gatherer>";
std::transform(myTest.begin(), myTest.end(), myTest.begin(), ::tolower);
std::size_t found = myTest.find("adaptive_loadbalancer");
if (found!=std::string::npos)
  std::cout << "first 'needle' found at: " << found << '\n';

std::cout<< "here it is: " << myTest<< std::endl;
JSONNode n_ar = n.at("ArrayOfNumbers");
std::cout<<"here :"<<n_ar[0].as_int()<< std::endl;
// if (0 == strcasecmp("hello", "HELLO"))

if(strcasecmp((i->name()).c_str(), strLowerCase.c_str()) == 0)
//if(!(n2.empty()))
  std::cout<<"haha"<<i->size()<<std::endl;
std::cout<<i->name()<<std::endl;
std::cout<<((i->as_array()).begin()+1)->as_int()<<std::endl;
std::cout<<((i->as_array()).at(1)).as_int()<<std::endl;
std::cout<<((i->as_array())[1]).as_int()<<std::endl;
//std::cout<<i->as_string()<<std::endl;
//JSONNode c(JSON_ARRAY);
//c=i->as_array();
//JSONNode nk= c.at(0);
//JSONNode::const_iterator it = c.begin();
//std::cout <<nk.as_int()<<std::endl;
return 0;
}
Beispiel #2
0
void Rig::loadJSON(JSONNode root) {
  //JSONNode::const_iterator i = root.begin();
  JSONNode::iterator i = root.begin();

  auto version = root.find("version");
  if (version == root.end()) {
    Logger::log(ERR, "No version specified for input file. Aborting load.");
    return;
  }
  else {
    stringstream ss;
    stringstream ss2(version->as_string());

    ss << LumiverseCore_VERSION_MAJOR << "." << LumiverseCore_VERSION_MINOR;
    
    float libVer;
    float fileVer;

    ss >> libVer;
    ss2 >> fileVer;

    if (fileVer < libVer) {
      // Friendly warning if you're loading an old file.
      Logger::log(WARN, "File created against earlier version of Lumiverse. Check logs for any load problems.");
    }
    else if (fileVer > libVer) {
      // Loading newer file with older library.
      Logger::log(WARN, "File created against newer version of Lumiverse. Check logs for any load problems.");
    }
  }

  while (i != root.end()){
    // get the node name and value as a string
    std::string nodeName = i->name();

    if (nodeName == "devices") {
      loadDevices(*i);
      Logger::log(INFO, "Device load complete");
    }
    else if (nodeName == "patches") {
	  i->push_back(*root.find("jsonPath"));
      loadPatches(*i);
      Logger::log(INFO, "Patch load complete");
    }
    else if (nodeName == "refreshRate") {
      setRefreshRate(i->as_int());
    }

    //increment the iterator
    ++i;
  }
}
Beispiel #3
0
void Rig::loadPatches(JSONNode root) {
  JSONNode::iterator i = root.begin();

  // for this we want to iterate through all children and have the device class
  // parse the sub-element.
  while (i != root.end()){
	if (i->name() == "jsonPath") {
		i++;
		continue;
	}

    // get the node name and value as a string
    std::string nodeName = i->name();

    stringstream ss;
    ss << "Loading patch " << nodeName;
    Logger::log(INFO, ss.str());

    Patch* patch;
    
    auto type = i->find("type");
    if (type == i->end()) {
      stringstream ss;
      ss << "Unable to determine Patch type for " << nodeName << ". Patch not loaded.";
      Logger::log(WARN, ss.str());
    }

    string patchType = type->as_string();

    // New patch types will need new seralization definitions.
    if (patchType == "DMXPatch") {
      patch = (Patch*) new DMXPatch(*i);
      addPatch(nodeName, patch);
    }
#ifdef USE_ARNOLD
	else if (patchType == "PhotoPatch") {
		patch = (Patch*) new PhotoPatch(*i);
		addPatch(nodeName, patch);

		Device::DeviceCallbackFunction callback = std::bind(&PhotoPatch::onDeviceChanged,
			(PhotoPatch*)patch,
			std::placeholders::_1);
		for (Device *d : getDeviceRaw()) {
			d->addParameterChangedCallback(callback);
			d->addMetadataChangedCallback(callback);
		}
	}
	else if (patchType == "PhotoAnimationPatch") {
		patch = (Patch*) new PhotoAnimationPatch(*i);
		addPatch(nodeName, patch);

		Device::DeviceCallbackFunction callback = std::bind(&PhotoAnimationPatch::onDeviceChanged,
			(PhotoAnimationPatch*)patch,
			std::placeholders::_1);
		for (Device *d : getDeviceRaw()) {
			d->addParameterChangedCallback(callback);
			d->addMetadataChangedCallback(callback);
		}
	}
    else if (patchType == "ArnoldAnimationPatch") {
	  i->push_back(*root.find("jsonPath"));
      patch = (Patch*) new ArnoldAnimationPatch(*i);
      addPatch(nodeName, patch);
      Device::DeviceCallbackFunction callback = std::bind(&ArnoldAnimationPatch::onDeviceChanged,
                                                            (ArnoldAnimationPatch*)patch,
                                                            std::placeholders::_1);
      for (Device *d : getDeviceRaw()) {
          d->addParameterChangedCallback(callback);
          d->addMetadataChangedCallback(callback);
      }
    }
    else if (patchType == "ArnoldPatch") {
	  i->push_back(*i->find("jsonPath"));
      patch = (Patch*) new ArnoldPatch(*i);
      addPatch(nodeName, patch);
        
        Device::DeviceCallbackFunction callback = std::bind(&ArnoldPatch::onDeviceChanged,
                                                            (ArnoldPatch*)patch,
                                                            std::placeholders::_1);
        for (Device *d : getDeviceRaw()) {
            d->addParameterChangedCallback(callback);
            d->addMetadataChangedCallback(callback);
        }
    }
#endif
    else {
      stringstream ss;
      ss << "Unknown Patch type " << patchType << " in Patch ID " << nodeName << "Patch not loaded.";
      Logger::log(WARN, ss.str());
    }

    //increment the iterator
    ++i;
  }
}
Beispiel #4
0
listener_ptr makeStreamListener(StreamingDevice* dev, ClientConn* client, JSONNode &n){
	std::auto_ptr<WSStreamListener> listener(new WSStreamListener());

	listener->id = jsonIntProp(n, "id");
	listener->device = dev;
	listener->client = client;
	
	listener->decimateFactor = jsonIntProp(n, "decimateFactor", 1);
	
	// Prevent divide by 0
	if (listener->decimateFactor == 0) listener->decimateFactor = 1; 

	int start = jsonIntProp(n, "start", -1);
	if (start < 0){ // Negative indexes are relative to latest sample
		start = (dev->buffer_max()) + start + 1;
	}

	if (start < 0) listener->index = 0;
	else listener->index = start;
	
	listener->count = jsonIntProp(n, "count");
	
	JSONNode j_streams = n.at("streams");
	for(JSONNode::iterator i=j_streams.begin(); i!=j_streams.end(); i++){
		listener->streams.push_back(
			dev->findStream(
				jsonStringProp(*i, "channel"),
				jsonStringProp(*i, "stream")));
	}
	
	JSONNode::iterator t = n.find("trigger");
	if (t != n.end() && (t->type()) == JSON_NODE){
		JSONNode &trigger = *t;
		
		string type = jsonStringProp(trigger, "type", "in");
		if (type == "in"){
			listener->triggerType = INSTREAM;
			listener->triggerLevel = jsonFloatProp(trigger, "level");
			listener->triggerStream = dev->findStream(
				jsonStringProp(trigger, "channel"),
				jsonStringProp(trigger, "stream"));
		}else if (type == "out"){
			listener->triggerType = OUTSOURCE;
			listener->triggerChannel = dev->channelById(jsonStringProp(trigger, "channel"));
			if (!listener->triggerChannel) throw ErrorStringException("Trigger channel not found");
		}else{
			throw ErrorStringException("Invalid trigger type");
		}
			
		listener->triggerRepeat = jsonBoolProp(trigger, "repeat", true);
		listener->triggerHoldoff = jsonIntProp(trigger, "holdoff", 0);
		listener->triggerOffset = jsonIntProp(trigger, "offset", 0);
		
		if (listener->triggerOffset<0 && -listener->triggerOffset >= listener->triggerHoldoff){
			// Prevent big negative offsets that could cause infinite loops
			listener->triggerHoldoff = -listener->triggerOffset;
		}
		listener->triggerForce = jsonIntProp(trigger, "force", 0);
		listener->triggerForceIndex = listener->index + listener->triggerForce;
	}
		
		
	return listener_ptr(listener.release());
}
Beispiel #5
0
inline bool jsonBoolProp(JSONNode &n, const char* prop, bool def){
	JSONNode::iterator i = n.find(prop);
	if (i != n.end() && i->type() == JSON_BOOL) return i->as_bool();
	else return def;
}
Beispiel #6
0
inline double jsonFloatProp(JSONNode &n, const char* prop, double def){
	JSONNode::iterator i = n.find(prop);
	if (i != n.end() && i->type() == JSON_NUMBER) return i->as_float();
	else return def;
}
Beispiel #7
0
inline int jsonIntProp(JSONNode &n, const char* prop, int def){
	JSONNode::iterator i = n.find(prop);
	if (i != n.end() && i->type() == JSON_NUMBER) return i->as_int();
	else return def;
}
Beispiel #8
0
inline string jsonStringProp(JSONNode &n, const char* prop, string def){
	JSONNode::iterator i = n.find(prop);
	if (i != n.end() && i->type() == JSON_STRING) return i->as_string();
	else return def;
}
Beispiel #9
0
inline double jsonFloatProp(JSONNode &n, const char* prop){
	JSONNode::iterator i = n.find(prop);
	if (i != n.end() && i->type() == JSON_NUMBER) return i->as_float();
	else throw ErrorStringException(string("JSON missing float property: ") + prop);
}
Beispiel #10
0
inline bool jsonBoolProp(JSONNode &n, const char* prop){
	JSONNode::iterator i = n.find(prop);
	if (i != n.end() && i->type() == JSON_BOOL) return i->as_bool();
	else throw ErrorStringException(string("JSON missing bool property: ") + prop);
}
Beispiel #11
0
inline string jsonStringProp(JSONNode &n, const char* prop){
	JSONNode::iterator i = n.find(prop);
	if (i != n.end() && i->type() == JSON_STRING) return i->as_string();
	else throw ErrorStringException(string("JSON missing string property: ") + prop);
}