void write_elf(FILE *outfile, Elf *elf) { add_symtab(elf); add_reloc(elf); add_shstrtab(elf); // Section header String *sh = make_string(); for (int i = 0; i < 64; i++) o1(sh, 0); // NULL section header // Body String *content = make_string(); for (int i = 0; i < LIST_LEN(elf->sections); i++) { write_section(sh, content, LIST_REF(elf->sections, i), 64); } align(content, 16); // ELF header String *eh = make_string(); int numsect = LIST_LEN(elf->sections) + 1; out(eh, elf_ident, sizeof(elf_ident)); o2(eh, 1); // e_type = ET_REL o2(eh, 62); // e_machine = EM_X86_64 o4(eh, 1); // e_version = EV_CURRENT o8(eh, 0); // e_entry o8(eh, 0); // e_phoff o8(eh, STRING_LEN(content) + 64); // e_shoff; o4(eh, 0); // e_flags o2(eh, 64); // e_ehsize o2(eh, 0); // e_phentsize o2(eh, 0); // e_phnum o2(eh, 64); // e_shentsize o2(eh, numsect); // e_shnum o2(eh, elf->shnum); // e_shstrndx fwrite(STRING_BODY(eh), STRING_LEN(eh), 1, outfile); fwrite(STRING_BODY(content), STRING_LEN(content), 1, outfile); fwrite(STRING_BODY(sh), STRING_LEN(sh), 1, outfile); fclose(outfile); }
int main(void) { // Use integer constructor Object o1(5); if (o1.add(2) != 7) return 1; // Use float constructor Object o2((float) 10.0); if (o2.add(2) != 12) return 2; // Test renamed object Steve s(5); if (s.val() != 5) return 3; return 0; }
TEST(Obis, Obis_extStrParsing) { Obis o1(0xff, 0xff, 0x0, 0x0, 0x0, 0xff); Obis o2("0.0.0"); ASSERT_EQ(o1, o2) << o1.toString( )<< o2.toString(); ASSERT_EQ(o1.toString(), o2.toString()); Obis o3(0xff, 0xff, 0x1, 0x2, 0x3, 0xff); Obis o4("1.2.3"); ASSERT_EQ(o3, o4); ASSERT_EQ(o3.toString(), o4.toString()); Obis o5(0xff, 0xff, 0x61, 0x61, 0xff, 0xff); Obis o6("F.F"); ASSERT_EQ(o5, o6); Obis o7(0xff, 0xff, 0x0, 0x0, 0x2, 0xff); Obis o8("0.0.2"); ASSERT_EQ(o7, o8); // this should throw an exception as hex codes are not valid inside obis codes. ASSERT_THROW(Obis o10("1.8.0*FF"), vz::VZException); ASSERT_THROW(Obis o10("1.8.0*F1"), vz::VZException); }
void FieldLineDetector::detectCorners(vector<Vec4i> &lines) { for (int i = 0; i < lines.size(); i++) { for (int j = i + 1; j < lines.size(); j++) { Point2f o1(lines[i][0], lines[i][1]); Point2f p1(lines[i][2], lines[i][3]); Point2f o2(lines[j][0], lines[j][1]); Point2f p2(lines[j][2], lines[j][3]); Point2f pt; GeoUtil::intersection(o1, p1, o2, p2, pt); Rect rect1(o1, p1); Rect rect2(o2, p2); if (!rect1.contains(pt) || !rect2.contains(pt)) { continue; } float angle = fabsf(GeoUtil::computeAngle(lines[i], lines[j])); if (pt.x >= 0 && pt.y >= 0 && angle > 0.2f) { cornerBuffer.push_back(pt); } } } cout << "cornerBuffer.size=" << cornerBuffer.size() << endl; // remove old corners if (cornerBuffer.size() > cornerBufferSize) { cornerBuffer = vector<Point2f>(cornerBuffer.end() - cornerBufferSize, cornerBuffer.end()); } }
TEST( RefVectorTests, rawPtrVectorEquivalence ) { PseudoInterface o1( 1 ), o2( 2 ), o3( 3 ); o1.serviceRetain(); o2.serviceRetain(); o3.serviceRetain(); co::RefPtr<PseudoInterface> refPtr( &o1 ); EXPECT_EQ( sizeof( co::RefPtr<PseudoInterface> ), sizeof( PseudoInterface* ) ); PseudoInterface* rawVec[] = { &o1, &o2, &o3 }; co::RefVector<PseudoInterface> refVec; refVec.push_back( &o1 ); refVec.push_back( &o2 ); refVec.push_back( &o3 ); co::Range<PseudoInterface* const> range( refVec ); for( int i = 0; i < 3; ++i ) { EXPECT_EQ( range.getFirst(), rawVec[i] ); range.popFirst(); } }
void TimeBaseGenerator::scaleFactor() { /* double T_max = (T_dur -27*SlopeRamp)/T_dur; double csi_max =(6*pow(T_max,5))-(15*pow(T_max,4))+(10*pow(T_max,3)); //6z^5-15z^4+10z^3 double csidot_max =(30*pow(T_max,4))-(60*pow(T_max,3))+(30*pow(T_max,2)); //csi_dot=30z^4-60z^3+30z^2 Gamma_max = (csidot_max)/(T_dur*(1.0001 - csi_max)); cout << "T_max: " << T_max << endl; cout << "Gamma_max :" << Gamma_max << endl; */ double csi, csidot, Gamma, tmax; tmax = 0; Gamma_max = 0; //ofstream o1("G.txt"); ofstream o2("Csi.txt"); //ofstream o3("Csidot.txt"); for (int t = (int)T_init/SlopeRamp; t < (int)(T_dur/SlopeRamp); t++) { double ti = t*SlopeRamp/T_dur; csi=(6*pow(ti,5))-(15*pow(ti,4))+(10*pow(ti,3)); //6z^5-15z^4+10z^3 csidot=(30*pow(ti,4))-(60*pow(ti,3))+(30*pow(ti,2)); //csi_dot=30z^4-60z^3+30z^2 Gamma = (csidot)/(T_dur *(alpha - (csi))); if(Gamma_max < Gamma) { Gamma_max = Gamma; tmax = ti; } //o1 << t << "\t" << Gamma << endl; o2 << t << "\t" << csi << endl; //o3 << t << "\t" << csidot << endl; } //o1 << "GAMMA MAX: " << Gamma_max <<endl; //o1.close(); o2.close(); //o3.close(); }
void test_basic() { table_t table; obj o; BOOST_TEST(table.size(&obj::m_id) == 0); BOOST_TEST(table.empty(&obj::m_id)); o.m_id = 3; table.insert(o, &obj::m_id); BOOST_TEST(o.m_id.is_linked() == true); BOOST_TEST(table.size(&obj::m_id) == 1); obj o2(o), o3; o3 = o; BOOST_TEST(o2.m_id.is_linked() == false); BOOST_TEST(o3.m_id.is_linked() == false); obj& result = table.erase_key(&obj::m_id, 3).get(); BOOST_TEST(o.m_id.is_linked() == false); BOOST_TEST(&result == &o); }
void tst_QuickPath::line() { QQmlEngine engine; QQmlComponent c1(&engine); c1.setData( "import QtQuick 2.0\n" "Path {\n" "startX: 0; startY: 0\n" "PathLine { x: 100; y: 100 }\n" "}", QUrl()); QScopedPointer<QObject> o1(c1.create()); QQuickPath *path1 = qobject_cast<QQuickPath *>(o1.data()); QVERIFY(path1); QQmlComponent c2(&engine); c2.setData( "import QtQuick 2.0\n" "Path {\n" "startX: 0; startY: 0\n" "PathLine { x: 50; y: 50 }\n" "PathLine { x: 100; y: 100 }\n" "}", QUrl()); QScopedPointer<QObject> o2(c2.create()); QQuickPath *path2 = qobject_cast<QQuickPath *>(o2.data()); QVERIFY(path2); for (int i = 0; i < 167; ++i) { qreal t = i / 167.0; QPointF p1 = path1->pointAt(t); QCOMPARE(p1.x(), p1.y()); QPointF p2 = path2->pointAt(t); QCOMPARE(p1.toPoint(), p2.toPoint()); } }
vector<vector<float> > DataSources::GetBars(int sizeX,int sizeY, int nrItems) { vector<vector<float> > out; for(int i=0;i<nrItems;i++) { vector<vector<float> > item(sizeY,vector<float>(sizeX)); // 10% chance of every bar occuring float r; bool onefound = false; for(int k=0;k<sizeY;k++) { r = (float)rand()/(float)RAND_MAX; if(r < 1.0/(float)sizeY)//0.1) { for(int j=0;j<sizeX;j++) { item[k][j] = 1.0; } onefound = true; } if(onefound == true) break; if(k == sizeY-1) k=-1; } onefound = false; for(int k=0;k<sizeX;k++) { r = (float)rand()/(float)RAND_MAX; if(r < 1.0/(float)sizeX) { for(int j=0;j<sizeY;j++) { item[j][k] = 1.0; } onefound = true; } if(onefound == true) break; if(k == sizeY-1) k=-1; } vector<float> o2(sizeX*sizeY); int index = 0; for(int x=0;x<sizeX;x++) { for(int y=0;y<sizeY;y++) { o2[index] = item[y][x]; index++; } } out.push_back(o2); } return out; }
void test_converitng_assignment_of_different_enums() { boost::optional<E2> o2(e2); boost::optional<E1> o1; o1 = o2; }
TEST(Optional, Comparisons) { Optional<int> o_; Optional<int> o1(1); Optional<int> o2(2); EXPECT_TRUE(o_ <= o_); EXPECT_TRUE(o_ == o_); EXPECT_TRUE(o_ >= o_); EXPECT_TRUE(o1 < o2); EXPECT_TRUE(o1 <= o2); EXPECT_TRUE(o1 <= o1); EXPECT_TRUE(o1 == o1); EXPECT_TRUE(o1 != o2); EXPECT_TRUE(o1 >= o1); EXPECT_TRUE(o2 >= o1); EXPECT_TRUE(o2 > o1); EXPECT_FALSE(o2 < o1); EXPECT_FALSE(o2 <= o1); EXPECT_FALSE(o2 <= o1); EXPECT_FALSE(o2 == o1); EXPECT_FALSE(o1 != o1); EXPECT_FALSE(o1 >= o2); EXPECT_FALSE(o1 >= o2); EXPECT_FALSE(o1 > o2); /* folly::Optional explicitly doesn't support comparisons with contained value EXPECT_TRUE(1 < o2); EXPECT_TRUE(1 <= o2); EXPECT_TRUE(1 <= o1); EXPECT_TRUE(1 == o1); EXPECT_TRUE(2 != o1); EXPECT_TRUE(1 >= o1); EXPECT_TRUE(2 >= o1); EXPECT_TRUE(2 > o1); EXPECT_FALSE(o2 < 1); EXPECT_FALSE(o2 <= 1); EXPECT_FALSE(o2 <= 1); EXPECT_FALSE(o2 == 1); EXPECT_FALSE(o2 != 2); EXPECT_FALSE(o1 >= 2); EXPECT_FALSE(o1 >= 2); EXPECT_FALSE(o1 > 2); */ // boost::optional does support comparison with contained value, which can // lead to confusion when a bool is contained boost::optional<int> boi(3); EXPECT_TRUE(boi < 5); EXPECT_TRUE(boi <= 4); EXPECT_TRUE(boi == 3); EXPECT_TRUE(boi != 2); EXPECT_TRUE(boi >= 1); EXPECT_TRUE(boi > 0); EXPECT_TRUE(1 < boi); EXPECT_TRUE(2 <= boi); EXPECT_TRUE(3 == boi); EXPECT_TRUE(4 != boi); EXPECT_TRUE(5 >= boi); EXPECT_TRUE(6 > boi); boost::optional<bool> bob(false); EXPECT_TRUE(bob); EXPECT_TRUE(bob == false); // well that was confusing EXPECT_FALSE(bob != false); }
int main(int argc, char **args) { // Test variable. int success_test = 1; if (argc < 2) error("Not enough parameters."); // Load the mesh. Mesh mesh; H3DReader mloader; if (!mloader.load(args[1], &mesh)) error("Loading mesh file '%s'.", args[1]); // Initialize the space 1. Ord3 o1(2, 2, 2); H1Space space1(&mesh, bc_types, NULL, o1); // Initialize the space 2. Ord3 o2(4, 4, 4); H1Space space2(&mesh, bc_types, NULL, o2); WeakForm wf(2); wf.add_matrix_form(0, 0, bilinear_form_1_1<double, scalar>, bilinear_form_1_1<Ord, Ord>, HERMES_SYM); wf.add_matrix_form(0, 1, bilinear_form_1_2<double, scalar>, bilinear_form_1_2<Ord, Ord>, HERMES_SYM); wf.add_vector_form(0, linear_form_1<double, scalar>, linear_form_1<Ord, Ord>); wf.add_matrix_form(1, 1, bilinear_form_2_2<double, scalar>, bilinear_form_2_2<Ord, Ord>, HERMES_SYM); wf.add_vector_form(1, linear_form_2<double, scalar>, linear_form_2<Ord, Ord>); // Initialize the FE problem. bool is_linear = true; DiscreteProblem dp(&wf, Tuple<Space *>(&space1, &space2), is_linear); // Initialize the solver in the case of SOLVER_PETSC or SOLVER_MUMPS. initialize_solution_environment(matrix_solver, argc, args); // Set up the solver, matrix, and rhs according to the solver selection. SparseMatrix* matrix = create_matrix(matrix_solver); Vector* rhs = create_vector(matrix_solver); Solver* solver = create_linear_solver(matrix_solver, matrix, rhs); // Initialize the preconditioner in the case of SOLVER_AZTECOO. if (matrix_solver == SOLVER_AZTECOO) { ((AztecOOSolver*) solver)->set_solver(iterative_method); ((AztecOOSolver*) solver)->set_precond(preconditioner); // Using default iteration parameters (see solver/aztecoo.h). } // Assemble the linear problem. info("Assembling (ndof: %d).", Space::get_num_dofs(Tuple<Space *>(&space1, &space2))); dp.assemble(matrix, rhs); // Solve the linear system. If successful, obtain the solution. info("Solving."); Solution sln1(&mesh); Solution sln2(&mesh); if(solver->solve()) Solution::vector_to_solutions(solver->get_solution(), Tuple<Space *>(&space1, &space2), Tuple<Solution *>(&sln1, &sln2)); else error ("Matrix solver failed.\n"); ExactSolution ex_sln1(&mesh, exact_sln_fn_1); ExactSolution ex_sln2(&mesh, exact_sln_fn_2); // Calculate exact error. info("Calculating exact error."); Adapt *adaptivity = new Adapt(Tuple<Space *>(&space1, &space2), Tuple<ProjNormType>(HERMES_H1_NORM, HERMES_H1_NORM)); bool solutions_for_adapt = false; double err_exact = adaptivity->calc_err_exact(Tuple<Solution *>(&sln1, &sln2), Tuple<Solution *>(&ex_sln1, &ex_sln2), solutions_for_adapt, HERMES_TOTAL_ERROR_ABS); if (err_exact > EPS) // Calculated solution is not precise enough. success_test = 0; // Clean up. delete matrix; delete rhs; delete solver; delete adaptivity; // Properly terminate the solver in the case of SOLVER_PETSC or SOLVER_MUMPS. finalize_solution_environment(matrix_solver); if (success_test) { info("Success!"); return ERR_SUCCESS; } else { info("Failure!"); return ERR_FAILURE; } }
static void TestOctet() { const char *str = "A test of octet strings...!@@#$%^&*()_+|~{}:,./<>?"; OctetStr o1; ACE_ASSERT(o1.valid() == 1); ACE_ASSERT(o1.length() == 0); ACE_ASSERT(o1.data() != (unsigned char *)0); ACE_DEBUG ((LM_DEBUG, "(%P|%t) Octet:o1(\"\") [%s]\n", o1.to_string())); o1.set_data((SmiBYTE *)str); ACE_ASSERT(!ACE_OS::strcmp(str, (char *)o1.data())); ACE_DEBUG ((LM_DEBUG, "(%P|%t) Octet:o1(\"str\") [%s]\n", o1.to_string())); OctetStr o2(str); ACE_ASSERT(o2.valid() == 1); ACE_ASSERT(o2.data() != (unsigned char *)0); ACE_DEBUG ((LM_DEBUG, "(%P|%t) Octet:o2(\"str\") [%s]\n", o2.to_string())); OctetStr o3(str, 4); // test setting less than full string length ACE_ASSERT(o3.valid() == 1); ACE_ASSERT(o3.length() == 4); ACE_DEBUG ((LM_DEBUG, "(%P|%t) Octet:o3(\"A te\") [%s]\n", o3.to_string())); OctetStr o4(o3); // test setting less than full string length ACE_DEBUG ((LM_DEBUG, "(%P|%t) Octet:o4(\"A te\") [%s]\n", o4.to_string())); ACE_ASSERT(o4.valid() == 1); ACE_ASSERT(o4.length() == 4); OctetStr o5; o5 = str; ACE_ASSERT(o5.valid() == 1); ACE_ASSERT(o5.length() == ACE_OS::strlen(str)); ACE_DEBUG ((LM_DEBUG, "(%P|%t) Octet:o5(\"str\") [%s]\n", o5.to_string())); OctetStr o6; o6 = o5; ACE_ASSERT(o6.valid() == 1); ACE_ASSERT(o5.length() == o6.length()); ACE_DEBUG ((LM_DEBUG, "(%P|%t) Octet:o6(\"str\") [%s]\n", o6.to_string())); o6 += o3; o6 = ""; o6 += str; o6 += '#'; ACE_ASSERT(o6[0] == (SmiBYTE) 'A'); ACE_DEBUG ((LM_DEBUG, "(%P|%t) Octet:o6(\"str\") [%s]\n", o6.to_string())); ACE_ASSERT(!(o3 < o3)); ACE_ASSERT(!(o3 > o3)); ACE_ASSERT(o3 >= o3); ACE_ASSERT(o3 <= o3); ACE_ASSERT(o3 == o3); ACE_ASSERT(!(o3 != o3)); }
void test_distance_capsule_box() { using CollisionGeometryPtr_t = std::shared_ptr<fcl::CollisionGeometry<S>>; // Capsule of radius 2 and of height 4 CollisionGeometryPtr_t capsuleGeometry (new fcl::Capsule<S> (2., 4.)); // Box of size 1 by 2 by 4 CollisionGeometryPtr_t boxGeometry (new fcl::Box<S> (1., 2., 4.)); // Enable computation of nearest points fcl::DistanceRequest<S> distanceRequest (true); fcl::DistanceResult<S> distanceResult; fcl::Transform3<S> tf1(fcl::Translation3<S>(fcl::Vector3<S> (3., 0, 0))); fcl::Transform3<S> tf2 = fcl::Transform3<S>::Identity(); fcl::CollisionObject<S> capsule (capsuleGeometry, tf1); fcl::CollisionObject<S> box (boxGeometry, tf2); // test distance fcl::distance (&capsule, &box, distanceRequest, distanceResult); // Nearest point on capsule fcl::Vector3<S> o1 (distanceResult.nearest_points [0]); // Nearest point on box fcl::Vector3<S> o2 (distanceResult.nearest_points [1]); EXPECT_NEAR (distanceResult.min_distance, 0.5, 1e-4); EXPECT_NEAR (o1 [0], -2.0, 1e-4); EXPECT_NEAR (o1 [1], 0.0, 1e-4); EXPECT_NEAR (o2 [0], 0.5, 1e-4); EXPECT_NEAR (o1 [1], 0.0, 1e-4); // TODO(JS): maybe o2 rather than o1? // Move capsule above box tf1 = fcl::Translation3<S>(fcl::Vector3<S> (0., 0., 8.)); capsule.setTransform (tf1); // test distance distanceResult.clear (); fcl::distance (&capsule, &box, distanceRequest, distanceResult); o1 = distanceResult.nearest_points [0]; o2 = distanceResult.nearest_points [1]; EXPECT_NEAR (distanceResult.min_distance, 2.0, 1e-4); EXPECT_NEAR (o1 [0], 0.0, 1e-4); EXPECT_NEAR (o1 [1], 0.0, 1e-4); EXPECT_NEAR (o1 [2], -4.0, 1e-4); // Disabled broken test lines. Please see #25. // CHECK_CLOSE_TO_0 (o2 [0], 1e-4); EXPECT_NEAR (o2 [1], 0.0, 1e-4); EXPECT_NEAR (o2 [2], 2.0, 1e-4); // Rotate capsule around y axis by pi/2 and move it behind box tf1.translation() = fcl::Vector3<S>(-10., 0., 0.); tf1.linear() = fcl::Quaternion<S>(sqrt(2)/2, 0, sqrt(2)/2, 0).toRotationMatrix(); capsule.setTransform (tf1); // test distance distanceResult.clear (); fcl::distance (&capsule, &box, distanceRequest, distanceResult); o1 = distanceResult.nearest_points [0]; o2 = distanceResult.nearest_points [1]; EXPECT_NEAR (distanceResult.min_distance, 5.5, 1e-4); EXPECT_NEAR (o1 [0], 0.0, 1e-4); EXPECT_NEAR (o1 [1], 0.0, 1e-4); EXPECT_NEAR (o1 [2], 4.0, 1e-4); EXPECT_NEAR (o2 [0], -0.5, 1e-4); EXPECT_NEAR (o2 [1], 0.0, 1e-4); EXPECT_NEAR (o2 [2], 0.0, 1e-4); }
int go(int argc){ seal::PluginManager::get()->initialise(); pool::URIParser p; p.parse(); pool::IFileCatalog lcat; pool::IFileCatalog * cat = &lcat; cat->setWriteCatalog(p.contactstring()); cat->connect(); cat->start(); pool::IDataSvc *svc = pool::DataSvcFactory::instance(cat); // Define the policy for the implicit file handling pool::DatabaseConnectionPolicy policy; policy.setWriteModeForNonExisting(pool::DatabaseConnectionPolicy::CREATE); // policy.setWriteModeForExisting(pool::DatabaseConnectionPolicy::OVERWRITE); policy.setWriteModeForExisting(pool::DatabaseConnectionPolicy::UPDATE); svc->session().setDefaultConnectionPolicy(policy); svc->transaction().start(pool::ITransaction::UPDATE); std::vector<pool::Ref<TT<T1> > > refs; std::string vten[] = { "0","1","2","3","4","5","6","7","8","9","10"}; std::vector<std::string> ten(vten,vten+11); std::vector<std::string>::const_iterator s = ten.begin(); for (;s!=ten.end();s++) { std::string f = std::string("E")+ (*s); std::string c = std::string("C")+ (*s); pool::Ref<TT<T1> > o1(svc, new TT<T1>); pool::Placement place(f, pool::DatabaseSpecification::PFN, c, ROOT::Reflex::Type(), pool::ROOTKEY_StorageType.type()); // This will also register the file. For this to occur, the placement object must use a PFN. o1.markWrite(place); refs.push_back(o1); } pool::Ref<TMe > o6(svc, new TMe); { pool::Placement place("E0", pool::DatabaseSpecification::PFN, "C0", ROOT::Reflex::Type(), pool::ROOTKEY_StorageType.type()); // This will also register the file. For this to occur, the placement object must use a PFN. o6.markWrite(place); } pool::Ref<TVoid> o7(svc, new TVoid); { pool::Placement place("E0", pool::DatabaseSpecification::PFN, "C0", ROOT::Reflex::Type(), pool::ROOTKEY_StorageType.type()); // This will also register the file. For this to occur, the placement object must use a PFN. o7.markWrite(place); } svc->transaction().commit(); svc->session().disconnectAll(); // cat->commit(); // cat->start(); svc->transaction().start(pool::ITransaction::UPDATE); pool::Ref<TT<T1> > o1(svc, new TT<T1>); { pool::Placement place("DN", pool::DatabaseSpecification::PFN, "L", ROOT::Reflex::Type(), pool::ROOTKEY_StorageType.type()); // This will also register the file. For this to occur, the placement object must use a PFN. o1.markWrite(place); } pool::Ref<TT<T2> > o2(svc, new TT<T2>); { pool::Placement place("EN", pool::DatabaseSpecification::PFN, "N", ROOT::Reflex::Type(), pool::ROOTKEY_StorageType.type()); // This will also register the file. For this to occur, the placement object must use a PFN. o2.markWrite(place); } // o1->bs.push_back(o2); // o2->c=o1; pool::Collection<TT<T1> > collection(svc, "ImplicitCollection", "PFN:DN", "L", pool::ICollection::READ) ; pool::Collection<TT<T1> >::Iterator iter = collection.select(); while (iter.next()) { std::cout << iter.ref().toString() << std::endl; std::cout << (*iter).i << std::endl; } std::vector<pool::Ref<TT<T1> > >::const_iterator r = refs.begin(); int n=0; for (;r!=refs.end();r++) { n++; std::cout << r->toString() << std::endl; if (n==2||n==8) r->markUpdate(); } svc->transaction().commit(); svc->session().disconnectAll(); svc->cacheSvc().resetCache(); svc->transaction().start(pool::ITransaction::READ); std::cout << "o6 " << o6.isNull() << " " << (*o6->me.get()).i << std::endl; std::cout << "o7 " << o7.isNull() << " " << (*o7->get()).i << std::endl; svc->transaction().commit(); svc->session().disconnectAll(); cat->commit(); delete svc; return 0; }
void test_distance_capsule_box(fcl::GJKSolverType solver_type, S solver_tolerance, S test_tolerance) { using CollisionGeometryPtr_t = std::shared_ptr<fcl::CollisionGeometry<S>>; // Capsule of radius 2 and of height 4 CollisionGeometryPtr_t capsuleGeometry (new fcl::Capsule<S> (2., 4.)); // Box of size 1 by 2 by 4 CollisionGeometryPtr_t boxGeometry (new fcl::Box<S> (1., 2., 4.)); // Enable computation of nearest points fcl::DistanceRequest<S> distanceRequest (true); fcl::DistanceResult<S> distanceResult; distanceRequest.gjk_solver_type = solver_type; distanceRequest.distance_tolerance = solver_tolerance; fcl::Transform3<S> tf1(fcl::Translation3<S>(fcl::Vector3<S> (3., 0, 0))); fcl::Transform3<S> tf2 = fcl::Transform3<S>::Identity(); fcl::CollisionObject<S> capsule (capsuleGeometry, tf1); fcl::CollisionObject<S> box (boxGeometry, tf2); // test distance fcl::distance (&capsule, &box, distanceRequest, distanceResult); // Nearest point on capsule fcl::Vector3<S> o1 (distanceResult.nearest_points [0]); // Nearest point on box fcl::Vector3<S> o2 (distanceResult.nearest_points [1]); EXPECT_NEAR (distanceResult.min_distance, 0.5, test_tolerance); EXPECT_NEAR (o1 [0], 1.0, test_tolerance); EXPECT_NEAR (o1 [1], 0.0, test_tolerance); EXPECT_NEAR (o2 [0], 0.5, test_tolerance); EXPECT_NEAR (o2 [1], 0.0, test_tolerance); // Move capsule above box tf1 = fcl::Translation3<S>(fcl::Vector3<S> (0., 0., 8.)); capsule.setTransform (tf1); // test distance distanceResult.clear (); fcl::distance (&capsule, &box, distanceRequest, distanceResult); o1 = distanceResult.nearest_points [0]; o2 = distanceResult.nearest_points [1]; EXPECT_NEAR (distanceResult.min_distance, 2.0, test_tolerance); EXPECT_NEAR (o1 [0], 0.0, test_tolerance); EXPECT_NEAR (o1 [1], 0.0, test_tolerance); EXPECT_NEAR (o1 [2], 4.0, test_tolerance); EXPECT_NEAR (o2 [0], 0.0, test_tolerance); EXPECT_NEAR (o2 [1], 0.0, test_tolerance); EXPECT_NEAR (o2 [2], 2.0, test_tolerance); // Rotate capsule around y axis by pi/2 and move it behind box tf1.translation() = fcl::Vector3<S>(-10., 0., 0.); tf1.linear() = fcl::Quaternion<S>(sqrt(2)/2, 0, sqrt(2)/2, 0).toRotationMatrix(); capsule.setTransform (tf1); // test distance distanceResult.clear (); fcl::distance (&capsule, &box, distanceRequest, distanceResult); o1 = distanceResult.nearest_points [0]; o2 = distanceResult.nearest_points [1]; EXPECT_NEAR (distanceResult.min_distance, 5.5, test_tolerance); EXPECT_NEAR (o1 [0], -6.0, test_tolerance); EXPECT_NEAR (o1 [1], 0.0, test_tolerance); EXPECT_NEAR (o1 [2], 0.0, test_tolerance); EXPECT_NEAR (o2 [0], -0.5, test_tolerance); EXPECT_NEAR (o2 [1], 0.0, test_tolerance); EXPECT_NEAR (o2 [2], 0.0, test_tolerance); }
void *aThread( void *ptr ) { isRunning++; while (keepRunning) { std::set<protocol::inventory_vector> v3Objects = database->getObjects(3); std::set<std::string> hashes; for (std::set<protocol::inventory_vector>::iterator it = v3Objects.begin(); it != v3Objects.end(); it++) { protocol::object o = database->getObject(*it); hashes.insert(o.getContentHash()); } std::set<protocol::inventory_vector> v2Objects = database->getObjects(2); std::set<protocol::inventory_vector> bridgeObjects; for (std::set<protocol::inventory_vector>::iterator it = v2Objects.begin(); it != v2Objects.end(); it++) { protocol::object o = database->getObject(*it); if ( /*(o.getType() != protocol::message::broadcast) && //we dont bridge broadcasts*/ (o.getPayload().size() < (256*1024)) && (o.getPayload().size() > 16) && (hashes.find(o.getContentHash()) == hashes.end())) bridgeObjects.insert(*it); } if (!bridgeObjects.empty()) { long num = rand() % bridgeObjects.size(); for (int i = 0; i < num; i++) { if (!bridgeObjects.empty()) bridgeObjects.erase(*bridgeObjects.begin()); } if (!bridgeObjects.empty()) { protocol::object o = database->getObject(*bridgeObjects.begin()); protocol::wPayload p; uint64_t time = o.getTime(); uint64_t nonceTime = (60 * 60 * 60); switch (o.getType()) { case protocol::message::msg: time += nonceTime; p.push_back(time); p.push_back((uint32_t)2); break; case protocol::message::getpubkey: time += nonceTime; p.push_back(time); p.push_back((uint32_t)0); break; case protocol::message::pubkey: nonceTime = (28 * 24 * 60 * 60); time += nonceTime; p.push_back(time); p.push_back((uint32_t)1); break; case protocol::message::broadcast: time += nonceTime; p.push_back(time); p.push_back((uint32_t)3); break; default: break; } const uint8_t* pp = *o.getPayload(); pp += 16; for (int i=0; i < (o.getPayload().size()-16); i++) p.push_back(*(pp + i)); uint8_t initialHash[SHA512_DIGEST_LENGTH]; uint8_t buffer[8+SHA512_DIGEST_LENGTH]; uint64_t s = p.size() + 1000; uint64_t target = (uint64_t)(0x8000000000000000) / ((s+(nonceTime*s/65536)) * 500); SHA512(*p, p.size(), initialHash); memcpy(&buffer[8], initialHash, SHA512_DIGEST_LENGTH); uint64_t trialValue = (uint64_t)0xffffffffffffffff; uint64_t nonce = 0; uint8_t resultHash1[SHA512_DIGEST_LENGTH]; uint8_t resultHash2[SHA512_DIGEST_LENGTH]; while (trialValue > target) { nonce++; memcpy(buffer, &nonce, 8); SHA512(buffer, SHA512_DIGEST_LENGTH + 8, resultHash1); SHA512(resultHash1, SHA512_DIGEST_LENGTH, resultHash2); memcpy(&trialValue, resultHash2, sizeof(trialValue)); trialValue = protocol::Payload::htonll(trialValue); } protocol::wPayload p2; p2.push_back(protocol::Payload::htonll(nonce)); p2.push_back(p); protocol::object o2(protocol::message::object,p2); if (o2.PowOk()) printf("generated a V3 object\n"); database->addObject(0,o2); } else { sleep(5); } } else { sleep(3+(rand() % 10)); } } isRunning--; return 0; }
int main (int argc, char *argv[]) { copy_const o1,o2(o1); return 0; }/* main */
int testSatisfyNode() { int errors = 0; shared_ptr<NodeContent> nilNode = NodeContent::makeNILNode(); shared_ptr<NodeContent> orNode = NodeContent::makeOrNode(3); shared_ptr<NodeContent> andNode = NodeContent::makeAndNode(2); shared_ptr<NodeContent> thrNode = NodeContent::makeThreshNode(4,3); shared_ptr<NodeContent> leaf1 = NodeContent::makeLeafNode(1); shared_ptr<NodeContent> leaf2 = NodeContent::makeLeafNode(2); shared_ptr<NodeContent> leaf3 = NodeContent::makeLeafNode(3); shared_ptr<NodeContent> leaf4 = NodeContent::makeLeafNode(4); std::shared_ptr<TreeNode> nilTree = TreeNode::makeTree(nilNode); std::shared_ptr<TreeNode> orTree = TreeNode::makeTree(orNode); std::shared_ptr<TreeNode> andTree = TreeNode::makeTree(andNode); std::shared_ptr<TreeNode> thrTree = TreeNode::makeTree(thrNode); orTree->appendChild(leaf1); orTree->appendChild(leaf2); orTree->appendChild(leaf3); andTree->appendChild(leaf3); andTree->appendChild(leaf4); thrTree->appendChild(leaf1); thrTree->appendChild(leaf2); thrTree->appendChild(leaf3); thrTree->appendChild(leaf4); ShareTuple o1(1, 0, "0:0"); ShareTuple o2(2, 0, "0:1"); ShareTuple o3(3, 0, "0:2"); ShareTuple a3(3,0,"0:0"); ShareTuple a4(4,0,"0:1"); ShareTuple t1(1,0,"0:0"); ShareTuple t2(2,0,"0:1"); ShareTuple t3(3,0,"0:2"); ShareTuple t4(4,0,"0:3"); vector<ShareTuple> v_o1; v_o1.push_back(o1); vector<ShareTuple> v_o2; v_o2.push_back(o2); vector<ShareTuple> v_o3; v_o3.push_back(o3); vector<ShareTuple> v_o12; v_o12.push_back(o1); v_o12.push_back(o2); vector<ShareTuple> v_o13; v_o13.push_back(o1); v_o13.push_back(o3); vector<ShareTuple> v_a3; v_a3.push_back(a3); vector<ShareTuple> v_a4; v_a4.push_back(a4); vector<ShareTuple> v_a34; v_a34.push_back(a3); v_a34.push_back(a4); vector<ShareTuple> v_t1; v_t1.push_back(t1); vector<ShareTuple> v_t12; v_t12.push_back(t1); v_t12.push_back(t2); vector<ShareTuple> v_t123; v_t123.push_back(t1); v_t123.push_back(t2); v_t123.push_back(t3); vector<ShareTuple> v_t1234; v_t1234.push_back(t1); v_t1234.push_back(t2); v_t1234.push_back(t3); v_t1234.push_back(t4); vector<ShareTuple> v_oat; v_oat.push_back(o1); v_oat.push_back(t2); v_oat.push_back(a3); vector<ShareTuple> v_oa; v_oa.push_back(o3); v_oa.push_back(a4); vector<ShareTuple> v_tt; v_tt.push_back(t1); v_tt.push_back(t2); v_tt.push_back(t2); vector<ShareTuple> w_o1; w_o1.push_back(o1); vector<ShareTuple> w_o2; w_o2.push_back(o2); vector<ShareTuple> w_o3; w_o3.push_back(o3); vector<ShareTuple> w_o12; w_o12.push_back(o1); vector<ShareTuple> w_o13; w_o13.push_back(o1); vector<ShareTuple> w_a3; vector<ShareTuple> w_a4; vector<ShareTuple> w_a34; w_a34.push_back(a3); w_a34.push_back(a4); vector<ShareTuple> w_t1; w_t1.push_back(t1); vector<ShareTuple> w_t12; vector<ShareTuple> w_t123; w_t123.push_back(t1); w_t123.push_back(t2); w_t123.push_back(t3); vector<ShareTuple> w_t1234; w_t1234.push_back(t1); w_t1234.push_back(t2); w_t1234.push_back(t3); vector<ShareTuple> w_oat; vector<ShareTuple> w_oa; w_oa.push_back(o3); w_oa.push_back(a4); vector<ShareTuple> w_tt; vector<ShareTuple> witnessVector; DEBUG("nil tree"); // NIL TREE bool b; bool verif_b; b = BLAccessPolicy::satisfyNode(nilTree, v_t1234, witnessVector); test_diagnosis("testSatisfyNode - [nilTree] [v_1234]", !b, errors); test_diagnosis("testSatisfyNode - [nilTree] [v_1234] - witness vector", witnessVector.empty(), errors); witnessVector.clear(); // OR TREE vector<vector<ShareTuple>> orTestList; orTestList.push_back(v_o1); orTestList.push_back(v_o2); orTestList.push_back(v_o3); orTestList.push_back(v_o1); orTestList.push_back(v_o13); orTestList.push_back(v_oat); orTestList.push_back(v_oa); orTestList.push_back(v_tt); vector<vector<ShareTuple>> orWitnessList; orWitnessList.push_back(w_o1); orWitnessList.push_back(w_o2); orWitnessList.push_back(w_o3); orWitnessList.push_back(w_o1); orWitnessList.push_back(w_o13); orWitnessList.push_back(w_o1); orWitnessList.push_back(w_o3); orWitnessList.push_back(w_t1); for (unsigned int i = 0; i < orTestList.size(); i++) { b = BLAccessPolicy::satisfyNode(orTree, orTestList[i], witnessVector); stringstream ss(""); ss << "testSatisfyNode - [orTree]: " << i; if (orWitnessList[i].empty()) { verif_b = false; } else { verif_b = true; } test_diagnosis(ss.str(), b = verif_b, errors); test_diagnosis(ss.str() + " - Witness vector", witnessVector == orWitnessList[i], errors); ENHDEBUG("Checking vectors" << i); DEBUG("Sizes: " << witnessVector.size() << " - " << orWitnessList[i].size()); for (unsigned int j = 0; j < witnessVector.size(); j++) { DEBUG("Witness: " << witnessVector[j].to_string()); DEBUG("Returned: " << orWitnessList[i][j].to_string()); } witnessVector.clear(); } // AND TREE ENHDEBUG("AND POLICY"); DEBUG("And tree: " << andTree->to_string()); shared_ptr<TreeNode> child = andTree->getChild(0); shared_ptr<NodeContent> node = child->getNode(); DEBUG("child 0 node: " << child->to_string()); DEBUG("Node ID " << node->getNodeID()); vector<vector<ShareTuple>> andTestList; andTestList.push_back(v_a3); andTestList.push_back(v_a4); andTestList.push_back(v_a34); andTestList.push_back(v_oat); andTestList.push_back(v_oa); andTestList.push_back(v_tt); vector<vector<ShareTuple>> andWitnessList; andWitnessList.push_back(w_a3); andWitnessList.push_back(w_a4); andWitnessList.push_back(w_a34); andWitnessList.push_back(w_oat); andWitnessList.push_back(w_oa); andWitnessList.push_back(w_tt); for (unsigned int i = 0; i < andTestList.size(); i++) { b = BLAccessPolicy::satisfyNode(andTree, andTestList[i], witnessVector); stringstream ss(""); ss << "testSatisfyNode - [andTree]: " << i; if (andWitnessList[i].empty()) { verif_b = false; } else { verif_b = true; } test_diagnosis(ss.str(), b = verif_b, errors); test_diagnosis(ss.str() + " - Witness vector", witnessVector == andWitnessList[i], errors); ENHDEBUG("Checking vectors" << i); DEBUG("Sizes: " << witnessVector.size() << " - " << andWitnessList[i].size()); for (unsigned int j = 0; j < witnessVector.size(); j++) { DEBUG("Witness: " << witnessVector[j].to_string()); DEBUG("Returned: " << andWitnessList[i][j].to_string()); } witnessVector.clear(); } return errors; }
int main(int argc, char **args) { int res = ERR_SUCCESS; #ifdef WITH_PETSC PetscInitialize(&argc, &args, (char *) PETSC_NULL, PETSC_NULL); #endif set_verbose(false); if (argc < 2) error("Not enough parameters"); H1ShapesetLobattoHex shapeset; printf("* Loading mesh '%s'\n", args[1]); Mesh mesh; Mesh3DReader mesh_loader; if (!mesh_loader.load(args[1], &mesh)) error("Loading mesh file '%s'\n", args[1]); printf("* Setup space #1\n"); H1Space space1(&mesh, &shapeset); space1.set_bc_types(bc_types); order3_t o1(2, 2, 2); printf(" - Setting uniform order to (%d, %d, %d)\n", o1.x, o1.y, o1.z); space1.set_uniform_order(o1); printf("* Setup space #2\n"); H1Space space2(&mesh, &shapeset); space2.set_bc_types(bc_types); order3_t o2(4, 4, 4); printf(" - Setting uniform order to (%d, %d, %d)\n", o2.x, o2.y, o2.z); space2.set_uniform_order(o2); int ndofs = 0; ndofs += space1.assign_dofs(); ndofs += space2.assign_dofs(ndofs); printf(" - Number of DOFs: %d\n", ndofs); printf("* Calculating a solution\n"); #if defined WITH_UMFPACK UMFPackMatrix mat; UMFPackVector rhs; UMFPackLinearSolver solver(&mat, &rhs); #elif defined WITH_PARDISO PardisoMatrix mat; PardisoVector rhs; PardisoLinearSolver solver(&mat, &rhs); #elif defined WITH_PETSC PetscMatrix mat; PetscVector rhs; PetscLinearSolver solver(&mat, &rhs); #elif defined WITH_MUMPS MumpsMatrix mat; MumpsVector rhs; MumpsSolver solver(&mat, &rhs); #endif WeakForm wf(2); wf.add_matrix_form(0, 0, bilinear_form_1<double, scalar>, bilinear_form_1<ord_t, ord_t>, SYM); wf.add_vector_form(0, linear_form_1<double, scalar>, linear_form_1<ord_t, ord_t>); wf.add_matrix_form(1, 1, bilinear_form_2<double, scalar>, bilinear_form_2<ord_t, ord_t>, SYM); wf.add_vector_form(1, linear_form_2<double, scalar>, linear_form_2<ord_t, ord_t>); LinearProblem lp(&wf, Tuple<Space *>(&space1, &space2)); // assemble stiffness matrix Timer assemble_timer("Assembling stiffness matrix"); assemble_timer.start(); lp.assemble(&mat, &rhs); assemble_timer.stop(); // solve the stiffness matrix Timer solve_timer("Solving stiffness matrix"); solve_timer.start(); bool solved = solver.solve(); solve_timer.stop(); // output the measured values printf("%s: %s (%lf secs)\n", assemble_timer.get_name(), assemble_timer.get_human_time(), assemble_timer.get_seconds()); printf("%s: %s (%lf secs)\n", solve_timer.get_name(), solve_timer.get_human_time(), solve_timer.get_seconds()); if (solved) { // solution 1 Solution sln1(&mesh); sln1.set_coeff_vector(&space1, solver.get_solution()); ExactSolution esln1(&mesh, exact_sln_fn_1); // norm double h1_sln_norm1 = h1_norm(&sln1); double h1_err_norm1 = h1_error(&sln1, &esln1); printf(" - H1 solution norm: % le\n", h1_sln_norm1); printf(" - H1 error norm: % le\n", h1_err_norm1); double l2_sln_norm1 = l2_norm(&sln1); double l2_err_norm1 = l2_error(&sln1, &esln1); printf(" - L2 solution norm: % le\n", l2_sln_norm1); printf(" - L2 error norm: % le\n", l2_err_norm1); if (h1_err_norm1 > EPS || l2_err_norm1 > EPS) { // calculated solution is not enough precise res = ERR_FAILURE; } // solution 2 Solution sln2(&mesh); sln2.set_coeff_vector(&space2, solver.get_solution()); ExactSolution esln2(&mesh, exact_sln_fn_2); // norm double h1_sln_norm2 = h1_norm(&sln2); double h1_err_norm2 = h1_error(&sln2, &esln2); printf(" - H1 solution norm: % le\n", h1_sln_norm2); printf(" - H1 error norm: % le\n", h1_err_norm2); double l2_sln_norm2 = l2_norm(&sln2); double l2_err_norm2 = l2_error(&sln2, &esln2); printf(" - L2 solution norm: % le\n", l2_sln_norm2); printf(" - L2 error norm: % le\n", l2_err_norm2); if (h1_err_norm2 > EPS || l2_err_norm2 > EPS) { // calculated solution is not enough precise res = ERR_FAILURE; } #ifdef OUTPUT_DIR // output const char *of_name = OUTPUT_DIR "/solution.pos"; FILE *ofile = fopen(of_name, "w"); if (ofile != NULL) { GmshOutputEngine output(ofile); output.out(&sln1, "Uh_1"); output.out(&esln1, "U1"); output.out(&sln2, "Uh_2"); output.out(&esln2, "U2"); fclose(ofile); } else { warning("Can not open '%s' for writing.", of_name); } #endif } #ifdef WITH_PETSC mat.free(); rhs.free(); PetscFinalize(); #endif TRACE_END; return res; }
int main(int argc) { seal::PluginManager::get()->initialise(); pool::URIParser p; p.parse(); pool::IFileCatalog lcat; pool::IFileCatalog * cat = &lcat; cat->setWriteCatalog(p.contactstring()); cat->connect(); cat->start(); pool::IDataSvc *svc = pool::DataSvcFactory::instance(cat); // Define the policy for the implicit file handling pool::DatabaseConnectionPolicy policy; policy.setWriteModeForNonExisting(pool::DatabaseConnectionPolicy::CREATE); // policy.setWriteModeForExisting(pool::DatabaseConnectionPolicy::OVERWRITE); policy.setWriteModeForExisting(pool::DatabaseConnectionPolicy::UPDATE); svc->session().setDefaultConnectionPolicy(policy); svc->transaction().start(pool::ITransaction::UPDATE); pool::Ref<NavigationTests::AS> as(svc, new NavigationTests::AS); { pool::Placement place("DN", pool::DatabaseSpecification::PFN, "L", ROOT::Reflex::Type(), pool::ROOTKEY_StorageType.type()); // This will also register the file. For this to occur, the placement object must use a PFN. as.markWrite(place); } as->p.t=new NavigationTests::BT; as->p.t->k = 3; // svc->transaction().start(pool::ITransaction::UPDATE); pool::Ref<NavigationTests::T2> o1(svc, new NavigationTests::T2); { pool::Placement place("DN", pool::DatabaseSpecification::PFN, "L", ROOT::Reflex::Type(), pool::ROOTKEY_StorageType.type()); // This will also register the file. For this to occur, the placement object must use a PFN. o1.markWrite(place); } pool::Ref<NavigationTests::T2> o2(svc, new NavigationTests::T2); { pool::Placement place("DN", pool::DatabaseSpecification::PFN, "L", ROOT::Reflex::Type(), pool::ROOTKEY_StorageType.type()); // This will also register the file. For this to occur, the placement object must use a PFN. o2.markWrite(place); } pool::Ref<NavigationTests::T2> o3(svc, new NavigationTests::T2); { pool::Placement place("DN", pool::DatabaseSpecification::PFN, "L", ROOT::Reflex::Type(), pool::ROOTKEY_StorageType.type()); // This will also register the file. For this to occur, the placement object must use a PFN. o3.markWrite(place); } pool::Ref<NavigationTests::T2> o5(svc, new NavigationTests::T2); { pool::Placement place("DN", pool::DatabaseSpecification::PFN, "L", ROOT::Reflex::Type(), pool::ROOTKEY_StorageType.type()); // This will also register the file. For this to occur, the placement object must use a PFN. o5.markWrite(place); } pool::Ref<NavigationTests::K> o4(svc, new NavigationTests::K); { pool::Placement place("DN", pool::DatabaseSpecification::PFN, "K", ROOT::Reflex::Type(), pool::ROOTKEY_StorageType.type()); // This will also register the file. For this to occur, the placement object must use a PFN. o4.markWrite(place); } o3->bs.push_back(o1); o3->bs.push_back(o2); o3->bs.push_back(o5); o5->bs.push_back(o2); std::cout << "vec size " << o3->bs.size() << std::endl; // svc->cacheSvc().resetCache(); o1.reset(); std::cout << "o1 " << o1.toString() << std::endl; std::cout << "o1 o " << o1.isOpen() <<std:: endl; std::cout << "o1 p " << o1.isNull() << std::endl; std::cout << "o2 p " << o2.isNull() << std::endl; svc->transaction().commit(); svc->session().disconnectAll(); svc->cacheSvc().resetCache(); svc->transaction().start(pool::ITransaction::UPDATE); // std::cout << "o1 p " << o1.isNull() << std::endl; std::cout << "o1 " << o1.toString() << std::endl; std::cout << "o1 o " << o1.isOpen() <<std:: endl; std::cout << "o1 p " << o1.isNull() << std::endl; o1.markDelete(); o1.reset(); std::cout << "after delete and reset" << std::endl; std::cout << "o1 " << o1.toString() << std::endl; std::cout << "o1 o " << o1.isOpen() <<std:: endl; std::cout << "o1 p " << o1.isNull() << std::endl; std::cout << "o2 d " << o2.toString() << std::endl; std::cout << "o2 t " << o2.token() << std::endl; std::cout << "o2 p " << o2.isNull() << std::endl; svc->transaction().commit(); svc->session().disconnectAll(); svc->transaction().start(pool::ITransaction::UPDATE); std::cout << "vec size " << o3->bs.size() << std::endl; std::cout << "here we do not die anymore..." << std::endl; std::cout << "o2 d " << o2.toString() << std::endl; std::cout << "o2 t " << o2.token() << std::endl; std::cout << "o2 p " << o2.isNull() << std::endl; pool::Ref<NavigationTests::T2> o22 = o2; svc->transaction().commit(); svc->session().disconnectAll(); svc->cacheSvc().resetCache(); svc->transaction().start(pool::ITransaction::UPDATE); std::cout << "vec size " << o3->bs.size() << std::endl; o3->bs.push_back(o5); o3.markUpdate(); std::cout << "vec size " << o3->bs.size() << std::endl; svc->transaction().commit(); if (argc>1) svc->session().disconnectAll(); svc->cacheSvc().resetCache(); svc->transaction().start(pool::ITransaction::UPDATE); std::cout << "vec size " << o3->bs.size() << std::endl; o3->bs.push_back(o5); std::cout << "vec size " << o3->bs.size() << std::endl; o3.markUpdate(); svc->transaction().commit(); svc->session().disconnectAll(); svc->cacheSvc().resetCache(); svc->transaction().start(pool::ITransaction::UPDATE); std::cout << "o1 d " << o1.toString() << std::endl; std::cout << "o1 t " << o1.token() << std::endl; std::cout << "o1 p " << o1.isNull() << std::endl; std::cout << "o2 d " << o2.toString() << std::endl; std::cout << "o2 t " << o2.token() << std::endl; std::cout << "o2 p " << o2.isNull() << std::endl; /// this is true??? svc->transaction().commit(); svc->session().disconnectAll(); try { svc->transaction().start(pool::ITransaction::UPDATE); std::cout << "o2 d " << o2.toString() << std::endl; std::cout << "o2 t " << o2.token() << std::endl; std::cout << "o2 p " << o2.isNull() << std::endl; o2.markUpdate(); std::cout << "after update 1" << std::endl; o2.markDelete(); std::cout << "after delete 1" << std::endl; o2.markUpdate(); std::cout << "after update 2" << std::endl; o2.markDelete(); std::cout << "after delete 2" << std::endl; o22.markDelete(); std::cout << "after delete 22" << std::endl; o3.markDelete(); std::cout << "after delete 3" << std::endl; pool::Ref<NavigationTests::T2> ol(svc, new NavigationTests::T2); { pool::Placement place("DN", pool::DatabaseSpecification::PFN, "L", ROOT::Reflex::Type(), pool::ROOTKEY_StorageType.type()); // This will also register the file. For this to occur, the placement object must use a PFN. ol.markWrite(place); } svc->transaction().commit(); svc->session().disconnectAll(); } catch(const seal::Error& er){ std::cout << "caught seal exception " << std::endl; std::cerr << er.explainSelf(); std::cerr << std::endl; svc->transaction().commit(); svc->session().disconnectAll(); } svc->transaction().start(pool::ITransaction::UPDATE); pool::Ref<NavigationTests::T2> oA(svc,new NavigationTests::T2); { pool::Placement place("DN", pool::DatabaseSpecification::PFN, "L", ROOT::Reflex::Type(), pool::ROOTKEY_StorageType.type()); // This will also register the file. For this to occur, the placement object must use a PFN. oA.markWrite(place); } svc->transaction().commit(); svc->session().disconnectAll(); svc->transaction().start(pool::ITransaction::UPDATE); oA.markDelete(); pool::Ref<NavigationTests::T2> oB(svc,new NavigationTests::T2); { pool::Placement place("DN", pool::DatabaseSpecification::PFN, "L", ROOT::Reflex::Type(), pool::ROOTKEY_StorageType.type()); // This will also register the file. For this to occur, the placement object must use a PFN. oB.markWrite(place); } oA = oB; svc->transaction().commit(); svc->session().disconnectAll(); try { svc->transaction().start(pool::ITransaction::UPDATE); oA.markDelete(); std::cout << "after delete A" << std::endl; svc->transaction().commit(); svc->session().disconnectAll(); } catch(const seal::Error& er){ std::cout << "caught seal exception " << std::endl; std::cerr << er.explainSelf(); std::cerr << std::endl; svc->transaction().commit(); svc->session().disconnectAll(); } try { svc->transaction().start(pool::ITransaction::UPDATE); o5.markDelete(); std::cout << "after delete 5" << std::endl; o3.markDelete(); std::cout << "after delete 3 2" << std::endl; svc->transaction().commit(); svc->session().disconnectAll(); } catch(const seal::Error& er){ std::cout << "OK! caught seal exception " << std::endl; std::cerr << er.explainSelf(); std::cerr << std::endl; svc->transaction().commit(); svc->session().disconnectAll(); } try { svc->transaction().start(pool::ITransaction::READ); pool::Ref<NavigationTests::T2> h2; std::cout << "before is open" <<std:: endl; std::cout << h2.isOpen() <<std:: endl; std::cout << "before reset" <<std:: endl; h2.reset(); svc->transaction().commit(); svc->session().disconnectAll(); } catch(const seal::Error& er){ std::cout << "caught seal exception " << std::endl; std::cerr << er.explainSelf(); std::cerr << std::endl; svc->transaction().commit(); svc->session().disconnectAll(); } cat->commit(); delete svc; }
int main() { /* Quick hack for Dominic should be removed later, has nothing to do with 2dx_S int n = 20; int r_inner = 4; int r_outer = 9; SingleParticle2dx::real_array2d_type data2d = SingleParticle2dx::real_array2d_type(boost::extents[n][n]); for (int i=0; i<n; i++) { for (int j=0; j<n; j++) { double r = sqrt( (i-n/2)*(i-n/2) + (j-n/2)*(j-n/2) ); //if ( (r>r_inner) && (r<r_outer) ) if ( (r<r_outer) ) { data2d[i][j] = 1; } else { data2d[i][j] = 0; } } } SingleParticle2dx::Utilities::MRCFileIO::writeToMrc(&data2d, "scheibe.mrc"); return 0; */ boost::uniform_real<> uni_dist(-1,1); boost::variate_generator<boost::mt19937, boost::uniform_real<> > generator(boost::mt19937(time(0)), uni_dist ); SingleParticle2dx::ConfigContainer* config = SingleParticle2dx::ConfigContainer::Instance(); config->setParticleSize(n); SingleParticle2dx::DataStructures::Projection2d proj(n,n); std::vector<SingleParticle2dx::DataStructures::Orientation*> orient_vec; std::vector<std::string> name_vec; orient_vec.push_back(new SingleParticle2dx::DataStructures::Orientation(0,0,0)); name_vec.push_back("test_0_0_0.mrc"); // orient_vec.push_back(new SingleParticle2dx::DataStructures::Orientation(0,0,45)); // name_vec.push_back("test_0_0_45.mrc"); // orient_vec.push_back(new SingleParticle2dx::DataStructures::Orientation(0,30,0)); // name_vec.push_back("test_0_30_0.mrc"); // orient_vec.push_back(new SingleParticle2dx::DataStructures::Orientation(0,30,45)); // name_vec.push_back("test_0_30_45.mrc"); // orient_vec.push_back(new SingleParticle2dx::DataStructures::Orientation(30,45,0)); // name_vec.push_back("test_30_45_0.mrc"); // orient_vec.push_back(new SingleParticle2dx::DataStructures::Orientation(30,45,30)); // name_vec.push_back("test_30_45_45.mrc"); SingleParticle2dx::real_array3d_type protein = SingleParticle2dx::real_array3d_type(boost::extents[2*dh+2*offset+1][2*dh+2*offset+1][2*dh+2*offset+1]); SingleParticle2dx::real_array3d_type data3d = SingleParticle2dx::real_array3d_type(boost::extents[n][n][n]); generateObject(dh+offset, dh+offset, dh+offset, protein); SingleParticle2dx::Utilities::MRCFileIO::writeToMrc(&protein, "protein.mrc"); SingleParticle2dx::DataStructures::Reconstruction3d rec(n,n,n); for (int k=0; k<static_cast<int>(orient_vec.size()); k++) { std::cout << "Generate model " << k+1 << "/" << orient_vec.size() << std::endl; SingleParticle2dx::Utilities::DataContainerFunctions::resetData(&data3d); for(int i=lat; i<(n-lat); i+=lat) { for(int j=lat; j<(n-lat); j+=lat) { insertObject(i, j, n/2, data3d, protein, generator); } } std::cout << "projecting down" << std::endl; for(int i=0; i<n; i++) { for(int j=0; j<n; j++) { for(int k=0; k<i; k++) { float aux = data3d[i][j][k]; data3d[i][j][k] = data3d[k][j][i]; data3d[k][j][i] = aux; } } } rec.setFourierSpaceData(data3d); rec.setProjectionMethod(4); SingleParticle2dx::DataStructures::ParticleContainer dummy_container; rec.forceProjectionPreparation(dummy_container); rec.writeToFile("test3d.mrc"); int tilt = 0; SingleParticle2dx::DataStructures::Orientation o(0, tilt, -90); rec.calculateProjection(o, proj); proj.writeToFile("proj_" + SingleParticle2dx::Utilities::StringFunctions::TtoString(tilt) + ".mrc" ); SingleParticle2dx::DataStructures::Orientation o2(90, 30, -180); rec.calculateProjection(o2, proj); proj.writeToFile("proj_" + SingleParticle2dx::Utilities::StringFunctions::TtoString(30) + ".mrc" ); } rec.writeToFile( "test_syn.mrc" ); return 0; }
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, }; static const unsigned int newline_word_array[11] = { #define universal_newline_infos WORDINDEX2INFO(0) FUNso, #define universal_newline WORDINDEX2INFO(1) universal_newline_offsets, universal_newline_infos, #define crlf_newline_infos WORDINDEX2INFO(3) NOMAP, o2(0x0d,0x0a), #define crlf_newline WORDINDEX2INFO(5) crlf_newline_offsets, crlf_newline_infos, #define cr_newline_infos WORDINDEX2INFO(7) NOMAP, o1(0x0d), #define cr_newline WORDINDEX2INFO(9) crlf_newline_offsets, cr_newline_infos, }; #define TRANSCODE_TABLE_INFO newline_byte_array, 516, newline_word_array, 11, ((int)sizeof(unsigned int))
bool SparseRec2View::save() { if(!_onlymatch) { //save reconstructed points string path1(dir+imgname1+string("-")+imgname2+string(".X")); std::ofstream o1(path1.c_str()); o1 << "VERTEX " << (int)results.size() << endl; for(int i=0; i<(int)results.size(); ++i) { o1<<results[i].x<<" "<<results[i].y<<" "<<results[i].z<<endl; } o1.close(); TagI("save reconstructed points to\n %s\n",path1.c_str()); //save cam par string path7(imgpath1+string(".par")); std::ofstream o7(path7.c_str()); o7.setf(std::ios::scientific); o7 << "K(alphaX alphaY u0 v0)=" <<endl; o7 << K[0] << " " << K[4] << " " << K[2] << " " << K[5] << endl; o7 << "R=" << endl; o7 << "1 0 0\n0 1 0\n0 0 1" <<endl; o7 << "T=" << endl; o7 << "0 0 0" << endl; o7.close(); TagI("save camera 1's parameters to\n %s\n",path7.c_str()); string path8(imgpath2+string(".par")); std::ofstream o8(path8.c_str()); o8.setf(std::ios::scientific); o8 << "K(alphaX alphaY u0 v0)=" <<endl; o8 << K[0] <<" "<< K[4] <<" "<< K[2] <<" "<< K[5] << endl; o8 << "R=" << endl; for(int i=0; i<3; ++i) { for(int j=0; j<3; ++j) { o8 << R[i*3+j] << " "; } o8 << endl; } o8 << "T=" << endl; o8 << t[0] <<" "<< t[1] <<" "<< t[2] << endl; o8.close(); TagI("save camera 2's parameters to\n %s\n",path8.c_str()); } double fontScale=0.5; CvPoint text_origin; //save matched point pairs string path2(dir+imgname1+string("-")+imgname2+string(".p1p2")); std::ofstream o2(path2.c_str()); //out.setf(std::ios::scientific); int cnt = 0; for(int i=0; i<(int)p1.size(); ++i) { if(!inliers[i]) continue; o2 << p1[i].x <<" "<< p1[i].y <<" "<< p2[i].x <<" "<< p2[i].y <<endl; char tmp[256]; sprintf(tmp, "%d", cnt++); text_origin.x = (int)p1[i].x+5; text_origin.y = (int)p1[i].y-5; putText(img1, tmp, text_origin, CV_FONT_HERSHEY_PLAIN, fontScale, CV_BLACK); text_origin.x = (int)p2[i].x+5; text_origin.y = (int)p2[i].y-5; putText(img2, tmp, text_origin, CV_FONT_HERSHEY_PLAIN, fontScale, CV_BLACK); } o2.close(); TagI("save matched point pairs to\n %s\n",path2.c_str()); //save images string path3(imgpath1+string("-detect.jpg")); string path4(imgpath2+string("-detect.jpg")); string path5(dir+imgname1+string("-")+imgname2+string(".jpg")); if(!img1.empty()) cv::imwrite(path3, img1); else { TagE("no valid image to save!\n"); return false; } if(!img2.empty()) cv::imwrite(path4, img2); if(!combined.empty()) cv::imwrite(path5, combined); TagI("save surfed image 1 to\n %s\n",path3.c_str()); TagI("save surfed image 2 to\n %s\n",path4.c_str()); TagI("save combined image to\n %s\n",path5.c_str()); //save F string path6(dir+imgname1+string("-")+imgname2+string(".fmatrix")); std::ofstream o6(path6.c_str()); o6 << helper::PrintMat<>(3,3,F); o6.close(); TagI("save fundamental matrix to\n %s\n",path6.c_str()); return true; }
DEF_TEST(SkPDF_DeflateWStream, r) { SkRandom random(123456); for (int i = 0; i < 50; ++i) { uint32_t size = random.nextULessThan(10000); SkAutoTMalloc<uint8_t> buffer(size); for (uint32_t j = 0; j < size; ++j) { buffer[j] = random.nextU() & 0xff; } SkDynamicMemoryWStream dynamicMemoryWStream; { SkDeflateWStream deflateWStream(&dynamicMemoryWStream); uint32_t j = 0; while (j < size) { uint32_t writeSize = SkTMin(size - j, random.nextRangeU(1, 400)); if (!deflateWStream.write(&buffer[j], writeSize)) { ERRORF(r, "something went wrong."); return; } j += writeSize; } REPORTER_ASSERT(r, deflateWStream.bytesWritten() == size); } std::unique_ptr<SkStreamAsset> compressed(dynamicMemoryWStream.detachAsStream()); std::unique_ptr<SkStreamAsset> decompressed(stream_inflate(r, compressed.get())); if (!decompressed) { ERRORF(r, "Decompression failed."); return; } if (decompressed->getLength() != size) { ERRORF(r, "Decompression failed to get right size [%d]." " %u != %u", i, (unsigned)(decompressed->getLength()), (unsigned)size); SkString s = SkStringPrintf("/tmp/deftst_compressed_%d", i); SkFILEWStream o(s.c_str()); o.writeStream(compressed.get(), compressed->getLength()); compressed->rewind(); s = SkStringPrintf("/tmp/deftst_input_%d", i); SkFILEWStream o2(s.c_str()); o2.write(&buffer[0], size); continue; } uint32_t minLength = SkTMin(size, (uint32_t)(decompressed->getLength())); for (uint32_t i = 0; i < minLength; ++i) { uint8_t c; SkDEBUGCODE(size_t rb =)decompressed->read(&c, sizeof(uint8_t)); SkASSERT(sizeof(uint8_t) == rb); if (buffer[i] != c) { ERRORF(r, "Decompression failed at byte %u.", (unsigned)i); break; } } } SkDeflateWStream emptyDeflateWStream(nullptr); REPORTER_ASSERT(r, !emptyDeflateWStream.writeText("FOO")); }
static void test() { T2 o2(1); T1 o1(static_cast<T1>(o2)); ++o1; // quiet gcc unused variable warning }
int main(int argc, char *argv[]) { QCoreApplication a(argc, argv); QTextStream out(stdout); QOptions options(argc, (const char**)argv); options.setProgramName("lightwave"); options.setMaxNonOptionalValues(0); options.setMinNonOptionalValues(0); QOption o1( Option_Port, "port" ); o1.setShortCode('p'); o1.setNeedsValue( true, "9871", "port_number" ); o1.setDescription("The FCGI port used by the web server to talk to lightwave"); options.addOption( o1 ); QOption o2( Option_Domain, "domain" ); o2.setShortCode('d'); o2.setNeedsValue( true, "localhost", "domain" ); o2.setDescription("The domain served by the lightwave server"); options.addOption( o2 ); QOption o3( Option_Help, "help" ); o3.setShortCode('h'); o3.setDescription("Print help page"); options.addOption( o3 ); if ( !options.parse() ) { options.printError(out); return 1; } if ( options.option(Option_Help).occurrence() ) { options.printHelp(out); return 1; } // Get the settings QString profile = "./waveserver.conf"; if ( argc == 2 ) profile = QString(argv[1]); Settings settings( profile ); if ( options.option(Option_Port).occurrence() ) settings.setFcgiPort(options.option(Option_Port).value().toInt() ); if ( options.option(Option_Domain).occurrence() ) settings.setDomain(options.option(Option_Domain).value()); FCGI::FCGIServer server; return a.exec(); // JSONObject obj; // obj.setAttribute("name", "Torben"); // obj.setAttribute("age", 35); // JSONArray arr; // arr.append("Heinz"); // arr.append("Franz"); // obj.setAttribute("friends", arr); // JSONObject o2; // o2.setAttribute("white", true); // o2.setAttribute("height", 1.73); // obj.setAttribute("props", o2); // // out << obj.toJSON() << endl; // // const char* str = "{\"friends\":[\"Heinz\",\"Franz\",\"Fritz\"],\"age\":35,\"props\":{\"white\":true,\"height\":1.73},\"name\":\"Torben\"}"; // JSONScanner scanner(str, strlen(str)); // bool ok; // JSONObject res = scanner.scan(&ok); // if ( !ok ) // out << "Scanner error" << endl; // else // out << res.toJSON() << endl; // const char* mut = "{\"actions\":[ {\"object\":\"props\", \"actions\":[ { \"key\":\"white\", \"value\":\"false\" }, { \"key\":\"male\", \"value\":\"yes\" } ] }, { \"key\":\"age\", \"value\":36 }, {\"array\":\"friends\", \"actions\":[ {\"skip\":1 }, {\"delete\":1}, {\"insert\":\"Hannes\" } ] } ] }"; // JSONScanner scanner2(mut, strlen(mut)); // DocumentMutation mutation( scanner2.scan(&ok) ); // if ( !ok ) // out << "Scanner error" << endl; // else // out << mutation.toJSON() << endl; // {"actions":[ {"object":"props", "actions":[ { "key":"white", "value":"false" }, { "key":"male", "value":"yes" } ] }, { "key":"age", "value":36 }, // {"array":"friends", "actions":[ {"skip":1 }, {"delete":1}, {"insert":"Hannes" } ] } ] } // {"actions":[ {"text":"name", "actions":[ {"delete":1}, {"insert":"t" } ] } ] } // {"actions":[ {"remove":"props"} ] } // {"actions":[ {"remove":"age"} ] } // {"actions":[ {"object":"props", "replace":true, "actions":[ { "value":"white", "value":"false" } ] } ] } // {"chat": [ "Hello", {"tag":"image", "url":"http..."}, "how are you?" ] } // {"actions":[ {"array":"chat", "actions":[ {"text":[ {"skip":5}, {"insert":"!"} ] } ] } ] } // {"list": [ 1,2,3,4,5 ] } // {"actions":[ {"array":"list", actions:[ {"lift":"id1234"}, {"skip":3}, {"squeeze":"id1234"} ] } ] } // const char* m1 = "{\"_object\":true, \"foo\":100, \"bar\":300, \"obj\":{\"_object\":true, \"name\":\"torben\", \"age\":37, \"props\":{\"doof\":\"server\"}, \"list\":[1,2,3,4] }, \"txt\":{\"_text\":[ \"Hallo\" ] } }"; // const char* m2 = "{\"_object\":true, \"foo\":200, \"snoop\":400, \"obj\":{\"_object\":true, \"name\":\"Torben\", \"props\":{\"irre\":\"Wahnsinn\"}, \"list\":[5,6,7,8] }, \"txt\":{\"_text\":[\"Welt\"] } }"; // const char* m1 = "{\"_object\":true, \"foo\":{\"_array\":[1,2,3,{\"_delete\":5},{\"_object\":true, \"x\":5,\"y\":6}]}}"; // const char* m2 = "{\"_object\":true, \"foo\":{\"_array\":[{\"_skip\":3},41,51,{\"_delete\":1},{\"_object\":true, \"bar\":100},{\"_object\":true, \"x\":50,\"z\":60}]}}"; // const char* m2 = "{\"_object\":true, \"foo\":{\"_array\":[{\"_object\":true, \"x\":10},{\"_skip\":2}]}}"; // const char* m1 = "{\"_object\":true, \"foo\":{\"_array\":[{\"_lift\":\"L1\"}, {\"_skip\":2}, {\"_squeeze\":\"L1\"}]}}"; // const char* m2 = "{\"_object\":true, \"foo\":{\"_array\":[{\"_object\":true, \"x\":10, \"y\":20},{\"_skip\":3}]}}"; // const char* m1 = "{\"_object\":true, \"foo\":{\"_array\":[{\"_lift\":\"L1\", \"_mutation\":{ \"_object\":true, \"y\":200, \"z\":300 }}, {\"_skip\":2}, {\"_squeeze\":\"L1\"}, {\"_skip\":1}]}}"; // const char* m2 = "{\"_object\":true, \"foo\":{\"_array\":[{\"_delete\":1},{\"_skip\":2}]}}"; // const char* m1 = "{\"_object\":true, \"foo\":{\"_array\":[{\"_lift\":\"L1\"}, {\"_skip\":2}, {\"_squeeze\":\"L1\"}]}}"; // const char* m2 = "{\"_object\":true, \"foo\":{\"_array\":[{\"_skip\":3}]}}"; // const char* m1 = "{\"_object\":true, \"foo\":{\"_array\":[{\"_lift\":\"L1\"}, {\"_skip\":2}, {\"_squeeze\":\"L1\"}]}}"; // const char* m2 = "{\"_object\":true, \"foo\":{\"_array\":[{\"_lift\":\"L2\"}, {\"_skip\":1}, {\"_squeeze\":\"L2\"}, {\"_skip\":1}]}}"; // const char* m1 = "{\"_object\":true, \"foo\":{\"_array\":[{\"_lift\":\"L1\"}, {\"_skip\":2}, {\"_squeeze\":\"L1\"}]}}"; // const char* m1 = "{\"_object\":true, \"foo\":{\"_array\":[{\"_lift\":\"L1\"}, {\"_skip\":2}]}, \"gonzo\":{\"_array\":[{\"_squeeze\":\"L1\"}]}}"; // const char* m2 = "{\"_object\":true, \"foo\":{\"_array\":[{\"_lift\":\"L2\", \"_mutation\":{\"_object\":true, \"fuzzy\":34}}, {\"_skip\":2}]}, \"bar\":{\"_array\":[1,2,{\"_squeeze\":\"L2\"},{\"_object\":true, \"holla\":123}]}}"; // const char* m1 = "{\"_object\":true, \"foo\":{\"_array\":[{\"_lift\":\"L1\", \"_mutation\":{\"_array\":[{\"_squeeze\":\"L2\"}]}}, {\"_lift\":\"L2\"}]}, \"gonzo\":{\"_array\":[{\"_squeeze\":\"L1\"}]}}"; // const char* m2 = "{\"_object\":true, \"foo\":{\"_array\":[{\"_lift\":\"L1\"}, {\"_lift\":\"L2\", \"_mutation\":{\"_object\":true, \"hudel\":\"dudel\"}}, 12, {\"_squeeze\":\"L2\"}, {\"_squeeze\":\"L1\"}]}}"; // const char* m1 = "{\"_object\":true, \"foo\":{\"_lift\":\"L1\"}, \"bar\":{\"_squeeze\":\"L1\"}}"; // const char* m2 = "{\"_object\":true, \"foo\":{\"_array\":[1,2,{\"_skip\":2},5,6]}}"; // // JSONScanner scanner3(m1, strlen(m1)); // AbstractMutation mutation1( scanner3.scan(&ok) ); // if ( !ok ) // out << "Scanner error" << endl; // else // out << "Server: " << mutation1.toJSON() << endl; // // JSONScanner scanner4(m2, strlen(m2)); // AbstractMutation mutation2( scanner4.scan(&ok) ); // if ( !ok ) // out << "Scanner error" << endl; // else // out << "Client: " << mutation2.toJSON() << endl; // // Transformation t; // t.xform(mutation1, mutation2); // out << "Server: " << mutation1.toJSON() << endl; // out << "Client: " << mutation2.toJSON() << endl; // // out << "===========================================" << endl; // // const char* doc = "{\"string\":\"xxxWelt\", \"men\":[\"Einstein\", \"Heisenberg\", \"Wirth\", \"Galileo\"], \"friends\":[\"Heinz\",\"Franz\",\"Fritz\"],\"age\":35,\"props\":{\"white\":true,\"height\":1.73},\"name\":\"Torben\"}"; // JSONScanner scanner1(doc, strlen(doc)); // JSONObject obj( scanner1.scan(&ok) ); // if ( !ok ) // out << "Scanner error" << endl; // else // out << "Doc: " << obj.toJSON() << endl; // // const char* mut = "{\"_object\":true, \"string\":{\"_text\":[{\"_delete\":3}, \"Hallo \", {\"_skip\":4}, \"!\"]}, \"name\":{\"_lift\":\"N\"}, \"newname\":{\"_squeeze\":\"N\"}, \"men\":{\"_array\":[{\"_squeeze\":\"G\"},{\"_skip\":3},{\"_lift\":\"G\"}]}, \"age\":40, \"friends\":{\"_array\":[{\"_skip\":1}, {\"_delete\":1}, {\"_skip\":1}, \"Georg\"]}, \"foo\":[1,2,3,4], \"props\":{\"_object\":true, \"white\":false}}"; // JSONScanner scanner2(mut, strlen(mut)); // DocumentMutation mutation( ObjectMutation( scanner2.scan(&ok) ) ); // if ( !ok ) // out << "Scanner error" << endl; // else // out << "Mutation: " << mutation.mutation().toJSON() << endl; // // obj = mutation.apply(obj, &ok); // if ( !ok ) // out << "Application error" << endl; // else // out << "Doc2: " << obj.toJSON() << endl; // // out << "===========================================" << endl; // // const char* doc = "{\"a\":{\"text\":[\"Hallo Welt\"], \"style\":[{\"count\":6}, {\"weight\":\"bold\", \"count\":4}]}}"; // const char* doc = "{\"a\":{\"_r\":[\"Hallo\", {\"newline\":true}, {\"_format\":{\"weight\":\"bold\"}}, \"Welt\"]}}"; // JSONScanner scanner1(doc, strlen(doc)); // JSONObject obj( scanner1.scan(&ok) ); // if ( !ok ) // out << "Scanner error" << endl; // else // out << "Doc: " << obj.toJSON() << endl; // // const char* mut = "{\"_object\":true, \"a\":{\"_richtext\":[{\"_format\":{\"fontsize\":21}}, {\"_skip\":10}]}}"; // JSONScanner scanner2(mut, strlen(mut)); // DocumentMutation mutation( ObjectMutation( scanner2.scan(&ok) ) ); // if ( !ok ) // out << "Scanner error" << endl; // else // out << "Mutation: " << mutation.mutation().toJSON() << endl; // // obj = mutation.apply(obj, &ok); // if ( !ok ) // out << "Application error" << endl; // else // out << "Doc2: " << obj.toJSON() << endl; // // out << "===========================================" << endl; // // return 0; // int lifts = 5; // qsrand(9); // RandomDocGenerator rand(1); // RandomMutationGenerator rmut(lifts); // for( int i = 0; i < 300000; ++i ) // { // JSONObject r = rand.createObject(0); // out << "Doc " << i << ": " << r.toJSON() << endl; // // DocumentMutation d1 = rmut.createDocumentMutation(r); // out << "M1: " << d1.mutation().toJSON() << endl; // // DocumentMutation d2 = rmut.createDocumentMutation(r); // out << "M2: " << d2.mutation().toJSON() << endl; // // Transformation t; // ObjectMutation m1b( d1.mutation().clone() ); // ObjectMutation m2b( d2.mutation().clone() ); // t.xform(m1b, m2b); // if ( t.hasError() ) // { // out << t.errorText() << endl; // qFatal("Error in transformation"); // } // out << "M1': " << m1b.toJSON() << endl; // out << "M2': " << m2b.toJSON() << endl; // // JSONObject r2( r.clone().toObject() ); // DocumentMutation d1b( m1b ); // DocumentMutation d2b( m2b ); // d1.apply(r, &ok); // if ( !ok ) // qFatal("d1: Application error"); // else // out << "d1: " << r.toJSON() << endl; // d2b.apply(r, &ok); // if ( !ok ) // qFatal("d1b: Application error"); // else // out << "d1b: " << r.toJSON() << endl; // // d2.apply(r2, &ok); // if ( !ok ) // qFatal("d2: Application error"); // else // out << "d2: " << r2.toJSON() << endl; // d1b.apply(r2, &ok); // if ( !ok ) // qFatal("d2b: Application error"); // else // out << "d2b: " << r2.toJSON() << endl; // // if ( !r.equals(r2)) // qFatal("The two resulting documents differ"); // out << "===========================================" << endl; // } // out << "Success" << endl; // const char* m1 = "{\"_object\":true, \"a\":{\"_richtext\":[ \"A\", {\"_skip\":2},{\"_format\":{\"a\":1, \"b\":2}}, \"abc\" ]}}"; // // const char* m1 = "{\"_object\":true, \"a\":{\"_richtext\":[ {\"_skip\":2}, \"abc\" ]}}"; // const char* m2 = "{\"_object\":true, \"a\":{\"_richtext\":[ \"B\", {\"_format\":{\"c\":3, \"b\":4}}, \"C\", {\"_skip\":2}, \"xyz\" ]}}"; // const char* m1 = "{\"_object\":true,\"a0\":{\"_richtext\":[\"n\",{\"_skip\":1},\"gv\",{\"_skip\":1},{\"_skip\":1},{\"_format\":{\"sb\":\"up\",\"sc\":\"f\"}},{\"_delete\":1},{\"_delete\":1},{\"_format\":{}},{\"_skip\":1},{\"_format\":{\"sb\":\"\",\"sa\":\"v\"}},{\"_skip\":1},{\"_skip\":1},{\"_delete\":1},\"\",{\"_skip\":1},\"m\",{\"_format\":{\"sa\":\"gl\"}},{\"_delete\":1},{\"_format\":{\"sb\":\"\",\"sc\":\"m\"}},{\"_delete\":1}]}}"; // const char* m2 = "{\"_object\":true,\"a0\":{\"_richtext\":[{\"_format\":{}},{\"_skip\":1},{\"_format\":{\"sb\":\"yt\",\"sa\":\"\"}},{\"_delete\":1},{\"_skip\":1},{\"_format\":{\"sa\":\"\"}},{\"_skip\":1},{\"_format\":{\"sb\":\"irt\",\"sa\":null}},\"ba\",\"wfq\",{\"_format\":{\"sa\":null}},\"ftl\",\"elq\",{\"_skip\":1},{\"_skip\":1},{\"_skip\":1},{\"_skip\":1},{\"_skip\":1},{\"_delete\":1},{\"_skip\":1},\"g\",{\"_skip\":1}]}}"; // // const char* m1 = "{\"_object\":true, \"a\":{\"_array\":[{\"_squeeze\":\"AL0\"},{\"_delete\":1},{\"_text\":[{\"_skip\":1},{\"_skip\":1}]},\"nqh\",{\"_delete\":1},{\"_lift\":\"AL0\"},{\"_delete\":1},{\"_delete\":1}]}}"; // const char* m2 = "{\"_object\":true, \"a\":{\"_array\":[{\"_lift\":\"AL2\",\"_mutation\":{\"_text\":[\"\",{\"_skip\":1},{\"_skip\":1},{\"_delete\":1}]}},{\"_text\":[{\"_skip\":1},\"\",{\"_skip\":1}]},{\"_lift\":\"AL1\",\"_mutation\":{\"_text\":[{\"_skip\":1}]}},\"na\",{\"_lift\":\"AL0\",\"_mutation\":{\"_text\":[{\"_skip\":1},\"jpp\",\"\",\"\",\"if\",\"una\",\"y\",\"c\",{\"_delete\":1},\"jz\",\"g\",{\"_skip\":1}]}},{\"_squeeze\":\"AL2\"},{\"_squeeze\":\"AL1\"},{\"_squeeze\":\"AL0\"},{\"_delete\":1},{\"_text\":[\"i\",{\"_delete\":1},{\"_delete\":1}]}]}}"; // // JSONScanner scanner3(m1, strlen(m1)); // AbstractMutation mutation1( scanner3.scan(&ok) ); // if ( !ok ) // out << "Scanner error" << endl; // else // out << "Server: " << mutation1.toJSON() << endl; // // JSONScanner scanner4(m2, strlen(m2)); // AbstractMutation mutation2( scanner4.scan(&ok) ); // if ( !ok ) // out << "Scanner error" << endl; // else // out << "Client: " << mutation2.toJSON() << endl; // // DocumentMutation d1(mutation1.clone()); // DocumentMutation d2(mutation2.clone()); // // Transformation t; // t.xform(mutation1, mutation2); // if ( t.hasError()) // out << "Transformation error: " << t.errorText() << endl; // out << "Server': " << mutation1.toJSON() << endl; // out << "Client': " << mutation2.toJSON() << endl; // // DocumentMutation d1b(mutation1); // DocumentMutation d2b(mutation2); // // const char* doc = "{\"a\":{\"_r\":[\"XY\"]}}"; // JSONScanner scanner1(doc, strlen(doc)); // JSONObject obj( scanner1.scan(&ok) ); // if ( !ok ) // out << "Scanner error" << endl; // else // out << "Doc: " << obj.toJSON() << endl; // JSONObject obj2 = obj.clone().toObject(); // // obj = d1.apply(obj, &ok); // if ( !ok ) // out << "Application error" << endl; // else // out << "Doc1a: " << obj.toJSON() << endl; // obj = d2b.apply(obj, &ok); // if ( !ok ) // out << "Application error" << endl; // else // out << "Doc1b: " << obj.toJSON() << endl; // // obj2 = d2.apply(obj2, &ok); // if ( !ok ) // out << "Application error" << endl; // else // out << "Doc2a: " << obj2.toJSON() << endl; // obj2 = d1b.apply(obj2, &ok); // if ( !ok ) // out << "Application error" << endl; // else // out << "Doc2b: " << obj2.toJSON() << endl; // // out << "===========================================" << endl; }
static void test() { T1 o2(2); T1 o1 = o2; ++o1; // quiet gcc unused variable warning }
int cpp_main(int, char * []) { be::endian_log = false; // make sure some simple things work be::big_int32_t o1(1); be::big_int32_t o2(2L); be::big_int32_t o3(3LL); be::big_int64_t o4(1); // use cases; if BOOST_ENDIAN_LOG is defined, will output to clog info on // what overloads and conversions are actually being performed. be::endian_log = true; std::clog << "set up test values\n"; be::big_int32_t big(12345); be::little_uint16_t little_u(10); be::big_int64_t result; // this is the use case that is so irritating that it caused the endian // constructors to be made non-explicit std::clog << "\nf(1234) where f(big_int32_t)\n"; f_big_int32_ut(1234); std::clog << "\nresult = big\n"; result = big; std::clog << "\nresult = +big\n"; result = +big; std::clog << "\nresult = -big\n"; result = -big; std::clog << "\n++big\n"; ++big; std::clog << "\nresult = big++\n"; result = big++; std::clog << "\n--big\n"; --big; std::clog << "\nbig--\n"; big--; std::clog << "\nresult = big * big\n"; result = big * big; std::clog << "\nresult = big * big\n"; result = big * big; std::clog << "\nresult = big * little_u\n"; result = big * little_u; std::clog << "\nbig *= little_u\n"; big *= little_u; std::clog << "\nresult = little_u * big\n"; result = little_u * big; std::clog << "\nresult = big * 5\n"; result = big * 5; std::clog << "\nbig *= 5\n"; big *= 5; std::clog << "\nresult = 5 * big\n"; result = 5 * big; std::clog << "\nresult = little_u * 5\n"; result = little_u * 5; std::clog << "\nresult = 5 * little_u\n"; result = 5 * little_u; std::clog << "\nresult = 5 * 10\n"; result = 5 * 10; std::clog << "\n"; // test from Roland Schwarz that detected ambiguities; these ambiguities // were eliminated by BOOST_ENDIAN_MINIMAL_COVER_OPERATORS unsigned u; be::little_uint32_t u1; be::little_uint32_t u2; u = 9; u1 = 1; std::clog << "\nu2 = u1 + u\n"; u2 = u1 + u; std::clog << "\n"; // variations to detect ambiguities be::little_uint32_t u3 = u1 + 5; u3 = u1 + 5u; if (u1 == 5) {} if (u1 == 5u) {} u1 += 5; u1 += 5u; u2 = u1 + 5; u2 = u1 + 5u; // one more wrinkle be::little_uint16_t u4(3); u4 = 3; std::clog << "\nu2 = u1 + u4\n"; u2 = u1 + u4; std::clog << "\n"; be::endian_log = false; test_inserter_and_extractor(); // perform the indicated test on ~60*60 operand types op_test<default_construct>(); op_test<construct>(); // includes copy construction op_test<initialize>(); op_test<assign>(); op_test<relational>(); op_test<op_plus>(); op_test<op_star>(); return boost::report_errors(); }
bool ViewerQuery::UpdateLineFromSlice(PlaneAttributes *newPlaneAtts) { // // Only update the line if the slice-plane attributes have truly changed. // if (*planeAtts == *newPlaneAtts) return false; int i, opId = -1; int lineId = resultsPlot->GetNOperators()-1; for (i = 0; i < lineId; i++) { ViewerOperator *oper = resultsPlot->GetOperator(i); if (strcmp(oper->GetName(), "Slice") == 0) { opId = i; break; } } // // No need to update if no slice-operator has been applied. // if (opId == -1) return false; avtVector pt1(lineAtts->GetPoint1()); avtVector pt2(lineAtts->GetPoint2()); avtVector o1(planeAtts->GetOrigin()); avtVector o2(newPlaneAtts->GetOrigin()); // Define the frame for Plane 1. avtVector P1N(planeAtts->GetNormal()); avtVector P1Up(planeAtts->GetUpAxis()); avtVector u1, v1, w1; CreateBasis(P1N, P1Up, u1, v1, w1); // Define the frame for Plane 2. avtVector P2N(newPlaneAtts->GetNormal()); avtVector P2Up(newPlaneAtts->GetUpAxis()); avtVector u2, v2, w2; CreateBasis(P2N, P2Up, u2, v2, w2); avtMatrix M1, M2, M3, C; int spaceT = 0; if (planeAtts->GetThreeSpace() && !newPlaneAtts->GetThreeSpace()) { // convert 3d to 2d avtVector zero(0., 0., 0.); avtMatrix C1, C2; C1.MakeFrameToCartesianConversion(u2, v2, w2, zero); C1.Inverse(); C2.MakeScale(1, 1, 0); C = C2 * C1; spaceT = 1; } else if (!planeAtts->GetThreeSpace() && newPlaneAtts->GetThreeSpace()) { // convert 2d to 3d avtVector zero(0., 0., 0.); avtMatrix C1, C2, C3; C1.MakeFrameToCartesianConversion(u1, v1, w1, zero); C2.MakeCartesianToFrameConversion(u1, v1, w1, zero); avtVector zdim = C1 * o1; zdim.x = 0; zdim.y = 0; zdim = C2 * zdim; C3.MakeTranslate(zdim.x, zdim.y, zdim.z); C = C3 * C1; spaceT = 2; } if ((!planeAtts->FieldsEqual(0, newPlaneAtts)) || (!planeAtts->FieldsEqual(1, newPlaneAtts)) || (!planeAtts->FieldsEqual(2, newPlaneAtts))) { // Create conversion between Cartesian and plane1 frame. M1.MakeCartesianToFrameConversion(u1, v1, w1, o1); // Create conversion between plane2 and Cartesian frame. M2.MakeFrameToCartesianConversion(u2, v2, w2, o2); // Create composition matrix. switch (spaceT) { case 0 : M3 = M2 * M1; break; // no dimensionality change case 1 : M3 = C * M2 * M1; break; // converted from 3d to 2d case 2 : M3 = M2 * M1 * C; break; // converted from 2d to 3d } } else { M3 = C; } // Convert points. pt1 = M3 * pt1; pt2 = M3 * pt2; // Update necessary attributes. lineAtts->SetPoint1(pt1.x, pt1.y, pt1.z); lineAtts->SetPoint2(pt2.x, pt2.y, pt2.z); *planeAtts = *newPlaneAtts; // Ensure that both the slice and lineout operators have the correct atts. resultsPlot->GetOperator(lineId)->SetOperatorAtts(lineAtts); resultsPlot->GetOperator(opId)->SetOperatorAtts(newPlaneAtts); // Update the refline. originatingWindow->UpdateQuery(lineAtts); return true; }