static void mdlUpdate(SimStruct *S, int_T tid) { yarp::os::BufferedPort<yarp::os::Bottle> *yPortIn = (yarp::os::BufferedPort<yarp::os::Bottle> *) ssGetPWork(S)[1]; yarp::os::Bottle *bottleIn = yPortIn->read(false); // shouldwait = false if(bottleIn != NULL) { #ifdef DEBUG mexPrintf("Receiving: #%s#\n", bottleIn->toString()); std::string strNull = std::string("is NULL: ") + std::string((bottleIn == NULL ? "yes": "no")) + std::string("\n"); mexPrintf(strNull.c_str()); #endif char_T buf03[LENGTH]; mxGetString(ssGetSFcnParam(S, 2), buf03, LENGTH); std::string strVarName(buf03); for (int bb=0;bb<(bottleIn->size()-1);bb++){ yarp::os::Value item = bottleIn->get(bb); std::string strKey = item.asList()->get(0).asString(); double fValue = item.asList()->get(1).asDouble(); if(!strKey.compare(strVarName)){ real_T *y = ssGetOutputPortRealSignal(S, 0); y[0] = fValue; } } } }
static void mdlUpdate(SimStruct *S, int_T tid) { yarp::os::BufferedPort<yarp::os::Bottle> *yPortIn = (yarp::os::BufferedPort<yarp::os::Bottle> *) ssGetPWork(S)[1]; yarp::os::Bottle *bottleIn = yPortIn->read(false); // shouldwait = false if(bottleIn != NULL) { #ifdef DEBUG mexPrintf("Receiving: #%s#\n", bottleIn->toString()); std::string strNull = std::string("is NULL: ") + std::string((bottleIn == NULL ? "yes": "no")) + std::string("\n"); mexPrintf(strNull.c_str()); #endif char_T buf03[LENGTH]; mxGetString(ssGetSFcnParam(S, 2), buf03, LENGTH); std::string strVarName(buf03); yarp::os::Value item = bottleIn->get(0); disp('item') disp(item); y[0] = item; } }
wxString wxExpandEnvVars(const wxString& str) { wxString strResult; strResult.Alloc(str.length()); size_t m; for ( size_t n = 0; n < str.length(); n++ ) { switch ( str[n].GetValue() ) { #ifdef __WXMSW__ case wxT('%'): #endif //WINDOWS case wxT('$'): { Bracket bracket; #ifdef __WXMSW__ if ( str[n] == wxT('%') ) bracket = Bracket_Windows; else #endif //WINDOWS if ( n == str.length() - 1 ) { bracket = Bracket_None; } else { switch ( str[n + 1].GetValue() ) { case wxT('('): bracket = Bracket_Normal; n++; // skip the bracket break; case wxT('{'): bracket = Bracket_Curly; n++; // skip the bracket break; default: bracket = Bracket_None; } } m = n + 1; while ( m < str.length() && (wxIsalnum(str[m]) || str[m] == wxT('_')) ) m++; wxString strVarName(str.c_str() + n + 1, m - n - 1); #ifdef __WXWINCE__ const bool expanded = false; #else // NB: use wxGetEnv instead of wxGetenv as otherwise variables // set through wxSetEnv may not be read correctly! bool expanded = false; wxString tmp; if (wxGetEnv(strVarName, &tmp)) { strResult += tmp; expanded = true; } else #endif { // variable doesn't exist => don't change anything #ifdef __WXMSW__ if ( bracket != Bracket_Windows ) #endif if ( bracket != Bracket_None ) strResult << str[n - 1]; strResult << str[n] << strVarName; } // check the closing bracket if ( bracket != Bracket_None ) { if ( m == str.length() || str[m] != (wxChar)bracket ) { // under MSW it's common to have '%' characters in the registry // and it's annoying to have warnings about them each time, so // ignroe them silently if they are not used for env vars // // under Unix, OTOH, this warning could be useful for the user to // understand why isn't the variable expanded as intended #ifndef __WXMSW__ wxLogWarning(_("Environment variables expansion failed: missing '%c' at position %u in '%s'."), (char)bracket, (unsigned int) (m + 1), str.c_str()); #endif // __WXMSW__ } else { // skip closing bracket unless the variables wasn't expanded if ( !expanded ) strResult << (wxChar)bracket; m++; } } n = m - 1; // skip variable name } break; case wxT('\\'): // backslash can be used to suppress special meaning of % and $ if ( n != str.length() - 1 && (str[n + 1] == wxT('%') || str[n + 1] == wxT('$')) ) { strResult += str[++n]; break; } //else: fall through default: strResult += str[n]; } } return strResult; }