// // Assignment operator // Variant & Variant::operator= (const char * value) { freeValue(); m_Type = String; assignString(value ? value : "", value ? strlen(value) : 0); return *this; }
// // Assignment operator // Variant & Variant::operator= (const wchar_t * value) { freeValue(); m_Type = WideString; assignString(value ? value : L"", value ? wcslen(value) : 0); return *this; }
// // Assignment operator // Variant & Variant::operator= (const std::wstring & value) { freeValue(); m_Type = WideString; assignString(value.data(), value.length()); return *this; }
// // Assigns value of the specified variant to this variant // void Variant::assignVariant(const Variant & src) { m_Type = src.m_Type; switch (m_Type) { case String: assignString((char *)src.m_Value._string.data, src.m_Value._string.length); break; case WideString: assignString((wchar_t *)src.m_Value._string.data, src.m_Value._string.length); break; default: memcpy(&m_Value, &src.m_Value, sizeof(m_Value)); } }
void solve(char* str1, char *str2, char *str){ int len1 = strlen(str1); int len2 = strlen(str2); int len3 = strlen(str); int sol1[MAXSIZE],sol2[MAXSIZE],sol3[len3+1]; int r=0,temp=-1,l=1,per,num1,num2; printf("%s + %s = %s\n",str1,str2,str); if(len1 == len2){ /*assigning numbers to 1st string*/ assignString(str1,sol1); /*assigning numbers to 2nd string*/ assignString(str2,sol2); /*Check for solution*/ check(str1, str2, str, sol1, sol2); }else{ printf("\nboth strings are of different length.\n\n"); exit(1); } }
static void presetVal(varInfo *v, int type) { v->active = ACT_ON; v->subtype = type; v->prot = preset[type].Prot; v->Dgroup = preset[type].Dgroup; v->Ggroup = preset[type].Ggroup; v->minVal = preset[type].minVal; v->maxVal = preset[type].maxVal; v->step = preset[type].step; v->R = NULL; v->E = NULL; v->T.size = 0; v->ET.size = 0; v->T.basicType = preset[type].type; v->ET.basicType= v->T.basicType; if(v->T.basicType == T_REAL) /* set inital value to zero */ assignReal(0.0,v,0); if(v->T.basicType == T_STRING) /* set inital value to null */ assignString("",v,0); }
int P_loadVar(int tree, char *name, vInfo *v, int *fd) { char buf[4097]; double dvalue; int i; int length; int nread; symbol **root; varInfo *newv; /* If the variable was passed as a system global, store it in the global variable tree. */ /* if lockfreq is passed from the system global and global annouce the fact and abort */ if (tree==SYSTEMGLOBAL) /* break if in two for speed,avoid strcmp if possible */ { if (strcmp(name,"lockfreq") == 0) { if (!havelockfreq) havelockfreq=1; else { text_error( "lockfreq in both conpar and global, remove occurrence in global.\n"); havelockfreq = -1; } } } if (tree==GLOBAL) /* break if in two for speed,avoid strcmp if possible */ { if (strcmp(name,"lockfreq") == 0) { if (!havelockfreq) havelockfreq=1; else { text_error( "lockfreq in both conpar and global, remove occurrence in global.\n"); havelockfreq = -1; } } } if (tree==SYSTEMGLOBAL) tree = GLOBAL; if ( (root = getTreeRoot(getRoot(tree))) ) { if ( (newv=rfindVar(name,root)) ) /* if variable exists, get rid of it*/ { if (newv->T.basicType == T_STRING) { disposeStringRvals(newv->R); disposeStringRvals(newv->E); } else { disposeRealRvals(newv->R); disposeRealRvals(newv->E); } newv->R = NULL; newv->E = NULL; newv->T.size = newv->ET.size = 0; newv->T.basicType = v->basicType; newv->ET.basicType = v->basicType; } else newv = RcreateVar(name,root,v->basicType); /* create the variable */ newv->active = v->active; newv->subtype= v->subtype; newv->Dgroup = v->Dgroup; newv->Ggroup = v->group; newv->prot = v->prot; newv->minVal = v->minVal; newv->maxVal = v->maxVal; newv->step = v->step; if (v->basicType == T_STRING) { for (i=0 ; i<v->size ; i++) { nread = read(fd[0],&length,sizeof(int)); nread = read(fd[0],buf,length); buf[length] = '\0'; if (bgflag > 2) fprintf(stderr,"bg: STRING[%d] = \"%s\"\n",i,buf); assignString(buf,newv,i+1); } /* copy over enumerals */ /* ---------------------- deleted for (i=0 ; i<v->Esize ; i++) { nread = read(fd[0],&length,sizeof(int)); nread = read(fd[0],buf,length); buf[length] = NULL; if (bgflag > 2) fprintf(stderr,"bg: Enum STRING[%d] = \"%s\"\n",i,buf); assignEString(buf,newv,i+1); } +------------------------- */ } else /* assume T_REAL */ { for (i=0 ; i<v->size ; i++) { nread = read(fd[0],&dvalue,sizeof(double)); /* convert usec pulse values in to seconds */ if (v->subtype == ST_PULSE) /* pulse in usec */ { dvalue *= 1.0e-6; /* now in sec. */ } if (bgflag > 2) fprintf(stderr,"bg: REAL[%d] = \"%g\"\n",i,dvalue); assignReal(dvalue,newv,i+1); } /* copy over enumeral values */ /* ---------------------- deleted for (i=0 ; i<v->Esize ; i++) { nread = read(fd[0],&dvalue,sizeof(double)); if (bgflag > 2) fprintf(stderr,"bg: Enum REAL[%d] = \"%g\"\n",i,dvalue); assignEReal(dvalue,newv,i+1); } +------------------------- */ } } else { fprintf(stderr,"P_loadVar: fatal error, cannot find tree %d\n",tree); havelockfreq = -1; /* make PSG abort */ } return(0); }
// // Constructor // Variant::Variant(const wchar_t * value) : m_Type(WideString) { assignString(value ? value : L"", value ? wcslen(value) : 0); }
// // Constructor // Variant::Variant(const char * value) : m_Type(String) { assignString(value ? value : "", value ? strlen(value) : 0); }
// // Constructor // Variant::Variant(const std::wstring & value) : m_Type(WideString) { assignString(value.data(), value.length()); }
int assignPair(pair *p, varInfo *v, int i) { Rval *r; DPRINT3(3,"assignPair: pair 0x%08x to var 0x%08x[%d]...\n",p,v,i); DSHOWPAIR(3,"assignPair: ",p); DSHOWVAR(3,"assignPair: ",v); if (v) { switch (p->T.basicType) { case T_UNDEF: return(0); case T_REAL: r = p->R; if (v->prot & P_ARR) { if ((r = r->next) || (i > 1)) { WerrprintfWithPos("cannot array parameter"); return(0); } r = p->R; } while (r) { if (assignReal(r->v.r,v,i)) { r = r->next; if (i == 0) i++; /* bump index to 2 */ i += 1; } else { return(0); } } DPRINT0(3,"assignPair: ...after\n"); DSHOWVAR(3,"assignPair: ",v); return(1); case T_STRING: r = p->R; if (v->prot & P_ARR) { if ((r = r->next) || (i > 1)) { WerrprintfWithPos("cannot array parameter"); return(0); } r = p->R; } while (r) if (assignString(r->v.s,v,i)) { r = r->next; if (i == 0) i++; /* bump index to 2 */ i += 1; } else return(0); DPRINT0(3,"assignPair: ...after\n"); DSHOWVAR(3,"assignPair: ",v); return(1); default: WerrprintfWithPos("unknown parameter assignment with basictype %d",p->T.basicType); return(0); } } return(0); }
bool assignString(unsigned char& dest, const std::string& data) { return assignString((char&)dest, data); }
bool assignString(unsigned long long& dest, const std::string& data) { return assignString((long long&)dest, data); }
bool assignString(unsigned int& dest, const std::string& data) { return assignString((int&)dest, data); }
/* Inherits from : - ======================================================================*/ fmiComponent fmiInstantiateModel(fmiString instanceName, fmiString GUID, fmiCallbackFunctions memory, fmiBoolean loggingOn) { /* Declaration of internal variables */ fmiComponentStructure* component; /* Internal data structure */ init_struct dim_values; /* Structure containing size of variables */ size_t i; /* Loop variable */ size_t dim_string[] = {7}; dim_values.nb_boolSVar = 0; dim_values.nb_intSVar = 11; dim_values.nb_realSVar = 29; dim_values.nb_stringSVar = 1; dim_values.nb_state_var = 2; dim_values.dim_string = dim_string; dim_values.GUID = GUID; dim_values.ref_GUID = "5922B96112515EF2"; dim_values.ModelName = "SHUNTDCMOTORWITHSTARTINGRESISTOR"; dim_values.memory = memory; dim_values.loggingOn = loggingOn; dim_values.nb_integer_stores = 0; dim_values.nb_real_stores = 0; dim_values.nb_pointer_stores = 1; component = NULL; /* Initialize pointer to fmiComponentStructure */ if ((component = commonInit(&dim_values)) == 0) /* Initiate variables */ { if (loggingOn) { memory.logger(component, instanceName, fmiFatal, "initialization", "Unable to initialize component structure."); } return NULL; } /* State variables */ component->idx_of_state_var[0] = 7; component->deriv_idx[7] = 0; component->idx_of_state_var[1] = 8; component->deriv_idx[8] = 1; /* Initialize var types */ component->real_var_type = (FMITransition*)memory.allocateMemory(29,sizeof(FMITransition)); for (i = 0 ; i < 29 ; ++i) { component->real_var_type[i] = T_unknown; } component->integer_var_type = (FMITransition*)memory.allocateMemory(19,sizeof(FMITransition)); for (i = 0 ; i < 19 ; ++i) { component->integer_var_type[i] = T_unknown; } component->boolean_var_type = NULL; component->string_var_type = (FMITransition*)memory.allocateMemory(1,sizeof(FMITransition)); for (i = 0 ; i < 1 ; ++i) { component->string_var_type[i] = T_unknown; } component->real_var_type[0] = T_fmiSetINI; component->real_var_type[1] = T_fmiSetINI; component->real_var_type[2] = T_fmiSetINI; component->real_var_type[3] = T_fmiSetINI; component->real_var_type[4] = T_fmiSetINI; component->real_var_type[5] = T_fmiSetINI; component->real_var_type[6] = T_fmiSetINI; component->real_var_type[7] = T_fmiSetINI; component->real_var_type[8] = T_fmiSetINI; component->integer_var_type[4] = T_fmiSetINI; component->integer_var_type[5] = T_fmiSetINI; component->integer_var_type[6] = T_fmiSetINI; component->string_var_type[0] = T_fmiSetINI; component->integer_var_type[0] = T_fmiSetINI; component->integer_var_type[1] = T_fmiSetINI; component->integer_var_type[2] = T_fmiSetINI; component->integer_var_type[3] = T_fmiSetINI; component->integer_var_type[7] = T_fmiSetINI; component->integer_var_type[8] = T_fmiSetINI; component->integer_var_type[9] = T_fmiSetINI; component->integer_var_type[10] = T_fmiSetINI; /* Initialize integer variables to their start values */ component->intSVar[0] = 1; /* x3 (event iteration type) */ component->intSVar[1] = 1; /* x6 (linear system solver logging) */ component->intSVar[2] = 3; /* x5 (logged events) */ component->intSVar[3] = 1; /* systemsettingssteploglevel (logged submodel calls) */ component->intSVar[4] = 10; /* x2 (maximum number of event iterations) */ component->intSVar[5] = 10; /* x14 (maximum number of mixed system solver iterations) */ component->intSVar[6] = 100; /* x11 (maximum number of nonlinear system solver iterations) */ component->intSVar[7] = 1; /* x15 (mixed system solver logging) */ component->intSVar[8] = 2; /* systemsettingsevalloglevel (model evaluation logging) */ component->intSVar[9] = 1; /* x13 (nonlinear system solver logging) */ component->intSVar[10] = 1; /* x12 (use backtraking in nonlinear system solver) */ /* Initialize enumeration variables to their start values */ component->intSVar[0] = 1; /* x3 (event iteration type) */ component->intSVar[1] = 1; /* x6 (linear system solver logging) */ component->intSVar[2] = 3; /* x5 (logged events) */ component->intSVar[3] = 1; /* systemsettingssteploglevel (logged submodel calls) */ component->intSVar[7] = 1; /* x15 (mixed system solver logging) */ component->intSVar[8] = 2; /* systemsettingsevalloglevel (model evaluation logging) */ component->intSVar[9] = 1; /* x13 (nonlinear system solver logging) */ component->intSVar[10] = 1; /* x12 (use backtraking in nonlinear system solver) */ /* Initialize real variables to their start values */ component->realSVar[0] = 0.00000000000000e+000; /* ifieldstart (ifield - fixed start value) */ component->realSVar[1] = 1.00000000000000e-005; /* x7 (nonlinear system solver function evaluation accuracy) */ component->realSVar[2] = 1.00000000000000e-005; /* x10 (nonlinear system solver gradient tolerance) */ component->realSVar[3] = 1.00000000000000e-014; /* x9 (nonlinear system solver step tolerance) */ component->realSVar[4] = 1.00000000000000e-012; /* x8 (nonlinear system solver value tolerance) */ component->realSVar[5] = 0.00000000000000e+000; /* speedstart (speed - fixed start value) */ component->realSVar[6] = 1.00000000000000e-015; /* x4 (zero crossing hysteresis) */ component->realSVar[7] = 0.00000000000000e+000; /* ifield (ifield - Field current) */ component->realSVar[8] = 0.00000000000000e+000; /* speed (speed - Rotary speed) */ /* Initialize string variables to their start values */ assignString(component, 0, "amo.log"); /* systemsettingslogfilename (log file name) */ component->verbose_level = VERBOSE_LEVEL; component->instanceName = component->memory.allocateMemory(strlen(instanceName)+1, sizeof(char)); strcpy(component->instanceName, instanceName); if ((component->status == fmiFatal) || (component->status == fmiError)) /* Update status if necessary */ { AME_status = fmiError; } return component; }