vector<Interval> merge(vector<Interval> &intervals) { // Start typing your C/C++ solution below // DO NOT write int main() function if (intervals.size()<=1) { return intervals; } sort(intervals.begin(), intervals.end(), comp); vector<Interval> ret; int cbegin = intervals[0].start; int cend = intervals[0].end; for (int i = 1; i< intervals.size(); i++) { if (intervals[i].start>cend) { Interval ival(cbegin, cend); ret.push_back(ival); cbegin=intervals[i].start; cend = intervals[i].end; } else { if (intervals[i].end>cend) cend = intervals[i].end; } } Interval ival(cbegin, cend); ret.push_back(ival); return ret; }
TEST(Type, OptCouldBe) { for (auto& x : optionals) EXPECT_TRUE(x.couldBe(unopt(x))); auto true_cases = std::initializer_list<std::pair<Type,Type>> { { opt(sval(s_test.get())), TStr }, { opt(sval(s_test.get())), TInitNull }, { opt(sval(s_test.get())), TSStr }, { opt(sval(s_test.get())), sval(s_test.get()) }, { opt(ival(2)), TInt }, { opt(ival(2)), TInitNull }, { opt(ival(2)), ival(2) }, { opt(dval(2.0)), TDbl }, { opt(dval(2.0)), TInitNull }, { opt(dval(2.0)), dval(2) }, { opt(TFalse), TBool }, { opt(TFalse), TFalse }, { opt(TTrue), TBool }, { opt(TTrue), TTrue }, }; auto false_cases = std::initializer_list<std::pair<Type,Type>> { { opt(sval(s_test.get())), TCStr }, { opt(ival(2)), TDbl }, { opt(dval(2.0)), TInt }, { opt(TFalse), TTrue }, { opt(TTrue), TFalse }, }; for (auto kv : true_cases) { EXPECT_TRUE(kv.first.couldBe(kv.second)) << show(kv.first) << " couldBe " << show(kv.second) << " should be true"; } for (auto kv : false_cases) { EXPECT_TRUE(!kv.first.couldBe(kv.second)) << show(kv.first) << " couldBe " << show(kv.second) << " should be false"; } for (auto kv : boost::join(true_cases, false_cases)) { EXPECT_EQ(kv.first.couldBe(kv.second), kv.second.couldBe(kv.first)) << show(kv.first) << " couldBe " << show(kv.second) << " wasn't reflexive"; } for (auto& x : optionals) { EXPECT_TRUE(x.couldBe(unopt(x))); EXPECT_TRUE(x.couldBe(TInitNull)); EXPECT_TRUE(!x.couldBe(TUninit)); for (auto& y : optionals) { EXPECT_TRUE(x.couldBe(y)); } } }
std::string cGoldBase::sval() { std::stringstream ss; ss << ival(); return ss.str(); }
std::unique_ptr<Value> FunctionValueNode::getValue(std::unique_ptr<Value> val) const { switch (val->getType()) { case Value::String: { StringValue& sval(static_cast<StringValue&>(*val)); if (_function == LOWERCASE) { return std::unique_ptr<Value>(new StringValue( vespalib::LowerCase::convert(sval.getValue()))); } else if (_function == HASH) { return std::unique_ptr<Value>(new IntegerValue( hash(sval.getValue().c_str(), sval.getValue().size()), false)); } break; } case Value::Float: { FloatValue& fval(static_cast<FloatValue&>(*val)); if (_function == HASH) { FloatValue::ValueType ffval = fval.getValue(); return std::unique_ptr<Value>(new IntegerValue( hash(&ffval, sizeof(ffval)), false)); } else if (_function == ABS) { FloatValue::ValueType ffval = fval.getValue(); if (ffval < 0) ffval *= -1; return std::unique_ptr<Value>(new FloatValue(ffval)); } break; } case Value::Integer: { IntegerValue& ival(static_cast<IntegerValue&>(*val)); if (_function == HASH) { IntegerValue::ValueType iival = ival.getValue(); return std::unique_ptr<Value>(new IntegerValue( hash(&iival, sizeof(iival)), false)); } else if (_function == ABS) { IntegerValue::ValueType iival = ival.getValue(); if (iival < 0) iival *= -1; return std::unique_ptr<Value>(new IntegerValue(iival, false)); } break; } case Value::Bucket: { throw ParsingFailedException( "No functioncalls are allowed on value of type bucket", VESPA_STRLOC); break; } case Value::Array: break; case Value::Struct: break; case Value::Invalid: break; case Value::Null: break; } return std::unique_ptr<Value>(new InvalidValue); }
TEST(Type, OptUnionOf) { EXPECT_EQ(opt(ival(2)), union_of(ival(2), TInitNull)); EXPECT_EQ(opt(dval(2.0)), union_of(TInitNull, dval(2.0))); EXPECT_EQ(opt(sval(s_test.get())), union_of(sval(s_test.get()), TInitNull)); EXPECT_EQ(opt(sval(s_test.get())), union_of(TInitNull, sval(s_test.get()))); EXPECT_EQ(TOptBool, union_of(TOptFalse, TOptTrue)); EXPECT_EQ(TOptBool, union_of(TOptTrue, TOptFalse)); EXPECT_EQ(TOptCArr, union_of(TCArr, TInitNull)); EXPECT_EQ(TOptCArr, union_of(TInitNull, TCArr)); EXPECT_EQ(TOptSArr, union_of(TInitNull, TOptSArr)); EXPECT_EQ(TOptSArr, union_of(TOptSArr, TInitNull)); EXPECT_EQ(TOptArr, union_of(TOptArr, TInitNull)); EXPECT_EQ(TOptArr, union_of(TInitNull, TOptArr)); EXPECT_EQ(TInitUnc, union_of(TOptSArr, TSStr)); EXPECT_EQ(TInitUnc, union_of(TSStr, TOptSArr)); }
TEST(Type, OptTV) { EXPECT_TRUE(!tv(opt(ival(2)))); EXPECT_TRUE(!tv(opt(sval(s_test.get())))); EXPECT_TRUE(!tv(opt(dval(2.0)))); EXPECT_TRUE(!tv(TOptFalse)); EXPECT_TRUE(!tv(TOptTrue)); for (auto& x : optionals) { EXPECT_TRUE(!tv(x)); } }
void testApp::update() { int fpsI = fps; ival(gui.getControlById("fps")->value) = fpsI; //for(int i = 0; i < NUM_AUDIO_CHANNELS; i++) { // volumes[i] = gains[i]*ABS(sin(ofGetElapsedTimef()+i)); //} audioMutex.lock(); audioFps = fps; smoothing = 0.9999 + gui.getControlById("smoothing")->floatValue()*0.0001; exponent = pow(2, gui.getControlById("exponent")->floatValue()); audioMutex.unlock(); }
string Value::ToString(ValueType vtype, PrintPrefs &pp) const { if (IsRefNil(vtype)) return ref_ ? ref_->ToString(pp) : "nil"; switch (vtype) { case V_INT: return to_string(ival()); case V_FLOAT: return to_string_float(fval(), pp.decimals); case V_FUNCTION: return "<FUNCTION>"; default: return string("(") + BaseTypeName(vtype) + ")"; } }
// Associate a range of addresses with a dynamically allocated data structure. static void assoc_addresses_with_dstruct (const bf_symbol_info_t* syminfo, void* old_baseptr, void* baseptr, uint64_t numaddrs, bool known_alloc) { // Find an existing set of counters for the same source-code location. If no // such counters exist, allocate a new set. DataStructCounters* counters; // Counters associated with the data structure if (old_baseptr == nullptr) { // Common case -- we haven't seen the old base address before (because it's // presumably the same as the new address, and that's what was just // allocated). auto count_iter = id_to_counters->find(syminfo->ID); if (count_iter == id_to_counters->end()) { // Not found -- allocate new counters. counters = new DataStructCounters(*syminfo, numaddrs, known_alloc); (*id_to_counters)[syminfo->ID] = counters; } else { // Found -- increment the size of the data structure and its tallies. counters = count_iter->second; counters->current_size += numaddrs; if (counters->current_size > counters->max_size) counters->max_size = counters->current_size; counters->bytes_alloced += numaddrs; counters->num_allocs++; } } else { // Case of realloc -- reuse the old counters, but remove the old address // range, and subtract off the bytes previously allocated. static Interval<uint64_t> search_addr(0, 0); search_addr.lower = search_addr.upper = uint64_t(uintptr_t(old_baseptr)); auto old_iter = data_structs->find(search_addr); counters = old_iter->second; Interval<uint64_t> old_interval = old_iter->first; counters->current_size -= old_interval.upper - old_interval.lower + 1; counters->current_size += numaddrs; if (counters->current_size > counters->max_size) counters->max_size = counters->current_size; counters->bytes_alloced += numaddrs; counters->num_allocs++; data_structs->erase(old_interval); } // Associate the new range of addresses with the old (or just created) // counters. uint64_t baseaddr = uint64_t(uintptr_t(baseptr)); Interval<uint64_t> ival(baseaddr, baseaddr + numaddrs - 1); (*data_structs)[ival] = counters; }
Type typeIncDec(IncDecOp op, Type t) { auto const overflowToDbl = isIncDecO(op); auto const val = tv(t); if (!val) { // Doubles always stay doubles if (t.subtypeOf(TDbl)) return TDbl; // Ints stay ints unless they can overflow to doubles if (t.subtypeOf(TInt)) { return overflowToDbl ? TNum : TInt; } // Null goes to 1 on ++, stays null on --. Uninit is folded to init. if (t.subtypeOf(TNull)) { return isInc(op) ? ival(1) : TInitNull; } // No-op on bool, array, resource, object. if (t.subtypeOfAny(TBool, TArr, TRes, TObj, TVec, TDict, TKeyset)) return t; // Last unhandled case: strings. These result in Int|Str because of the // behavior on strictly-numeric strings, and we can't express that yet. return TInitCell; } auto const inc = isInc(op); // We can't constprop with this eval_cell, because of the effects // on locals. auto resultTy = eval_cell([inc,overflowToDbl,val] { auto c = *val; if (inc) { (overflowToDbl ? cellIncO : cellInc)(c); } else { (overflowToDbl ? cellDecO : cellDec)(c); } return c; }); if (!resultTy) resultTy = TInitCell; // We may have inferred a TSStr or TSArr with a value here, but at // runtime it will not be static. resultTy = loosen_staticness(*resultTy); return *resultTy; }
/* one child operation */ static void child_op(struct child_struct *child, const char *opname, const char *fname, const char *fname2, char **params, const char *status) { static struct dbench_op prev_op; struct dbench_op op; unsigned i; child->lasttime = timeval_current(); ZERO_STRUCT(op); op.child = child; op.op = opname; op.fname = fname; op.fname2 = fname2; op.status = status; for (i=0;i<sizeof(op.params)/sizeof(op.params[0]);i++) { switch (params[i][0]) { case '*': case '+': op.params[i] = parse_special(params[i], prev_op.params[i]); break; default: op.params[i] = params[i]?ival(params[i]):0; } } prev_op = op; if (strcasecmp(op.op, "Sleep") == 0) { nb_sleep(op.params[0]); return; } for (i=0;nb_ops->ops[i].name;i++) { if (strcasecmp(op.op, nb_ops->ops[i].name) == 0) { nb_ops->ops[i].fn(&op); finish_op(child, &child->ops[i]); return; } } printf("[%u] Unknown operation %s in pid %u\n", child->line, op.op, (unsigned)getpid()); }
/* * tjoin - Interface for users to call join on their threads in SCAM * * @args - The thread ID to join on */ int tjoin (int args) { int tid = ival(car(args)); // Might garbage collect and then wait with pthread_join T_P(); --WorkingThreads; T_V(); pthread_join(Thread[tid], NULL); // I can now garbage collect again T_P(); ++WorkingThreads; T_V(); return newInteger(tid); }
void s_BuildMaskedRanges(CSeqMasker::TMaskList & masks, const CSeq_loc & seqloc, CSeq_id & query_id, TMaskedQueryRegions * mqr, CRef<CSeq_loc> * psl) { TSeqPos query_start = seqloc.GetStart(eExtreme_Positional); // This needs to be examined further for places where a +1, -1, // etc is needed due to biological vs. computer science offset // notations. ITERATE(CSeqMasker::TMaskList, pr, masks) { CRef<CSeq_interval> ival(new CSeq_interval); TSeqPos start = pr->first, end = pr->second; ival->SetFrom (query_start + start); ival->SetTo (query_start + end); ival->SetId (query_id); ival->SetStrand(eNa_strand_both); if (mqr) { CRef<CSeqLocInfo> info_plus (new CSeqLocInfo(&* ival, CSeqLocInfo::eFramePlus1)); mqr->push_back(info_plus); CRef<CSeqLocInfo> info_minus (new CSeqLocInfo(&* ival, CSeqLocInfo::eFrameMinus1)); mqr->push_back(info_minus); } if (psl) { if (psl->Empty()) { psl->Reset(new CSeq_loc); } (**psl).SetPacked_int().Set().push_back(ival); } }
boost::shared_ptr< LogicalQueryPlanNode> Optimizer::logicalRewriteIfNeeded(const boost::shared_ptr<Query>& query, boost::shared_ptr< LogicalQueryPlanNode> instance) { //rewrite load(array,'filename') into store(input(array,'filename'),array) //Note: this rewrite mechanism should be // 1. generic // 2. user-extensible //Note: optimizer also performs rewrites like "sum" -> "sum2(sum)" but we can't do these here because: // 1. they are physical; not logical // 2. they are recursive. We don't want logical rewrites to be recursive. OperatorLibrary *olib = OperatorLibrary::getInstance(); if (instance->getLogicalOperator()->getLogicalName()=="load") { boost::shared_ptr< LogicalOperator> loadOperator = instance->getLogicalOperator(); LogicalOperator::Parameters loadParameters = loadOperator->getParameters(); ArrayDesc outputSchema = loadOperator->getSchema(); boost::shared_ptr< LogicalOperator> inputOperator = olib->createLogicalOperator("input"); inputOperator->setParameters(loadParameters); inputOperator->setSchema(outputSchema); boost::shared_ptr< OperatorParam> paramArrayName = loadParameters[0]; if ( query->getInstancesCount() == 1) { boost::shared_ptr< LogicalOperator> storeOperator = olib->createLogicalOperator("store"); storeOperator->addParameter(paramArrayName); std::vector< ArrayDesc> storeInputSchemas; storeInputSchemas.push_back(inputOperator->getSchema()); storeOperator->setSchema(storeOperator->inferSchema(storeInputSchemas, query)); boost::shared_ptr< LogicalQueryPlanNode> inputInstance( new LogicalQueryPlanNode (instance->getParsingContext(), inputOperator)); boost::shared_ptr< LogicalQueryPlanNode> storeInstance( new LogicalQueryPlanNode (instance->getParsingContext(), storeOperator)); //load instance does not have any children. so the input instance will also have none. assert(instance->getChildren().size()==0); storeInstance->addChild(inputInstance); return storeInstance; } else { LogicalOperator::Parameters sgParams(3); Value ival(TypeLibrary::getType(TID_INT32)); ival.setInt32(psRoundRobin); sgParams[0] = boost::shared_ptr<OperatorParam>( new OperatorParamLogicalExpression(instance->getParsingContext(), boost::shared_ptr<LogicalExpression>(new Constant(instance->getParsingContext(), ival, TID_INT32)), TypeLibrary::getType(TID_INT32), true)); ival.setInt32(-1); sgParams[1] = boost::shared_ptr<OperatorParam>( new OperatorParamLogicalExpression(instance->getParsingContext(), boost::shared_ptr<LogicalExpression>(new Constant(instance->getParsingContext(), ival, TID_INT32)), TypeLibrary::getType(TID_INT32), true)); sgParams[2] = paramArrayName; boost::shared_ptr< LogicalOperator> sgOperator = olib->createLogicalOperator("sg"); sgOperator->setParameters(sgParams); std::vector< ArrayDesc> sgInputSchemas; sgInputSchemas.push_back(inputOperator->getSchema()); sgOperator->setSchema(sgOperator->inferSchema(sgInputSchemas,query)); boost::shared_ptr< LogicalQueryPlanNode> inputInstance( new LogicalQueryPlanNode (instance->getParsingContext(), inputOperator)); boost::shared_ptr< LogicalQueryPlanNode> sgInstance( new LogicalQueryPlanNode (instance->getParsingContext(), sgOperator)); //load instance does not have any children. so the input instance will also have none. assert(instance->getChildren().size()==0); sgInstance->addChild(inputInstance); return sgInstance; } } else if (instance->getLogicalOperator()->getLogicalName()=="sum" || instance->getLogicalOperator()->getLogicalName()=="avg" || instance->getLogicalOperator()->getLogicalName()=="min" || instance->getLogicalOperator()->getLogicalName()=="max" || instance->getLogicalOperator()->getLogicalName()=="stdev" || instance->getLogicalOperator()->getLogicalName()=="var" || instance->getLogicalOperator()->getLogicalName()=="count") { boost::shared_ptr< LogicalOperator> oldStyleOperator = instance->getLogicalOperator(); boost::shared_ptr< LogicalOperator> aggOperator = olib->createLogicalOperator("aggregate"); aggOperator->setSchema(oldStyleOperator->getSchema()); LogicalOperator::Parameters oldStyleParams = oldStyleOperator->getParameters(); if (instance->getLogicalOperator()->getLogicalName()=="count") { shared_ptr<OperatorParam> asterisk (new OperatorParamAsterisk(instance->getParsingContext())); shared_ptr<OperatorParam> aggCall ( new OperatorParamAggregateCall (instance->getParsingContext(), instance->getLogicalOperator()->getLogicalName(), asterisk, "")); aggOperator->addParameter(aggCall); } else if (oldStyleParams.size() == 0) { ArrayDesc const& inputSchema = instance->getChildren()[0]->getLogicalOperator()->getSchema(); shared_ptr<OperatorParamReference> attRef ( new OperatorParamAttributeReference(instance->getParsingContext(), inputSchema.getName(), inputSchema.getAttributes()[0].getName(), true)); attRef->setInputNo(0); attRef->setObjectNo(0); shared_ptr<OperatorParam> aggCall ( new OperatorParamAggregateCall (instance->getParsingContext(), instance->getLogicalOperator()->getLogicalName(), attRef, "")); aggOperator->addParameter(aggCall); } for (size_t i =0; i<oldStyleParams.size(); i++) { if (oldStyleParams[i]->getParamType() == PARAM_ATTRIBUTE_REF) { shared_ptr<OperatorParam> aggCall ( new OperatorParamAggregateCall (oldStyleParams[i]->getParsingContext(), instance->getLogicalOperator()->getLogicalName(), oldStyleParams[i], "")); aggOperator->addParameter(aggCall); } else if (oldStyleParams[i]->getParamType() == PARAM_DIMENSION_REF) { aggOperator->addParameter(oldStyleParams[i]); } } boost::shared_ptr< LogicalQueryPlanNode> aggInstance( new LogicalQueryPlanNode (instance->getParsingContext(), aggOperator)); assert(instance->getChildren().size() == 1); aggInstance->addChild(instance->getChildren()[0]); return aggInstance; } else { return instance; } }
void GuiControl::setValue(int i) { ival(value) = i; }
Type typeToInt(Type ty) { if (auto const v = tv(ty)) return ival(cellToInt(*v)); if (ty.subtypeOf(TNull)) return ival(0); return TInt; }
int xmlgui::Control::getInt() { return ival(value); }
TEST(Type, SpecificExamples) { // Random examples to stress option types, values, etc: EXPECT_TRUE(!TInt.subtypeOf(ival(1))); EXPECT_TRUE(TInitCell.couldBe(ival(1))); EXPECT_TRUE(TInitCell.subtypeOf(TGen)); EXPECT_TRUE(ival(2).subtypeOf(TInt)); EXPECT_TRUE(!ival(2).subtypeOf(TBool)); EXPECT_TRUE(ival(3).subtypeOf(TOptInt)); EXPECT_TRUE(TInt.subtypeOf(TOptInt)); EXPECT_TRUE(!TBool.subtypeOf(TOptInt)); EXPECT_TRUE(TInitNull.subtypeOf(TOptInt)); EXPECT_TRUE(!TNull.subtypeOf(TOptInt)); EXPECT_TRUE(TNull.couldBe(TOptInt)); EXPECT_TRUE(TNull.couldBe(TOptBool)); EXPECT_TRUE(TInitNull.subtypeOf(TInitCell)); EXPECT_TRUE(TInitNull.subtypeOf(TCell)); EXPECT_TRUE(!TUninit.subtypeOf(TInitNull)); EXPECT_TRUE(ival(3).subtypeOf(TOptInt)); EXPECT_TRUE(ival(3).subtypeOf(opt(ival(3)))); EXPECT_TRUE(ival(3).couldBe(opt(ival(3)))); EXPECT_TRUE(ival(3).couldBe(TInt)); EXPECT_TRUE(TInitNull.couldBe(opt(ival(3)))); EXPECT_TRUE(TNull.couldBe(opt(ival(3)))); EXPECT_TRUE(TInitNull.subtypeOf(opt(ival(3)))); EXPECT_TRUE(!TNull.subtypeOf(opt(ival(3)))); EXPECT_EQ(TStr, union_of(sval(s_test.get()), TCStr)); EXPECT_EQ(TStr, union_of(TCStr, sval(s_test.get()))); EXPECT_EQ(TGen, union_of(TRef, TUninit)); }
void gen3Dfdfhdr(struct data *d,int image,int slab,int echo,int receiver,int type,int precision) { char str[100]; int cycle,n,id; double pro,ppe,pss,psi,phi,theta; double cospsi,cosphi,costheta; double sinpsi,sinphi,sintheta; double or0,or1,or2,or3,or4,or5,or6,or7,or8; double value; int dim1,dim2,dim3,ns,nr; int ne; int i,j,add; int align=0,hdrlen,pad_cnt; int *intval; double *dblval; char **strval; int datamode; /* Check that type is valid */ if (!validtype(type) || (type == VJ)) { fprintf(stderr,"\n%s: %s()\n",__FILE__,__FUNCTION__); fprintf(stderr," Invalid 6th argument %s(*,*,*,*,*,'type',*)\n",__FUNCTION__); fflush(stderr); return; } datamode=FID; /* If FT has been done flag it as IMAGE */ if ((d->dimstatus[0] & FFT) || (d->dimstatus[1] & FFT) || (d->dimstatus[2] & FFT)) datamode=IMAGE; /* Allocate for header */ if ((d->fdfhdr = (char *)malloc(FDFHDRLEN*sizeof(char))) == NULL) nomem(__FILE__,__FUNCTION__,__LINE__); /* Data dimensions */ dim1=d->np/2; dim2=d->nv; dim3=d->nv2; nr=d->nr; /* Number of echoes */ ne=(int)*val("ne",&d->p); if (ne < 1) ne=1; /* Set ne to 1 if 'ne' does not exist */ /* Number of slices (slabs) */ ns=nvals("pss",&d->p); if (ns < 1) ns=1; /* Set ns to 1 if 'ns' does not exist */ /* Allow for compressed multi-echo loop and multiple slabs */ /* image=(volindex-IMAGEOFFSET)/(ne*ns); slab=((volindex-IMAGEOFFSET)/ne)%ns; echo=(volindex-IMAGEOFFSET)%ne; */ /* Set up for orientation */ pro=getelem(d,"pro",image); ppe=getelem(d,"ppe",image); pss=sliceposition(d,slab); /* position in 2nd phase encode dimension */ psi=getelem(d,"psi",image); phi=getelem(d,"phi",image); theta=getelem(d,"theta",image); /* Create header */ sprintf(d->fdfhdr,"#!/usr/local/fdf/startup\n"); strcat(d->fdfhdr,"float rank = 3;\n"); strcat(d->fdfhdr,"char *spatial_rank = \"3dfov\";\n"); switch(precision) { case FLT32: /* 32 bit float */ strcat(d->fdfhdr,"char *storage = \"float\";\n"); strcat(d->fdfhdr,"float bits = 32;\n"); break; case DBL64: /* 64 bit double */ strcat(d->fdfhdr,"char *storage = \"double\";\n"); strcat(d->fdfhdr,"float bits = 64;\n"); break; default: strcat(d->fdfhdr,"char *storage = \"not supported\";\n"); strcat(d->fdfhdr,"float bits = ?;\n"); break; } /* end precision switch */ switch(type) { case MG: /* Magnitude */ strcat(d->fdfhdr,"char *type = \"absval\";\n"); break; case RE: /* Real */ strcat(d->fdfhdr,"char *type = \"real\";\n"); break; case IM: /* Imaginary */ strcat(d->fdfhdr,"char *type = \"imag\";\n"); break; case PH: /* Phase */ strcat(d->fdfhdr,"char *type = \"phase\";\n"); break; case MK: /* Mask */ strcat(d->fdfhdr,"char *type = \"mask\";\n"); break; case RMK: /* Reverse mask of magnitude */ strcat(d->fdfhdr,"char *type = \"absval\";\n"); break; case SM: /* Sensitivity map */ strcat(d->fdfhdr,"char *type = \"smap\";\n"); break; case GF: /* Geometry factor */ strcat(d->fdfhdr,"char *type = \"gmap\";\n"); break; case RS: /* Relative SNR */ strcat(d->fdfhdr,"char *type = \"rsnrmap\";\n"); break; default: break; } /* end type switch */ sprintf(str,"float matrix[] = {%d, %d, %d};\n",dim1,dim2,dim3); strcat(d->fdfhdr,str); switch(datamode) { case IMAGE: /* Image */ strcat(d->fdfhdr,"char *abscissa[] = {\"cm\", \"cm\", \"cm\"};\n"); break; case FID: /* FID */ /* strcat(d->fdfhdr,"char *abscissa[] = {\"s\", \"s\", \"s\"};\n"); */ /* We must define as for image space to get a good display in VnmrJ */ strcat(d->fdfhdr,"char *abscissa[] = {\"cm\", \"cm\", \"cm\"};\n"); break; default: strcat(d->fdfhdr,"char *abscissa[] = {\"cm\", \"cm\", \"cm\"};\n"); break; } /* end datamode switch */ switch(type) { case PH: /* Phase */ strcat(d->fdfhdr,"char *ordinate[] = { \"radians\" };\n"); break; case MK: /* Mask */ strcat(d->fdfhdr,"char *ordinate[] = { \"mask\" };\n"); break; default: strcat(d->fdfhdr,"char *ordinate[] = { \"intensity\" };\n"); break; } /* end type switch */ switch(datamode) { case IMAGE: /* Image */ sprintf(str,"float span[] = {%.6f, %.6f, %.6f};\n",*val("lro",&d->p),*val("lpe",&d->p),*val("lpe2",&d->p)); strcat(d->fdfhdr,str); sprintf(str,"float origin[] = {%.6f,%.6f,%.6f};\n",-pro-*val("lro",&d->p)/2,ppe-*val("lpe",&d->p)/2,pss-*val("lpe2",&d->p)/2); strcat(d->fdfhdr,str); break; case FID: /* FID */ /* sprintf(str,"float span[] = {%.6f, %.6f, %.6f};\n",dim1/(*val("sw",&d->p)),dim2/(*val("sw1",&d->p)),dim3/(*val("sw2",&d->p))); strcat(d->fdfhdr,str); sprintf(str,"float origin[] = {%.6f, %.6f, %.6f};\n",0.0,0.0,0.0); strcat(d->fdfhdr,str); */ /* We must define as for image space to get a good display in VnmrJ */ sprintf(str,"float span[] = {%.6f, %.6f, %.6f};\n",*val("lro",&d->p),*val("lpe",&d->p),*val("lpe2",&d->p)); strcat(d->fdfhdr,str); sprintf(str,"float origin[] = {%.6f,%.6f,%.6f};\n",-pro-*val("lro",&d->p)/2,ppe-*val("lpe",&d->p)/2,pss-*val("lpe2",&d->p)/2); strcat(d->fdfhdr,str); break; default: sprintf(str,"float span[] = {%.6f, %.6f, %.6f};\n",*val("lro",&d->p),*val("lpe",&d->p),*val("lpe2",&d->p)); strcat(d->fdfhdr,str); sprintf(str,"float origin[] = {%.6f,%.6f,%.6f};\n",-pro-*val("lro",&d->p)/2,ppe-*val("lpe",&d->p)/2,pss-*val("lpe2",&d->p)/2); strcat(d->fdfhdr,str); break; } /* end datamode switch */ sprintf(str,"char *nucleus[] = {\"%s\",\"%s\"};\n",*sval("tn",&d->p),*sval("dn",&d->p)); strcat(d->fdfhdr,str); sprintf(str,"float nucfreq[] = {%.6f,%.6f};\n",*val("sfrq",&d->p),*val("dfrq",&d->p)); strcat(d->fdfhdr,str); switch(datamode) { case IMAGE: /* Image */ sprintf(str,"float location[] = {%.6f,%.6f,%.6f};\n",-pro,ppe,pss); strcat(d->fdfhdr,str); sprintf(str,"float roi[] = {%.6f,%.6f,%.6f};\n",*val("lro",&d->p),*val("lpe",&d->p),*val("lpe2",&d->p)); strcat(d->fdfhdr,str); break; case FID: /* FID */ sprintf(str,"float location[] = {%.6f,%.6f,%.6f};\n",-pro,ppe,pss); strcat(d->fdfhdr,str); sprintf(str,"float roi[] = {%.6f,%.6f,%.6f};\n",dim1/(*val("sw",&d->p)),dim2/(*val("sw1",&d->p)),dim3/(*val("sw2",&d->p))); strcat(d->fdfhdr,str); break; default: sprintf(str,"float location[] = {%.6f,%.6f,%.6f};\n",-pro,ppe,pss); strcat(d->fdfhdr,str); sprintf(str,"float roi[] = {%.6f,%.6f,%.6f};\n",*val("lro",&d->p),*val("lpe",&d->p),*val("lpe2",&d->p)); strcat(d->fdfhdr,str); break; } /* end datamode switch */ sprintf(str,"float gap = %.6f;\n",*val("gap",&d->p)); strcat(d->fdfhdr,str); sprintf(str,"char *file = \"%s\";\n",d->file); strcat(d->fdfhdr,str); sprintf(str,"int slab_no = %d;\n",slab+1); strcat(d->fdfhdr,str); sprintf(str,"int slabs = %d;\n",ns); strcat(d->fdfhdr,str); sprintf(str,"int echo_no = %d;\n",echo+1); strcat(d->fdfhdr,str); sprintf(str,"int echoes = %d;\n",ne); strcat(d->fdfhdr,str); if (ne < 2) value=getelem(d,"te",image); else { /* a multi echo expt */ /* The TE array should hold the echo time of each echo */ if (nvals("TE",&d->p) == *val("ne",&d->p)) { dblval=val("TE",&d->p); value=dblval[echo]/1000.0; } else { value=1.0; /* Just set a silly value */ } } sprintf(str,"float TE = %.3f;\n",1000.0*value); strcat(d->fdfhdr,str); sprintf(str,"float te = %.6f;\n",value); strcat(d->fdfhdr,str); value=getelem(d,"tr",image); sprintf(str,"float TR = %.3f;\n",1000.0*value); strcat(d->fdfhdr,str); sprintf(str,"float tr = %.6f;\n",value); strcat(d->fdfhdr,str); sprintf(str,"int ro_size = %d;\n",(int)*val("np",&d->p)/2); strcat(d->fdfhdr,str); sprintf(str,"int pe_size = %d;\n",(int)*val("nv",&d->p)); strcat(d->fdfhdr,str); sprintf(str,"int pe2_size = %d;\n",(int)*val("nv2",&d->p)); strcat(d->fdfhdr,str); sprintf(str,"char *sequence = \"%s\";\n",*sval("seqfil",&d->p)); strcat(d->fdfhdr,str); sprintf(str,"char *studyid = \"%s\";\n",*sval("studyid_",&d->p)); strcat(d->fdfhdr,str); /* sprintf(str,"char *position1 = \"%s\";\n",""); strcat(d->fdfhdr,str); sprintf(str,"char *position2 = \"%s\";\n",""); strcat(d->fdfhdr,str); */ value=getelem(d,"ti",image); sprintf(str,"float TI = %.3f;\n",1000.0*value); strcat(d->fdfhdr,str); sprintf(str,"float ti = %.6f;\n",value); strcat(d->fdfhdr,str); sprintf(str,"int array_index = %d;\n",image+1-IMAGEOFFSET); strcat(d->fdfhdr,str); /* The array_dim is the number of *image???*.fdf = (for 3D) # volumes divided by # echoes*slices */ value=(double)d->nvols/(ne*ns); /* But if there are reference volumes they must be accounted for */ /* Check for image parameter array, since that is used to signify reference scans */ if (arraycheck("image",&d->a)) { /* count # image=1 values */ for (i=0;i<nvals("image",&d->p);i++) if (getelem(d,"image",i)<1) value--; } sprintf(str,"float array_dim = %.4f;\n",value); strcat(d->fdfhdr,str); /* sprintf(str,"float image = 1.0;\n"); strcat(d->fdfhdr,str); */ /* The following assumes that fid data is always stored bigendian .. .. if we must reverse byte order to interpret then CPU is lilendian */ if (reverse_byte_order) { sprintf(str,"int bigendian = 0;\n"); strcat(d->fdfhdr,str); } /* Image scaling */ value=*val("aipScale",&d->p); if (FP_EQ(value,0.0)) value=1.0; sprintf(str,"float imagescale = %.9f;\n",value); strcat(d->fdfhdr,str); sprintf(str,"float psi = %.4f;\n",psi); strcat(d->fdfhdr,str); sprintf(str,"float phi = %.4f;\n",phi); strcat(d->fdfhdr,str); sprintf(str,"float theta = %.4f;\n",theta); strcat(d->fdfhdr,str); /* Generate direction cosine matrix from "Euler" angles just as recon_all */ cospsi=cos(DEG2RAD*psi); sinpsi=sin(DEG2RAD*psi); cosphi=cos(DEG2RAD*phi); sinphi=sin(DEG2RAD*phi); costheta=cos(DEG2RAD*theta); sintheta=sin(DEG2RAD*theta); /* For 2D ... or0=-1*cosphi*cospsi - sinphi*costheta*sinpsi; or1=-1*cosphi*sinpsi + sinphi*costheta*cospsi; or2=-1*sinphi*sintheta; or3=-1*sinphi*cospsi + cosphi*costheta*sinpsi; or4=-1*sinphi*sinpsi - cosphi*costheta*cospsi; or5=cosphi*sintheta; or6=-1*sintheta*sinpsi; or7=sintheta*cospsi; or8=costheta; */ /* For 3D ... */ or0=-1*sinphi*sinpsi - cosphi*costheta*cospsi; /* the 2D or4 */ or1=sinphi*cospsi - cosphi*costheta*sinpsi; /* the 2D -or3 */ or2=cosphi*sintheta; /* the 2D or5 */ or3=cosphi*sinpsi - sinphi*costheta*cospsi; /* the 2D -or1 */ or4=-1*cosphi*cospsi - sinphi*costheta*sinpsi; /* the 2D or0 */ or5=sinphi*sintheta; /* the 2D -or2 */ or6=sintheta*cospsi; /* the 2D or7 */ or7=sintheta*sinpsi; /* the 2D -or6 */ or8=costheta; /* the 2D or8 */ sprintf(str,"float orientation[] = {%.4f,%.4f,%.4f,%.4f,%.4f,%.4f,%.4f,%.4f,%.4f};\n", or0,or1,or2,or3,or4,or5,or6,or7,or8); strcat(d->fdfhdr,str); sprintf(str,"char *array_name = \"none\";\n"); strcat(d->fdfhdr,str); /* Add arrayed parameters */ if (d->a.npars>0) { for (i=0;i<*d->a.nvals;i++) { if (addpar2hdr(&d->a,i)) { /* If not already included by default */ cycle=(int)d->a.d[0][i]; n=nvals(d->a.s[0][i],&d->p); id=(image/cycle)%n; switch (ptype(d->a.s[0][i],&d->p)) { case 0: strcat(d->fdfhdr,"int "); intval=ival(d->a.s[0][i],&d->p); sprintf(str,"%s = %d;\n",d->a.s[0][i],intval[id]); strcat(d->fdfhdr,str); break; case 1: strcat(d->fdfhdr,"float "); dblval=val(d->a.s[0][i],&d->p); sprintf(str,"%s = %.6f;\n",d->a.s[0][i],dblval[id]); strcat(d->fdfhdr,str); break; case 2: strcat(d->fdfhdr,"char *"); strval=sval(d->a.s[0][i],&d->p); sprintf(str,"%s = \"%s\";\n",d->a.s[0][i],strval[id]); strcat(d->fdfhdr,str); break; } } } } /* Add sviblist parameters */ if (d->s.npars>0) { for (i=0;i<*d->s.nvals;i++) { if (addpar2hdr(&d->s,i)) { /* If not already included by default */ add = 1; if (d->a.npars>0) { /* Don't include arrayed parameters */ for (j=0;j<*d->a.nvals;j++) if (!strcmp(d->a.s[0][j],d->s.s[0][i])) add--; } if (add) { /* NB The parameter may be arrayed with setprotect('par','on',256) */ n=nvals(d->s.s[0][i],&d->p); if (n>0) { id=image%n; /* Assume 'cycle' is 1 - no mechanism exists to suggest otherwise */ switch (ptype(d->s.s[0][i],&d->p)) { case 0: /* Integer */ strcat(d->fdfhdr,"int "); intval=ival(d->s.s[0][i],&d->p); sprintf(str,"%s = %d;\n",d->s.s[0][i],intval[id]); strcat(d->fdfhdr,str); break; case 1: /* Real */ strcat(d->fdfhdr,"float "); dblval=val(d->s.s[0][i],&d->p); sprintf(str,"%s = %.6f;\n",d->s.s[0][i],dblval[id]); strcat(d->fdfhdr,str); break; case 2: /* String */ strcat(d->fdfhdr,"char *"); strval=sval(d->s.s[0][i],&d->p); sprintf(str,"%s = \"%s\";\n",d->s.s[0][i],strval[id]); strcat(d->fdfhdr,str); break; } } } } } } /* For 2D strcat(d->fdfhdr,"int checksum = 1291708713;\n"); is used for some unknown reason */ strcat(d->fdfhdr,"int checksum = 0;\n"); strcat(d->fdfhdr,"\f\n"); /* Add padding */ switch(precision) { case FLT32: /* 32 bit float */ align = sizeof(float); break; case DBL64: /* 64 bit double */ align = sizeof(double); break; default: break; } /* end precision switch */ hdrlen=strlen(d->fdfhdr); hdrlen++; /* allow for NULL terminator */ pad_cnt=hdrlen%align; pad_cnt=(align-pad_cnt)%align; for(i=0;i<pad_cnt;i++) strcat(d->fdfhdr,"\n"); }
/* run a test that simulates an approximate netbench client load */ static bool run_netbench(struct torture_context *tctx, struct smbcli_state *cli, int client) { int torture_nprocs = torture_setting_int(tctx, "nprocs", 4); int i; char line[1024]; char *cname; FILE *f; bool correct = true; double target_rate = torture_setting_double(tctx, "targetrate", 0); int n; if (target_rate != 0 && client == 0) { printf("Targetting %.4f MByte/sec\n", target_rate); } nb_setup(cli, client); if (torture_nprocs == 1) { if (!read_only) { NB_RETRY(torture_setup_dir(cli, "\\clients")); } } asprintf(&cname, "client%d", client+1); f = fopen(loadfile, "r"); if (!f) { perror(loadfile); return false; } again: nbio_time_reset(); while (fgets(line, sizeof(line)-1, f)) { NTSTATUS status; const char **params0, **params; nbench_line_count++; line[strlen(line)-1] = 0; all_string_sub(line,"client1", cname, sizeof(line)); params = params0 = str_list_make_shell(NULL, line, " "); i = str_list_length(params); if (i > 0 && isdigit(params[0][0])) { double targett = strtod(params[0], NULL); if (target_rate != 0) { nbio_target_rate(target_rate); } else { nbio_time_delay(targett); } params++; i--; } else if (target_rate != 0) { nbio_target_rate(target_rate); } if (i < 2 || params[0][0] == '#') continue; if (!strncmp(params[0],"SMB", 3)) { printf("ERROR: You are using a dbench 1 load file\n"); nb_exit(1); } if (strncmp(params[i-1], "NT_STATUS_", 10) != 0 && strncmp(params[i-1], "0x", 2) != 0) { printf("Badly formed status at line %d\n", nbench_line_count); talloc_free(params); continue; } /* accept numeric or string status codes */ if (strncmp(params[i-1], "0x", 2) == 0) { status = NT_STATUS(strtoul(params[i-1], NULL, 16)); } else { status = nt_status_string_to_code(params[i-1]); } DEBUG(9,("run_netbench(%d): %s %s\n", client, params[0], params[1])); if (!strcmp(params[0],"NTCreateX")) { NB_RETRY(nb_createx(params[1], ival(params[2]), ival(params[3]), ival(params[4]), status)); } else if (!strcmp(params[0],"Close")) { NB_RETRY(nb_close(ival(params[1]), status)); } else if (!read_only && !strcmp(params[0],"Rename")) { NB_RETRY(nb_rename(params[1], params[2], status, n>0)); } else if (!read_only && !strcmp(params[0],"Unlink")) { NB_RETRY(nb_unlink(params[1], ival(params[2]), status, n>0)); } else if (!read_only && !strcmp(params[0],"Deltree")) { NB_RETRY(nb_deltree(params[1], n>0)); } else if (!read_only && !strcmp(params[0],"Rmdir")) { NB_RETRY(nb_rmdir(params[1], status, n>0)); } else if (!read_only && !strcmp(params[0],"Mkdir")) { NB_RETRY(nb_mkdir(params[1], status, n>0)); } else if (!strcmp(params[0],"QUERY_PATH_INFORMATION")) { NB_RETRY(nb_qpathinfo(params[1], ival(params[2]), status)); } else if (!strcmp(params[0],"QUERY_FILE_INFORMATION")) { NB_RETRY(nb_qfileinfo(ival(params[1]), ival(params[2]), status)); } else if (!strcmp(params[0],"QUERY_FS_INFORMATION")) { NB_RETRY(nb_qfsinfo(ival(params[1]), status)); } else if (!read_only && !strcmp(params[0],"SET_FILE_INFORMATION")) { NB_RETRY(nb_sfileinfo(ival(params[1]), ival(params[2]), status)); } else if (!strcmp(params[0],"FIND_FIRST")) { NB_RETRY(nb_findfirst(params[1], ival(params[2]), ival(params[3]), ival(params[4]), status)); } else if (!read_only && !strcmp(params[0],"WriteX")) { NB_RETRY(nb_writex(ival(params[1]), ival(params[2]), ival(params[3]), ival(params[4]), status)); } else if (!read_only && !strcmp(params[0],"Write")) { NB_RETRY(nb_write(ival(params[1]), ival(params[2]), ival(params[3]), ival(params[4]), status)); } else if (!strcmp(params[0],"LockX")) { NB_RETRY(nb_lockx(ival(params[1]), ival(params[2]), ival(params[3]), status)); } else if (!strcmp(params[0],"UnlockX")) { NB_RETRY(nb_unlockx(ival(params[1]), ival(params[2]), ival(params[3]), status)); } else if (!strcmp(params[0],"ReadX")) { NB_RETRY(nb_readx(ival(params[1]), ival(params[2]), ival(params[3]), ival(params[4]), status)); } else if (!strcmp(params[0],"Flush")) { NB_RETRY(nb_flush(ival(params[1]), status)); } else if (!strcmp(params[0],"Sleep")) { nb_sleep(ival(params[1]), status); } else { printf("[%d] Unknown operation %s\n", nbench_line_count, params[0]); } if (n > nb_max_retries) { printf("Maximum reconnect retries reached for op '%s'\n", params[0]); nb_exit(1); } talloc_free(params0); if (nb_tick()) goto done; } rewind(f); goto again; done: fclose(f); if (!read_only && torture_nprocs == 1) { smbcli_deltree(cli->tree, "\\clients"); } if (!torture_close_connection(cli)) { correct = false; } return correct; }
TEST(Type, Option) { EXPECT_TRUE(TTrue.subtypeOf(TOptTrue)); EXPECT_TRUE(TInitNull.subtypeOf(TOptTrue)); EXPECT_TRUE(!TUninit.subtypeOf(TOptTrue)); EXPECT_TRUE(TFalse.subtypeOf(TOptFalse)); EXPECT_TRUE(TInitNull.subtypeOf(TOptFalse)); EXPECT_TRUE(!TUninit.subtypeOf(TOptFalse)); EXPECT_TRUE(TFalse.subtypeOf(TOptBool)); EXPECT_TRUE(TTrue.subtypeOf(TOptBool)); EXPECT_TRUE(TInitNull.subtypeOf(TOptBool)); EXPECT_TRUE(!TUninit.subtypeOf(TOptBool)); EXPECT_TRUE(ival(3).subtypeOf(TOptInt)); EXPECT_TRUE(TInt.subtypeOf(TOptInt)); EXPECT_TRUE(TInitNull.subtypeOf(TOptInt)); EXPECT_TRUE(!TUninit.subtypeOf(TOptInt)); EXPECT_TRUE(TDbl.subtypeOf(TOptDbl)); EXPECT_TRUE(TInitNull.subtypeOf(TOptDbl)); EXPECT_TRUE(!TUninit.subtypeOf(TOptDbl)); EXPECT_TRUE(dval(3.0).subtypeOf(TOptDbl)); EXPECT_TRUE(sval(s_test.get()).subtypeOf(TOptSStr)); EXPECT_TRUE(TSStr.subtypeOf(TOptSStr)); EXPECT_TRUE(TInitNull.subtypeOf(TOptSStr)); EXPECT_TRUE(!TUninit.subtypeOf(TOptSStr)); EXPECT_TRUE(!TStr.subtypeOf(TOptSStr)); EXPECT_TRUE(TStr.couldBe(TOptSStr)); EXPECT_TRUE(TCStr.subtypeOf(TOptStr)); EXPECT_TRUE(TCArr.subtypeOf(TOptArr)); EXPECT_TRUE(TStr.subtypeOf(TOptStr)); EXPECT_TRUE(TSStr.subtypeOf(TOptStr)); EXPECT_TRUE(sval(s_test.get()).subtypeOf(TOptStr)); EXPECT_TRUE(TInitNull.subtypeOf(TOptStr)); EXPECT_TRUE(!TUninit.subtypeOf(TOptStr)); EXPECT_TRUE(TSArr.subtypeOf(TOptSArr)); EXPECT_TRUE(!TArr.subtypeOf(TOptSArr)); EXPECT_TRUE(TInitNull.subtypeOf(TOptSArr)); EXPECT_TRUE(!TUninit.subtypeOf(TOptSArr)); EXPECT_TRUE(TArr.subtypeOf(TOptArr)); EXPECT_TRUE(TInitNull.subtypeOf(TOptArr)); EXPECT_TRUE(!TUninit.subtypeOf(TOptArr)); EXPECT_TRUE(TObj.subtypeOf(TOptObj)); EXPECT_TRUE(TInitNull.subtypeOf(TOptObj)); EXPECT_TRUE(!TUninit.subtypeOf(TOptObj)); EXPECT_TRUE(TRes.subtypeOf(TOptRes)); EXPECT_TRUE(TInitNull.subtypeOf(TOptRes)); EXPECT_TRUE(!TUninit.subtypeOf(TOptRes)); for (auto& t : optionals) EXPECT_EQ(t, opt(unopt(t))); for (auto& t : optionals) EXPECT_TRUE(is_opt(t)); for (auto& t : all) { auto const found = std::find(begin(optionals), end(optionals), t) != end(optionals); EXPECT_EQ(found, is_opt(t)); } EXPECT_TRUE(is_opt(opt(sval(s_test.get())))); EXPECT_TRUE(is_opt(opt(ival(2)))); EXPECT_TRUE(is_opt(opt(dval(2.0)))); EXPECT_FALSE(is_opt(sval(s_test.get()))); EXPECT_FALSE(is_opt(ival(2))); EXPECT_FALSE(is_opt(dval(2.0))); }
int validate(char *str) { if(StackDebugging) { int tid = THREAD_ID; int st_len = STACK_SPOT; int sh_len = SHADOW_SPOT; if(st_len!=sh_len) { printf("Validating at %s\n" , str ); printf("Stacks differ in length (%d,%d) on thread %d\n",st_len,sh_len,tid); return 0; } int *S = STACK; int i = 0; while( i < st_len ) { S_CELL C = SHADOW[i]; int addr = S[i]; char *shadow = C.type; char *light = type(addr); if(shadow != light) { printf("Stack for thread %d : \n",tid); printf("\t\tType = %s\n", type(addr)); printf("\t\tFile = %d\n", file(addr)); printf("\t\tLine = %d\n", line(addr)); printf("\t\tCount = %d\n", count(addr)); printf("\t\tIval = %d\n", ival(addr)); printf("\t\tRval = %f\n", rval(addr)); printf("\t\tFval = %p\n", fval(addr)); printf("\t\tCdr = %d\n\n", cdr(addr)); printf("Stack for thread %d : \n",tid); printf("\t\tAddress = %d\n", C.addr); printf("\t\tType = %s\n", C.type); printf("\t\tFile = %d\n", C.file); printf("\t\tLine = %d\n", C.line); printf("\t\tCount = %d\n", C.count); printf("\t\tIval = %d\n", C.ival); printf("\t\tRval = %f\n", C.rval); printf("\t\tFval = %p\n", C.fval); printf("\t\tCdr = %d\n\n", C.cdr); printf("\t\tFile Changed : %s\n", C.fileChanged); printf("\t\tLine Changed : %d\n\n", C.lineChanged); return 0; } ++i; } } return 1; }
node* integer(long long num) { node *ptr = newnode(INT); ival(ptr) = num; return ptr; }
std::unique_ptr<Value> FunctionValueNode::traceValue(std::unique_ptr<Value> val, std::ostream& out) const { switch (val->getType()) { case Value::String: { StringValue& sval(static_cast<StringValue&>(*val)); if (_function == LOWERCASE) { std::unique_ptr<Value> result(new StringValue( vespalib::LowerCase::convert(sval.getValue()))); out << "Performed lowercase function on '" << sval << "' => '" << *result << "'.\n"; return result; } else if (_function == HASH) { std::unique_ptr<Value> result(new IntegerValue( hash(sval.getValue().c_str(), sval.getValue().size()), false)); out << "Performed hash on string '" << sval << "' -> " << *result << "\n"; return result; } break; } case Value::Float: { FloatValue& fval(static_cast<FloatValue&>(*val)); if (_function == HASH) { FloatValue::ValueType ffval = fval.getValue(); std::unique_ptr<Value> result(new IntegerValue( hash(&ffval, sizeof(ffval)), false)); out << "Performed hash on float " << ffval << " -> " << *result << "\n"; return result; } else if (_function == ABS) { FloatValue::ValueType ffval = fval.getValue(); if (ffval < 0) ffval *= -1; out << "Performed abs on float " << fval.getValue() << " -> " << ffval << "\n"; return std::unique_ptr<Value>(new FloatValue(ffval)); } break; } case Value::Integer: { IntegerValue& ival(static_cast<IntegerValue&>(*val)); if (_function == HASH) { IntegerValue::ValueType iival = ival.getValue(); std::unique_ptr<Value> result(new IntegerValue( hash(&iival, sizeof(iival)), false)); out << "Performed hash on float " << iival << " -> " << *result << "\n"; return result; } else if (_function == ABS) { IntegerValue::ValueType iival = ival.getValue(); if (iival < 0) iival *= -1; out << "Performed abs on integer " << ival.getValue() << " -> " << iival << "\n"; return std::unique_ptr<Value>(new IntegerValue(iival, false)); } break; } case Value::Bucket: break; case Value::Array: break; case Value::Struct: break; case Value::Invalid: break; case Value::Null: break; } out << "Cannot use function " << _function << " on a value of type " << val->getType() << ". Resolving invalid.\n"; return std::unique_ptr<Value>(new InvalidValue); }
static int x_issue_special_command(const char * line, Command_Options *copts, Dictionary dict) { char *s, myline[1000], *x, *y; int i, count, j, k; Switch * as = default_switches; Parse_Options opts = copts->popts; strncpy(myline, line, sizeof(myline)); myline[sizeof(myline)-1] = '\0'; clean_up_string(myline); s = myline; j = k = -1; count = 0; /* Look for boolean flippers */ for (i=0; as[i].string != NULL; i++) { if ((Bool == as[i].param_type) && strncasecmp(s, as[i].string, strlen(s)) == 0) { count++; j = i; } } /* Look for abbreviations */ for (i=0; user_command[i].s != NULL; i++) { if (strncasecmp(s, user_command[i].s, strlen(s)) == 0) { count++; k = i; } } if (count > 1) { printf("Ambiguous command. Type \"!help\" or \"!variables\"\n"); return -1; } else if (count == 1) { /* flip boolean value */ if (j >= 0) { setival(as[j], (0 == ival(as[j]))); printf("%s turned %s.\n", as[j].description, (ival(as[j]))? "on" : "off"); return 0; } else { /* Found an abbreviated command, but it wasn't a boolean */ /* Replace the abbreviated command by the full one */ /* Basically, this just fixes !v and !h for use below. */ strcpy(s, user_command[k].s); } } if (strcmp(s, "variables") == 0) { printf(" Variable Controls Value\n"); printf(" -------- -------- -----\n"); for (i = 0; as[i].string != NULL; i++) { printf(" "); left_print_string(stdout, as[i].string, " "); left_print_string(stdout, as[i].description, " "); if (Float == as[i].param_type) { /* Float point print! */ printf("%5.2f", *((double *)as[i].ptr)); } else if ((Bool == as[i].param_type) || Int == as[i].param_type) { printf("%5d", ival(as[i])); } else if (String == as[i].param_type) { printf("%s", *(char **)as[i].ptr); } if (Bool == as[i].param_type) { if (ival(as[i])) printf(" (On)"); else printf(" (Off)"); } printf("\n"); } printf("\n"); printf("Toggle a boolean variable as in \"!batch\"; "); printf("set a variable as in \"!width=100\".\n"); return 0; } if (strcmp(s, "help") == 0) { printf("Special commands always begin with \"!\". Command and variable names\n"); printf("can be abbreviated. Here is a list of the commands:\n\n"); for (i=0; user_command[i].s != NULL; i++) { printf(" !"); left_print_string(stdout, user_command[i].s, " "); left_print_string(stdout, user_command[i].str, " "); printf("\n"); } printf(" !!<string> Print all the dictionary words that matches <string>.\n"); printf(" A wildcard * may be used to find multiple matches.\n"); printf("\n"); printf(" !<var> Toggle the specified boolean variable.\n"); printf(" !<var>=<val> Assign that value to that variable.\n"); return 0; } if (s[0] == '!') { dict_display_word_info(dict, s+1, opts); dict_display_word_expr(dict, s+1, opts); return 0; } #ifdef USE_REGEX_TOKENIZER if (s[0] == '/') { int rc = regex_tokenizer_test(dict, s+1); if (0 != rc) printf("regex_tokenizer_test: rc %d\n", rc); return 0; } #endif /* Test here for an equation i.e. does the command line hold an equals sign? */ for (x=s; (*x != '=') && (*x != '\0') ; x++) ; if (*x == '=') { *x = '\0'; y = x+1; x = s; /* now x is the first word and y is the rest */ /* Figure out which command it is .. it'll be the j'th one */ j = -1; for (i=0; as[i].string != NULL; i++) { if (strncasecmp(x, as[i].string, strlen(x)) == 0) { j = i; count ++; } } if (j<0) { printf("There is no user variable called \"%s\".\n", x); return -1; } if (count > 1) { printf("Ambiguous variable. Type \"!help\" or \"!variables\"\n"); return -1; } if ((as[j].param_type == Int) || (as[j].param_type == Bool)) { int val = -1; if (is_numerical_rhs(y)) val = atoi(y); if ((0 == strcasecmp(y, "true")) || (0 == strcasecmp(y, "t"))) val = 1; if ((0 == strcasecmp(y, "false")) || (0 == strcasecmp(y, "f"))) val = 0; if (val < 0) { printf("Invalid value %s for variable %s Type \"!help\" or \"!variables\"\n", y, as[j].string); return -1; } setival(as[j], val); printf("%s set to %d\n", as[j].string, val); return 0; } else if (as[j].param_type == Float) { double val = -1.0; val = atof(y); if (val < 0.0) { printf("Invalid value %s for variable %s Type \"!help\" or \"!variables\"\n", y, as[j].string); return -1; } *((double *) as[j].ptr) = val; printf("%s set to %5.2f\n", as[j].string, val); return 0; } else if (as[j].param_type == String) { *((char **) as[j].ptr) = y; printf("%s set to %s\n", (char *)as[j].string, y); return 0; } else { printf("Internal error: Unknown variable type %d\n", as[j].param_type); return -1; } } /* Look for valid commands, but ones that needed an argument */ j = -1; count = 0; for (i = 0; as[i].string != NULL; i++) { if ((Bool != as[i].param_type) && strncasecmp(s, as[i].string, strlen(s)) == 0) { j = i; count++; } } if (0 < count) { printf("Variable \"%s\" requires a value. Try \"!help\".\n", as[j].string); return -1; } printf("I can't interpret \"%s\" as a command. Try \"!help\".\n", myline); return -1; }
// default behaviour is to save data as an int string GuiControl::valueToString() { if(value==NULL) return ""; return ofToString(ival(value)); }
void GuiControl::valueFromString(string inp) { if(value==NULL) value = new int[1]; ival(value) = atoi(inp.c_str()); }
int GuiControl::intValue() { return ival(value); }
void xmlgui::Control::setValue(int val) { ival(value) = val; }
TEST(Type, Num) { EXPECT_EQ(union_of(TInt, TDbl), TNum); EXPECT_EQ(union_of(ival(2), dval(1.0)), TNum); EXPECT_EQ(union_of(TInt, dval(1.0)), TNum); }