// the translator function void SEH_To_Cplusplus ( unsigned int u, EXCEPTION_POINTERS *exp ) { int code = exp->ExceptionRecord->ExceptionCode; if ( code == EXCEPTION_ACCESS_VIOLATION ) { NosuchErrorOutput("NULL POINTER DEREFERENCE!! throwing NosuchException\n"); throw NosuchException("NULL POINTER DEREFERENCE!! (NosuchException translated from SEH exception)"); } else { throw NosuchException("NosuchException translated from SEH exception, code=%d",code); } }
double methodNeedDouble(std::string meth,cJSON *j,std::string nm) { NosuchAssert(j); cJSON *c = cJSON_GetObjectItem(j,nm.c_str()); if ( ! c ) { throw NosuchException("Missing %s argument on %s method",nm.c_str(),meth.c_str()); } if ( c->type != cJSON_Number ) { throw NosuchException("Unexpected type for %s argument to %s method, expecting double",nm.c_str(),meth.c_str()); } return (double)(c->valuedouble); }
std::string methodNeedString(std::string meth,cJSON *j,std::string nm) { NosuchAssert(j); cJSON *c = cJSON_GetObjectItem(j,nm.c_str()); if ( ! c ) { throw NosuchException("Missing %s argument on %s method",nm.c_str(),meth.c_str()); } if ( c->type != cJSON_String ) { throw NosuchException("Unexpected type for %s argument to %s method, expecting string",nm.c_str(),meth.c_str()); } return c->valuestring; }
std::string jsonNeedString(cJSON *j,std::string nm, std::string dflt) { if ( j == NULL ) { return dflt; } cJSON *c = cJSON_GetObjectItem(j,nm.c_str()); if ( ! c ) { if ( dflt == DFLT_STR_THROW_EXCEPTION ) { throw NosuchException("Missing '%s' value in JSON",nm.c_str()); } return dflt; } if ( c->type != cJSON_String ) { throw NosuchException("Unexpected type for %s value, expecting string",nm.c_str()); } return c->valuestring; }
double jsonNeedDouble(cJSON *j,std::string nm, double dflt) { if ( j == NULL ) { return dflt; } cJSON *c = cJSON_GetObjectItem(j,nm.c_str()); if ( ! c ) { if ( dflt == DFLT_DOUBLE_THROW_EXCEPTION ) { throw NosuchException("Missing '%s' value in JSON",nm.c_str()); } return dflt; } if ( c->type != cJSON_Number ) { throw NosuchException("Unexpected type for %s value, expecting double",nm.c_str()); } return (double)(c->valuedouble); }
int jsonNeedInt(cJSON *j,std::string nm, int dflt) { if ( j == NULL ) { return dflt; } cJSON *c = cJSON_GetObjectItem(j,nm.c_str()); if ( ! c ) { if ( dflt == DFLT_INT_THROW_EXCEPTION ) { throw NosuchException("Missing '%s' value in JSON",nm.c_str()); } return dflt; } if ( c->type != cJSON_Number ) { throw NosuchException("Unexpected type for '%s' value, expecting number",nm.c_str()); } return c->valueint; }
void Region::instantiateSprite(Cursor* c, bool throttle) { std::string shape = params.shape; int tm = Palette::now; int dt = tm - c->last_instantiate(); if ( throttle && (dt < SPRITE_THROTTLE_MS_PER_CURSOR ) ) { // NosuchDebug("THROTTLE is avoiding making a new sprite at tm=%d",tm); return; } Sprite* s = NULL; if ( shape == "square" ) { s = new SpriteSquare(); } else if ( shape == "triangle" ) { s = new SpriteTriangle(); } else if ( shape == "circle" ) { s = new SpriteCircle(); } else if ( shape == "outline" ) { OutlineMem* om = c->outline(); if ( om ) { SpriteOutline* so = new SpriteOutline(); MMTT_SharedMemHeader* hdr = palette->paletteHost()->outlines_memory(); so->setOutline(c->outline(),hdr); s = (Sprite*) so; } } else if ( shape == "curve" ) { s = new SpriteCurve(); } else if ( shape == "line" ) { s = new SpriteLine(); } else if ( shape == "arc" ) { NosuchDebug(1,"Sprite arc need to be finished!\n"); s = new SpriteSquare(); } else if ( shape == "nothing" ) { // } else { throw NosuchException("Unrecognized type of shape: %s",shape.c_str()); } if ( s ) { s->params.initValues(this); s->initState(c->sidnum(),c->sidsource(),c->curr_pos,spriteMoveDir(c),c->curr_depth); c->set_last_instantiate(tm); // NosuchDebug("instantiateSprite c->curr_degrees=%.4lf direction=%.4lf",c->curr_degrees,s->state.direction); if ( params.shape == "curve" ) { c->curr_behaviour = "accumulate"; s->startAccumulate(c); } spritelist->add(s,params.nsprites); } }
AllVizParams* Region::LoadParams(std::string pathname,AllVizParams* p) { std::string err; DEBUGPRINT(("LoadParams pathname=%s",pathname.c_str())); cJSON* j = jsonReadFile(pathname,err); if ( ! j ) { throw NosuchException("Unable to open file (name=%s, err=%s)",pathname.c_str(),err.c_str()); } p->loadJson(j); jsonFree(j); return p; }
std::string VizMidi::processJson(std::string meth, cJSON *params, const char *id) { // NO OpenGL calls here if ( meth == "circle" ) { _midiparams->shape.set("circle"); return jsonOK(id); } if ( meth == "line" ) { _midiparams->shape.set("line"); return jsonOK(id); } throw NosuchException("VizMidi - Unrecognized method '%s'",meth.c_str()); }
std::string jsonValueString(cJSON* j) { std::string val; switch (j->type) { case cJSON_Number: val = NosuchSnprintf("%f",j->valuedouble); break; case cJSON_String: val = j->valuestring; break; default: throw NosuchException("jsonValueString not prepared to handle type=%d",j->type); } return val; }
double Region::getMoveDir(std::string movedirtype) { if ( movedirtype == "left" ) { return 180.0f; } if ( movedirtype == "right" ) { return 0.0f; } if ( movedirtype == "up" ) { return 90.0f; } if ( movedirtype == "down" ) { return 270.0f; } if ( movedirtype == "random" ) { double f = ((double)(rand()))/ RAND_MAX; return f * 360.0f; } throw NosuchException("Unrecognized movedirtype value %s",movedirtype.c_str()); }
double Channel::getMoveDir(std::string movedirtype) { if ( movedirtype == "left" ) { return 180.0f; } if ( movedirtype == "right" ) { return 0.0f; } if ( movedirtype == "up" ) { return 90.0f; } if ( movedirtype == "down" ) { return 270.0f; } if ( movedirtype == "random" ) { double f = ((double)(rand()))/ RAND_MAX; return f * 360.0f; } if ( movedirtype == "cursor" ) { // random, not sure what it should be double f = ((double)(rand()))/ RAND_MAX; return f * 360.0f; } throw NosuchException("Unrecognized movedirtype value %s",movedirtype.c_str()); }
void Palette::applyPatch(std::string patchname) { Patch* patch = GetPatchNamed(patchname); if ( patch == NULL ) { throw NosuchException("Unable to find patch named: %s",patchname.c_str()); } for ( size_t i=0; i < _regions.size(); i++ ) { Region* r = _regions[i]; std::string parampath = patch->getRegionParamPath(r->name); if ( parampath == "" ) { continue; } r->resetRegionParams(); std::vector<std::string> files = NosuchSplitOnString(parampath,","); for ( size_t i=0; i<files.size(); i++ ) { // Read region-specific params for the patch AllVizParams* rparams = vizlet()->getAllVizParams(files[i]); if ( rparams == NULL ) { DEBUGPRINT(("Unable to retrieve params file: %s",files[i].c_str())); } else { r->regionParams()->applyVizParamsFrom(rparams); } // Should rparams be freed? } } std::string effects = patch->getEffects(); LoadEffectSet(effects); }
std::string Viz10Example1::processJson(std::string meth, cJSON *json, const char *id) { throw NosuchException("Viz10Example1 - Unrecognized method '%s'",meth.c_str()); }
void methodNeedParams(std::string meth, cJSON* j) { if(j==NULL) { throw NosuchException("No parameters on %s method?",meth.c_str()); } }