void handle_read(ranger::event::tcp_connection& conn, ranger::event::buffer&& buf) { std::vector<char> v(buf.size()); buf.remove(v.data(), v.size()); for (auto ch: v) std::cout << ch << std::flush; conn.write_buffer().append(v.data(), v.size()); }
/** * The method returns the measurement noise vector. * * \return The process noise. */ inline const vector& calculateV() { for(size_t i=0; i<ngV.size(); ++i) v(i) = (*ngV[i])(); return v; }
Estimate Estimate::operator << (i32 howmuch) const { LongFloat v(m_Value << howmuch); return Estimate(v, (m_Error << howmuch) + RoundingError(v, v.AdditionRoundingError())); }
/// Multiply a vector by scalar. /// \param a a scalar. template < typename T > vector < T > vector < T >::operator*(T a) const { vector < T > v(this->m_rows); for (int i = this->m_rows - 1; i >= 0; i--) v.p[i] = a * this->p[i]; return v; }
inline Vector<DIM, T> Vector<DIM, T>::normalized() const { Vector<DIM, T> v(*this); v.normalize(); return v; }
const var& var::operator= (const String& newValue) { var v (newValue); swapWith (v); return *this; }
const var& var::operator= (ReferenceCountedObject* newValue) { var v (newValue); swapWith (v); return *this; }
/************************************************************************* Obsolete 1-based subroutine. See RMatrixBDMultiplyByQ for 0-based replacement. *************************************************************************/ void multiplybyqfrombidiagonal(const ap::real_2d_array& qp, int m, int n, const ap::real_1d_array& tauq, ap::real_2d_array& z, int zrows, int zcolumns, bool fromtheright, bool dotranspose) { int i; int ip1; int i1; int i2; int istep; ap::real_1d_array v; ap::real_1d_array work; int vm; int mx; if( m<=0||n<=0||zrows<=0||zcolumns<=0 ) { return; } ap::ap_error::make_assertion(fromtheright&&zcolumns==m||!fromtheright&&zrows==m, "MultiplyByQFromBidiagonal: incorrect Z size!"); // // init // mx = ap::maxint(m, n); mx = ap::maxint(mx, zrows); mx = ap::maxint(mx, zcolumns); v.setbounds(1, mx); work.setbounds(1, mx); if( m>=n ) { // // setup // if( fromtheright ) { i1 = 1; i2 = n; istep = +1; } else { i1 = n; i2 = 1; istep = -1; } if( dotranspose ) { i = i1; i1 = i2; i2 = i; istep = -istep; } // // Process // i = i1; do { vm = m-i+1; ap::vmove(v.getvector(1, vm), qp.getcolumn(i, i, m)); v(1) = 1; if( fromtheright ) { applyreflectionfromtheright(z, tauq(i), v, 1, zrows, i, m, work); } else { applyreflectionfromtheleft(z, tauq(i), v, i, m, 1, zcolumns, work); } i = i+istep; } while(i!=i2+istep); } else { // // setup // if( fromtheright ) { i1 = 1; i2 = m-1; istep = +1; } else { i1 = m-1; i2 = 1; istep = -1; } if( dotranspose ) { i = i1; i1 = i2; i2 = i; istep = -istep; } // // Process // if( m-1>0 ) { i = i1; do { vm = m-i; ip1 = i+1; ap::vmove(v.getvector(1, vm), qp.getcolumn(i, ip1, m)); v(1) = 1; if( fromtheright ) { applyreflectionfromtheright(z, tauq(i), v, 1, zrows, i+1, m, work); } else { applyreflectionfromtheleft(z, tauq(i), v, i+1, m, 1, zcolumns, work); } i = i+istep; } while(i!=i2+istep); } } }
int main(int, char**) { int failed = 0; // Basic AMQP types RUN_TEST(failed, simple_type_test(null())); RUN_TEST(failed, simple_type_test(false)); RUN_TEST(failed, simple_type_test(uint8_t(42))); RUN_TEST(failed, simple_type_test(int8_t(-42))); RUN_TEST(failed, simple_type_test(uint16_t(4242))); RUN_TEST(failed, simple_type_test(int16_t(-4242))); RUN_TEST(failed, simple_type_test(uint32_t(4242))); RUN_TEST(failed, simple_type_test(int32_t(-4242))); RUN_TEST(failed, simple_type_test(uint64_t(4242))); RUN_TEST(failed, simple_type_test(int64_t(-4242))); RUN_TEST(failed, simple_type_test(wchar_t('X'))); RUN_TEST(failed, simple_type_test(float(1.234))); RUN_TEST(failed, simple_type_test(double(11.2233))); RUN_TEST(failed, simple_type_test(timestamp(1234))); RUN_TEST(failed, simple_type_test(make_fill<decimal32>(0))); RUN_TEST(failed, simple_type_test(make_fill<decimal64>(0))); RUN_TEST(failed, simple_type_test(make_fill<decimal128>(0))); RUN_TEST(failed, simple_type_test(uuid::copy("\x00\x11\x22\x33\x44\x55\x66\x77\x88\x99\xaa\xbb\xcc\xdd\xee\xff"))); RUN_TEST(failed, simple_type_test(std::string("xxx"))); RUN_TEST(failed, simple_type_test(symbol("aaa"))); RUN_TEST(failed, simple_type_test(binary("aaa"))); // Native int type that may map differently per platform to uint types. RUN_TEST(failed, simple_type_test(char(42))); RUN_TEST(failed, simple_type_test(short(42))); RUN_TEST(failed, simple_type_test(int(42))); RUN_TEST(failed, simple_type_test(long(42))); RUN_TEST(failed, simple_type_test(static_cast<signed char>(42))); RUN_TEST(failed, simple_type_test(static_cast<signed short>(42))); RUN_TEST(failed, simple_type_test(static_cast<signed int>(42))); RUN_TEST(failed, simple_type_test(static_cast<signed long>(42))); RUN_TEST(failed, simple_type_test(static_cast<unsigned char>(42))); RUN_TEST(failed, simple_type_test(static_cast<unsigned short>(42))); RUN_TEST(failed, simple_type_test(static_cast<unsigned int>(42))); RUN_TEST(failed, simple_type_test(static_cast<unsigned long>(42))); #if PN_CPP_HAS_LONG_LONG_TYPE RUN_TEST(failed, simple_type_test(static_cast<long long>(42))); RUN_TEST(failed, simple_type_test(static_cast<signed long long>(42))); RUN_TEST(failed, simple_type_test(static_cast<unsigned long long>(42))); #endif // value and scalar types, more tests in value_test and scalar_test. RUN_TEST(failed, simple_type_test(value("foo"))); RUN_TEST(failed, value v(23); simple_type_test(v)); RUN_TEST(failed, simple_type_test(scalar(23))); RUN_TEST(failed, simple_type_test(annotation_key(42))); RUN_TEST(failed, simple_type_test(message_id(42))); // Make sure we reject uncodable types RUN_TEST(failed, (uncodable_type_test<std::pair<int, float> >())); RUN_TEST(failed, (uncodable_type_test<std::pair<scalar, value> >())); RUN_TEST(failed, (uncodable_type_test<std::basic_string<wchar_t> >())); RUN_TEST(failed, (uncodable_type_test<internal::data>())); RUN_TEST(failed, (uncodable_type_test<pn_data_t*>())); return failed; }
/************************************************************************* Multiplication by matrix P which reduces matrix A to bidiagonal form. The algorithm allows pre- or post-multiply by P or P'. Input parameters: QP - matrices Q and P in compact form. Output of RMatrixBD subroutine. M - number of rows in matrix A. N - number of columns in matrix A. TAUP - scalar factors which are used to form P. Output of RMatrixBD subroutine. Z - multiplied matrix. Array whose indexes range within [0..ZRows-1,0..ZColumns-1]. ZRows - number of rows in matrix Z. If FromTheRight=False, ZRows=N, otherwise ZRows can be arbitrary. ZColumns - number of columns in matrix Z. If FromTheRight=True, ZColumns=N, otherwise ZColumns can be arbitrary. FromTheRight - pre- or post-multiply. DoTranspose - multiply by P or P'. Output parameters: Z - product of Z and P. Array whose indexes range within [0..ZRows-1,0..ZColumns-1]. If ZRows=0 or ZColumns=0, the array is not modified. -- ALGLIB -- Copyright 2005-2007 by Bochkanov Sergey *************************************************************************/ void rmatrixbdmultiplybyp(const ap::real_2d_array& qp, int m, int n, const ap::real_1d_array& taup, ap::real_2d_array& z, int zrows, int zcolumns, bool fromtheright, bool dotranspose) { int i; ap::real_1d_array v; ap::real_1d_array work; int mx; int i1; int i2; int istep; if( m<=0||n<=0||zrows<=0||zcolumns<=0 ) { return; } ap::ap_error::make_assertion(fromtheright&&zcolumns==n||!fromtheright&&zrows==n, "RMatrixBDMultiplyByP: incorrect Z size!"); // // init // mx = ap::maxint(m, n); mx = ap::maxint(mx, zrows); mx = ap::maxint(mx, zcolumns); v.setbounds(0, mx); work.setbounds(0, mx); v.setbounds(0, mx); work.setbounds(0, mx); if( m>=n ) { // // setup // if( fromtheright ) { i1 = n-2; i2 = 0; istep = -1; } else { i1 = 0; i2 = n-2; istep = +1; } if( !dotranspose ) { i = i1; i1 = i2; i2 = i; istep = -istep; } // // Process // if( n-1>0 ) { i = i1; do { ap::vmove(&v(1), &qp(i, i+1), ap::vlen(1,n-1-i)); v(1) = 1; if( fromtheright ) { applyreflectionfromtheright(z, taup(i), v, 0, zrows-1, i+1, n-1, work); } else { applyreflectionfromtheleft(z, taup(i), v, i+1, n-1, 0, zcolumns-1, work); } i = i+istep; } while(i!=i2+istep); } } else { // // setup // if( fromtheright ) { i1 = m-1; i2 = 0; istep = -1; } else { i1 = 0; i2 = m-1; istep = +1; } if( !dotranspose ) { i = i1; i1 = i2; i2 = i; istep = -istep; } // // Process // i = i1; do { ap::vmove(&v(1), &qp(i, i), ap::vlen(1,n-i)); v(1) = 1; if( fromtheright ) { applyreflectionfromtheright(z, taup(i), v, 0, zrows-1, i, n-1, work); } else { applyreflectionfromtheleft(z, taup(i), v, i, n-1, 0, zcolumns-1, work); } i = i+istep; } while(i!=i2+istep); } }
/************************************************************************* Obsolete 1-based subroutine. See RMatrixBDUnpackQ for 0-based replacement. *************************************************************************/ void unpackqfrombidiagonal(const ap::real_2d_array& qp, int m, int n, const ap::real_1d_array& tauq, int qcolumns, ap::real_2d_array& q) { int i; int j; int ip1; ap::real_1d_array v; ap::real_1d_array work; int vm; ap::ap_error::make_assertion(qcolumns<=m, "UnpackQFromBidiagonal: QColumns>M!"); if( m==0||n==0||qcolumns==0 ) { return; } // // init // q.setbounds(1, m, 1, qcolumns); v.setbounds(1, m); work.setbounds(1, qcolumns); // // prepare Q // for(i = 1; i <= m; i++) { for(j = 1; j <= qcolumns; j++) { if( i==j ) { q(i,j) = 1; } else { q(i,j) = 0; } } } if( m>=n ) { for(i = ap::minint(n, qcolumns); i >= 1; i--) { vm = m-i+1; ap::vmove(v.getvector(1, vm), qp.getcolumn(i, i, m)); v(1) = 1; applyreflectionfromtheleft(q, tauq(i), v, i, m, 1, qcolumns, work); } } else { for(i = ap::minint(m-1, qcolumns-1); i >= 1; i--) { vm = m-i; ip1 = i+1; ap::vmove(v.getvector(1, vm), qp.getcolumn(i, ip1, m)); v(1) = 1; applyreflectionfromtheleft(q, tauq(i), v, i+1, m, 1, qcolumns, work); } } }
/************************************************************************* Obsolete 1-based subroutine. See RMatrixBDUnpackPT for 0-based replacement. *************************************************************************/ void unpackptfrombidiagonal(const ap::real_2d_array& qp, int m, int n, const ap::real_1d_array& taup, int ptrows, ap::real_2d_array& pt) { int i; int j; int ip1; ap::real_1d_array v; ap::real_1d_array work; int vm; ap::ap_error::make_assertion(ptrows<=n, "UnpackPTFromBidiagonal: PTRows>N!"); if( m==0||n==0||ptrows==0 ) { return; } // // init // pt.setbounds(1, ptrows, 1, n); v.setbounds(1, n); work.setbounds(1, ptrows); // // prepare PT // for(i = 1; i <= ptrows; i++) { for(j = 1; j <= n; j++) { if( i==j ) { pt(i,j) = 1; } else { pt(i,j) = 0; } } } if( m>=n ) { for(i = ap::minint(n-1, ptrows-1); i >= 1; i--) { vm = n-i; ip1 = i+1; ap::vmove(&v(1), &qp(i, ip1), ap::vlen(1,vm)); v(1) = 1; applyreflectionfromtheright(pt, taup(i), v, 1, ptrows, i+1, n, work); } } else { for(i = ap::minint(m, ptrows); i >= 1; i--) { vm = n-i+1; ap::vmove(&v(1), &qp(i, i), ap::vlen(1,vm)); v(1) = 1; applyreflectionfromtheright(pt, taup(i), v, 1, ptrows, i, n, work); } } }
int main() { quan::velocity::m_per_s v(1); v += 20; }
int main() { { boost::shared_ptr<int> sp(new int(10)); assert(sp.unique()); boost::shared_ptr<int> sp2 = sp; assert(sp == sp2 && sp.use_count() == 2); *sp2 = 100; assert(*sp == 100); sp.reset(); assert(!sp); boost::shared_ptr<int> p(new int(100)); shared s1(p), s2(p); s1.print(); s2.print(); *p = 20; print_func(p); s1.print(); } { //factory function //template<class T,class... Args> //boost::shared_ptr<T> boost::make_shared(Args && ... args); boost::shared_ptr<std::string> sp = boost::make_shared<std::string>("make_shared"); boost::shared_ptr<std::vector<int> > spv = boost::make_shared<std::vector<int> >(10,2); assert(spv->size() == 10); } { typedef std::vector<boost::shared_ptr<int> > vs; vs v(10); int i = 0; for(vs::iterator pos=v.begin();pos!=v.end();++pos) { (*pos) = boost::make_shared<int>(++i); std::cout << *(*pos) << ", "; } std::cout << std::endl; boost::shared_ptr<int> p = v[9]; *p = 100; std::cout << *v[9] << std::endl; for(auto& ptr : v) { ptr = boost::make_shared<int>(++i); std::cout << *ptr << ", "; } std::cout << std::endl; } { //bridge pattern sample s; s.print(); } return 0; }
void SaveLimits(Robot& robot,const TimeScaledBezierCurve& traj,Real dt,const char* fn) { Real T=traj.EndTime(); int numdivs = (int)Ceil(T/dt); printf("Saving time-scaled values to %s\n",fn); ofstream out(fn,ios::out); out<<"t"; for(size_t i=0;i<robot.links.size();i++) out<<",q["<<robot.linkNames[i]<<"]"; for(size_t i=0;i<robot.links.size();i++) out<<",v["<<robot.linkNames[i]<<"]"; for(size_t i=0;i<robot.links.size();i++) out<<",a["<<robot.linkNames[i]<<"]"; out<<",activeVLimit,activeAlimit,vsaturation,asaturation"; out<<endl; Vector q,v,a,maxv,maxa; for(int i=0;i<=numdivs;i++) { //double-checking velocity and acceleration bounds Real t = Real(i)/Real(numdivs)*T; traj.Eval(t,q); traj.Deriv(t,v); traj.Accel(t,a); out<<t; for(int j=0;j<q.n;j++) out<<","<<q(j); for(int j=0;j<v.n;j++) out<<","<<v(j); for(int j=0;j<a.n;j++) out<<","<<a(j); Real maxVSat=0,maxASat=0; int maxVSatInd=0,maxASatInd=0; for(int j=0;j<v.n;j++) if(Abs(v(j))/robot.velMax(j) > maxVSat) { maxVSat = Abs(v(j))/robot.velMax(j); maxVSatInd = j; } for(int j=0;j<a.n;j++) if(Abs(a(j))/robot.accMax(j) > maxASat) { maxASat = Abs(a(j))/robot.accMax(j); maxASatInd = j; } out<<","<<robot.linkNames[maxVSatInd]; out<<","<<robot.linkNames[maxASatInd]; out<<","<<maxVSat<<","<<maxASat<<endl; } out<<endl; for(size_t i=0;i<traj.timeScaling.times.size();i++) { //double-checking velocity and acceleration bounds Real t = traj.timeScaling.times[i]; traj.Eval(t,q); traj.Deriv(t,v); traj.Accel(t,a); out<<t; for(int j=0;j<q.n;j++) out<<","<<q(j); for(int j=0;j<v.n;j++) out<<","<<v(j); for(int j=0;j<a.n;j++) out<<","<<a(j); Real maxSat=0; int maxSatInd=0; bool maxSatA=false; for(int j=0;j<v.n;j++) if(Abs(v(j))/robot.velMax(j) > maxSat) { maxSat = Abs(v(j))/robot.velMax(j); maxSatInd = j; } for(int j=0;j<a.n;j++) if(Abs(a(j))/robot.accMax(j) > maxSat) { maxSat = Abs(a(j))/robot.accMax(j); maxSatInd = j; maxSatA=true; } if(maxSatA) out<<",a["<<robot.linkNames[maxSatInd]<<"]"; else out<<",v["<<robot.linkNames[maxSatInd]<<"]"; out<<","<<maxSat<<endl; } }
int main(int argc, char *argv[]) { int time_limit; char name[1000]; ListGraph g; EdgeWeight lpvar(g); EdgeWeight weight(g); NodeName vname(g); ListGraph::NodeMap<double> posx(g),posy(g); string filename; int seed=1; // uncomment one of these lines to change default pdf reader, or insert new one //set_pdfreader("open"); // pdf reader for Mac OS X //set_pdfreader("xpdf"); // pdf reader for Linux //set_pdfreader("evince"); // pdf reader for Linux srand48(seed); time_limit = 3600; // solution must be obtained within time_limit seconds if (argc!=2) {cout<< endl << "Usage: "<< argv[0]<<" <graph_filename>"<<endl << endl << "Example: " << argv[0] << " gr_berlin52" << endl << " " << argv[0] << " gr_att48" << endl << endl; exit(0);} else if (!FileExists(argv[1])) {cout<<"File "<<argv[1]<<" does not exist."<<endl; exit(0);} filename = argv[1]; // Read the graph if (!ReadListGraph(filename,g,vname,weight,posx,posy)) {cout<<"Error reading graph file "<<argv[1]<<"."<<endl;exit(0);} TSP_Data tsp(g,vname,posx,posy,weight); ListGraph::EdgeMap<GRBVar> x(g); GRBEnv env = GRBEnv(); GRBModel model = GRBModel(env); #if GUROBI_NEWVERSION model.getEnv().set(GRB_IntParam_LazyConstraints, 1); model.getEnv().set(GRB_IntParam_Seed, seed); #else model.getEnv().set(GRB_IntParam_DualReductions, 0); // Dual reductions must be disabled when using lazy constraints #endif model.set(GRB_StringAttr_ModelName, "Emparelhamento perfeito with GUROBI"); // name to the problem model.set(GRB_IntAttr_ModelSense, GRB_MAXIMIZE); // is a minimization problem // Add one binary variable for each edge and also sets its cost in //the objective function for (ListGraph::EdgeIt e(g); e!=INVALID; ++e) { sprintf(name,"x_%s_%s",vname[g.u(e)].c_str(),vname[g.v(e)].c_str()); x[e] = model.addVar(0.0, 1.0, weight[e],GRB_BINARY,name); } model.update(); // run update to use model inserted variables // Add degree constraint for each node (sum of solution edges incident to a node is 2) for (ListGraph::NodeIt v(g); v!=INVALID; ++v) { GRBLinExpr expr; for (ListGraph::IncEdgeIt e(g,v); e!=INVALID; ++e) expr += x[e]; //aqui model.addConstr(expr == 2 ); what? ignorou! model.addConstr(expr == 1); } try { model.update(); // Process any pending model modifications. if (time_limit >= 0) model.getEnv().set(GRB_DoubleParam_TimeLimit,time_limit); model.update(); // Process any pending model modifications. model.write("model.lp"); system("cat model.lp"); model.optimize(); double soma=0.0; int i = 0; for (ListGraph::EdgeIt e(g); e!=INVALID; ++e) { lpvar[e] = x[e].get(GRB_DoubleAttr_X); if (lpvar[e] > 1-BC_EPS ) { soma += weight[e]; cout << "Achei, x("<< vname[g.u(e)] << " , " << vname[g.v(e)] << ") = " << lpvar[e] <<"\n"; tsp.BestCircuit[i] = g.u(e); tsp.BestCircuit[i+1] = g.v(e); i = i+2; } } cout << "Solution cost = "<< soma << endl; ViewTspCircuit(tsp); }catch (...) { if (tsp.BestCircuitValue < DBL_MAX) { cout << "Heuristic obtained optimum solution" << endl; ViewTspCircuit(tsp); return 0; }else { cout << "Graph is infeasible" << endl; return 1; } } }
const var& var::operator= (const wchar_t* const newValue) { var v (newValue); swapWith (v); return *this; }
static std::vector<std::complex<double>> vector(gsl_vector_complex *p){ std::vector<std::complex<double>> v(p->size); for(size_t i=0; i<v.size(); i++) v[i] = std::complex<double>(GSL_VECTOR_REAL(p, i), GSL_VECTOR_IMAG(p, i)); return v;}
const var& var::operator= (const Array<var>& newValue) { var v (newValue); swapWith (v); return *this; }
static std::vector<size_t> vector(gsl_permutation *p){ std::vector<size_t> v(p->size); for(size_t i=0; i<v.size(); i++) v[i] = gsl_permutation_get(p, i); return v;}
const var& var::operator= (MethodFunction newValue) { var v (newValue); swapWith (v); return *this; }
//--- get stl contener matrix from gsl_matrix --- static std::vector<std::vector<double>> (gsl_matrix *p){ std::vector<std::vector<double>> v(p.size2); for(size_t i=0; i<v.size(); i++) v[i] = gsl_permutation_get(p, i); return v;}
vector < T > vector < T >::operator-() const { vector < T > v(this->m_rows); for (int i = this->m_rows - 1; i >= 0; i--) v.p[i] = -this->p[i]; return v; }
//--- get stl contener from gsl_vector -- static std::vector<double> vector(gsl_vector *p){ std::vector<double> v(p->size); for(size_t i=0; i<v.size(); i++) v[i] = gsl_vector_get(p, i); return v;}
void test01(const T& x) { CIMValue v(x); CIMValue v2(v); CIMValue v3; // Create a null constructor CIMType type = v.getType(); // get the type of v CIMValue v4(type,false); v3 = v2; CIMValue v5; v5 = v4; #ifdef IO if (verbose) { cout << "\n----------------------\n"; XmlWriter::printValueElement(v3, cout); } #endif try { T t; v3.get(t); assert (!v.isNull()); assert (!v.isArray()); assert (!v2.isNull()); assert(t == x); assert (v3.typeCompatible(v2)); // Confirm that the constructor created Null, not array and correct type assert (v4.isNull()); assert (!v4.isArray()); assert (v4.typeCompatible(v)); assert (v5.isNull()); assert (!v5.isArray()); assert (v5.typeCompatible(v)); // Test toMof Array<char> mofout; mofout.clear(); MofWriter::appendValueElement(mofout, v); mofout.append('\0'); // Test toXml Array<char> out; XmlWriter::appendValueElement(out, v); XmlWriter::appendValueElement(out, v); // Test toString String valueString = v.toString(); #ifdef IO if (verbose) { cout << "MOF = [" << mofout.getData() << "]" << endl; cout << "toString Output [" << valueString << "]" << endl; } #endif // There should be no exceptions to this point in the test. } catch(Exception& e) { cerr << "Error: " << e.getMessage() << endl; exit(1); } // From here forward, in the future we may have exceptions because // of the isNull which should generate an exception on the getdata. // ATTN: KS 12 Feb 2002 This is work in progress until we complete // adding the exception return to the CIMValue get functions. try { // Test for isNull and the setNullValue function CIMType type = v.getType(); v.setNullValue(type, false); assert(v.isNull()); // get the String and XML outputs for v String valueString2 = v.toString(); Array<char> xmlBuffer; XmlWriter::appendValueElement(xmlBuffer, v); xmlBuffer.append('\0'); Array<char> mofOutput2; MofWriter::appendValueElement(mofOutput2, v); mofOutput2.append('\0'); #ifdef IO if (verbose) { cout << "MOF NULL = [" << mofOutput2.getData() << "]" << endl; cout << "toString NULL Output [" << valueString2 << "]" << endl; cout << " XML NULL = [" << xmlBuffer.getData() << "]" << endl; } #endif v.clear(); assert(v.isNull()); //v2.clear(); //assert(v2.isNull(); } catch(Exception& e) { cerr << "Error: " << e.getMessage() << endl; exit(1); } }
void Position::display( ) const { //! TODO use a graphic engine int32_t error = std::system( "clear" ); if ( error != 0 ) { std::cerr << "error when clearing screen!" << error << std::endl; } std::vector< std::string > v( m_heigth, std::string( m_width, '.' ) ); v[ m_food.y ][ m_food.x ] = 'o'; if ( m_snake.x >= 0 && m_snake.x < m_width && m_snake.y >= 0 && m_snake.y < m_heigth ) { char c; switch ( m_direction ) { case Direction::RIGHT: c = '>'; break; case Direction::LEFT: c = '<'; break; case Direction::UP: c = '^'; break; case Direction::DOWN: c = 'v'; break; default: c = '?'; break; } v[ m_snake.y ][ m_snake.x ] = c; } for ( const auto& s : v ) { std::cout << s << std::endl; } std::cout << "score = " << m_score << ", life = " << m_life << ", dir = "; switch ( m_direction ) { case Direction::RIGHT: std::cout << "RIGHT"; break; case Direction::LEFT: std::cout << "LEFT"; break; case Direction::UP: std::cout << "UP"; break; case Direction::DOWN: std::cout << "DOWN"; break; default: std::cout << "UNKNOWN"; break; } std::cout << std::endl; std::cout << std::endl; }
bool EntitiesParserListener::parserProperty(TCODParser *parser,const char *name, TCOD_value_type_t type, TCOD_value_t value) { if(currentStructIsBase == false) return false; std::string propName = name; auto entityInfo = info->Entities.back(); if(propName.compare("attributes") == 0 && type == TCOD_TYPE_LIST | TCOD_TYPE_INT) { auto list = TCODList<int>(value.list); for(auto it = list.begin(); it != list.end(); ++it) { entityInfo->AttributeValues.push_back(*it); } } else if(propName.compare("vitals") == 0 && type == TCOD_TYPE_LIST | TCOD_TYPE_INT) { auto list = TCODList<int>(value.list); for(auto it = list.begin(); it != list.end(); ++it) { entityInfo->VitalValues.push_back(*it); } } else if(propName.compare("skills") == 0 && type == TCOD_TYPE_LIST | TCOD_TYPE_INT) { auto list = TCODList<int>(value.list); for(auto it = list.begin(); it != list.end(); ++it) { entityInfo->SkillValues.push_back(*it); } } else { if(type == TCOD_TYPE_INT) { auto prop = std::make_shared<Totem::Property<int>>(propName); prop->set(value.i, false); entityInfo->IntProperties.push_back(prop); } else if(type == TCOD_TYPE_CHAR) { auto prop = std::make_shared<Totem::Property<int>>(propName); prop->set((int)value.c, false); entityInfo->IntProperties.push_back(prop); } else if(type == TCOD_TYPE_FLOAT) { auto prop = std::make_shared<Totem::Property<float>>(propName); prop->set(value.f, false); entityInfo->FloatProperties.push_back(prop); } else if(type == TCOD_TYPE_STRING) { auto prop = std::make_shared<Totem::Property<std::string>>(propName); prop->set(value.s, false); entityInfo->StringProperties.push_back(prop); } else if(type == TCOD_TYPE_COLOR) { auto prop = std::make_shared<Totem::Property<TCODColor>>(propName); prop->set(value.col, false); entityInfo->ColorProperties.push_back(prop); } else if(type == TCOD_TYPE_LIST | TCOD_TYPE_INT) { auto list = TCODList<int>(value.list); if(list.size() == 2) { clan::Vec2i v(list.get(0), list.get(1)); auto prop = std::make_shared<Totem::Property<clan::Vec2i>>(propName); prop->set(v, false); entityInfo->Vec2iProperties.push_back(prop); } } else return false; } return true; }
TEST_F(AutoConstructTest, CanCopyAutoConstruct) { AutoConstruct<HasDefaultCtorAndOthers> v(100); }
bool WindowNamedPropertiesHandler::getOwnPropDescriptor(JSContext* aCx, JS::Handle<JSObject*> aProxy, JS::Handle<jsid> aId, bool /* unused */, JS::MutableHandle<JSPropertyDescriptor> aDesc) const { if (!JSID_IS_STRING(aId)) { // Nothing to do if we're resolving a non-string property. return true; } bool hasOnPrototype; if (!HasPropertyOnPrototype(aCx, aProxy, aId, &hasOnPrototype)) { return false; } if (hasOnPrototype) { return true; } nsAutoJSString str; if (!str.init(aCx, JSID_TO_STRING(aId))) { return false; } // Grab the DOM window. JS::Rooted<JSObject*> global(aCx, JS_GetGlobalForObject(aCx, aProxy)); nsGlobalWindow* win = xpc::WindowOrNull(global); if (win->Length() > 0) { nsCOMPtr<nsIDOMWindow> childWin = win->GetChildWindow(str); if (childWin && ShouldExposeChildWindow(str, childWin)) { // We found a subframe of the right name. Shadowing via |var foo| in // global scope is still allowed, since |var| only looks up |own| // properties. But unqualified shadowing will fail, per-spec. JS::Rooted<JS::Value> v(aCx); if (!WrapObject(aCx, childWin, &v)) { return false; } FillPropertyDescriptor(aDesc, aProxy, 0, v); return true; } } // The rest of this function is for HTML documents only. nsCOMPtr<nsIHTMLDocument> htmlDoc = do_QueryInterface(win->GetExtantDoc()); if (!htmlDoc) { return true; } nsHTMLDocument* document = static_cast<nsHTMLDocument*>(htmlDoc.get()); Element* element = document->GetElementById(str); if (element) { JS::Rooted<JS::Value> v(aCx); if (!WrapObject(aCx, element, &v)) { return false; } FillPropertyDescriptor(aDesc, aProxy, 0, v); return true; } nsWrapperCache* cache; nsISupports* result = document->ResolveName(str, &cache); if (!result) { return true; } JS::Rooted<JS::Value> v(aCx); if (!WrapObject(aCx, result, cache, nullptr, &v)) { return false; } FillPropertyDescriptor(aDesc, aProxy, 0, v); return true; }
int CGVM_PointContents( void ) { VMSwap v( cgvm ); return cge->PointContents(); }