示例#1
0
int main()
{
    if( o1( 0, 0 ) != 0 ) fail(__LINE__);
    if( count != 0 ) { count = 0; fail(__LINE__); }
    if( o1( 1, 0 ) != 1 ) fail(__LINE__);
    if( count != 0 ) { count = 0; fail(__LINE__); }
    if( o1( 0, 1 ) != 1 ) fail(__LINE__);
    if( count != 0 ) { count = 0; fail(__LINE__); }
    if( o1( 1, 1 ) != 1 ) fail(__LINE__);
    if( count != 0 ) { count = 0; fail(__LINE__); }
    if( o2( 0, 0 ) != 0 ) fail(__LINE__);
    if( count != 0 ) { count = 0; fail(__LINE__); }
    if( o2( 1, 0 ) != 1 ) fail(__LINE__);
    if( count != 0 ) { count = 0; fail(__LINE__); }
    if( o2( 0, 1 ) != 1 ) fail(__LINE__);
    if( count != 0 ) { count = 0; fail(__LINE__); }
    if( o2( 1, 1 ) != 1 ) fail(__LINE__);
    if( count != 0 ) { count = 0; fail(__LINE__); }
    if( o3( 0, 0 ) != 0 ) fail(__LINE__);
    if( count != 0 ) { count = 0; fail(__LINE__); }
    if( o3( 1, 0 ) != 1 ) fail(__LINE__);
    if( count != 0 ) { count = 0; fail(__LINE__); }
    if( o3( 0, 1 ) != 1 ) fail(__LINE__);
    if( count != 0 ) { count = 0; fail(__LINE__); }
    if( o3( 1, 1 ) != 1 ) fail(__LINE__);
    if( count != 0 ) { count = 0; fail(__LINE__); }
    if( a1( 0, 0 ) != 0 ) fail(__LINE__);
    if( count != 0 ) { count = 0; fail(__LINE__); }
    if( a1( 1, 0 ) != 0 ) fail(__LINE__);
    if( count != 0 ) { count = 0; fail(__LINE__); }
    if( a1( 0, 1 ) != 0 ) fail(__LINE__);
    if( count != 0 ) { count = 0; fail(__LINE__); }
    if( a1( 1, 1 ) != 1 ) fail(__LINE__);
    if( count != 0 ) { count = 0; fail(__LINE__); }
    if( a2( 0, 0 ) != 0 ) fail(__LINE__);
    if( count != 0 ) { count = 0; fail(__LINE__); }
    if( a2( 1, 0 ) != 0 ) fail(__LINE__);
    if( count != 0 ) { count = 0; fail(__LINE__); }
    if( a2( 0, 1 ) != 0 ) fail(__LINE__);
    if( count != 0 ) { count = 0; fail(__LINE__); }
    if( a2( 1, 1 ) != 1 ) fail(__LINE__);
    if( count != 0 ) { count = 0; fail(__LINE__); }
    if( a3( 0, 0 ) != 0 ) fail(__LINE__);
    if( count != 0 ) { count = 0; fail(__LINE__); }
    if( a3( 1, 0 ) != 0 ) fail(__LINE__);
    if( count != 0 ) { count = 0; fail(__LINE__); }
    if( a3( 0, 1 ) != 0 ) fail(__LINE__);
    if( count != 0 ) { count = 0; fail(__LINE__); }
    if( a3( 1, 1 ) != 1 ) fail(__LINE__);
    if( count != 0 ) { count = 0; fail(__LINE__); }
    _PASS;
}
示例#2
0
/* Finds the median-of-three in the array spanning **left to **right
 * and puts the value in *pivot_ptr.
 */
static yes_no find_pivot_3(char **left, char **right, char **pivot_ptr)
{
  char **p;
  int step = (right - left) / 2;
  char *a = *left;
  char *b = *(left + step);
  char *c = *right;

  o3(a, b, c);

  if (strcmp(a, b) == -1) {
    *pivot_ptr = b;
    return yes;
  }
  if (strcmp(b, c) == -1) {
    *pivot_ptr = c;
    return yes;
  }
  for (p = left + 1; p <= right; ++p) {
    if (strcmp(*p, *left) != 0) {
        *pivot_ptr = (strcmp(*p, *left) == -1) ? *left : *p;
      return yes;
    }
  }
  return no;
}
示例#3
0
HLInst* X86Compiler::emit(uint32_t code, const Operand& o0, const Operand& o1, const Operand& o2, uint64_t o3_) noexcept {
  Imm o3(o3_);
  HLInst* node = newInst(code, o0, o1, o2, o3);
  if (node == nullptr)
    return nullptr;
  return static_cast<HLInst*>(addNode(node));
}
示例#4
0
HLInst* X86Compiler::emit(uint32_t code, const Operand& o0, const Operand& o1, const Operand& o2, uint64_t o3_) {
  Imm o3(o3_);
  HLInst* node = newInst(code, o0, o1, o2, o3);
  if (node == NULL)
    return NULL;
  return static_cast<HLInst*>(addNode(node));
}
示例#5
0
文件: main.cpp 项目: CCJY/coliru
int main()
{
    Obj o1(5);
    Obj o2(o1);
    Obj o3(10);
    o1 = o3;
}
示例#6
0
TEST(CacheTest, GetSet) {
	order_id_t o1(true);
	order_id_t o2(true);
	order_id_t o3(true);
	OrderInfo_ptr oi1 = boost::make_shared<OrderInfo>();
	mc.add(o1,oi1);
	mc.add(o2,oi1);
	mc.add(o3,oi1);

	// check get(...) method
	std::cerr << "Testing cache.get(oid)" << std::endl;
	char sidbuf[UUID_STRLEN + 1];
	char oidbuf[UUID_STRLEN + 1];
	order_id_t o4(true);
	strategy_id_t s1(true);
	std::cerr << "Created oid: " << o4.c_str(oidbuf) << std::endl;
	std::cerr << "Created sid: " << s1.c_str(sidbuf) << std::endl;
	// clear the buffer!
	memset(sidbuf, 0, sizeof(sidbuf));
	OrderInfo_ptr oi2 = boost::make_shared<OrderInfo>(o4, s1);
	mc.add(o4, oi2);
	OrderInfo_ptr foundoi = mc.get(o4);
	EXPECT_NE(foundoi, OrderInfo_ptr());
	std::cerr << "Found strategy id: " << foundoi->getStrategyID().c_str(sidbuf) << std::endl;
	std::cerr << "Cache size(): " << (mc.getCache())->size() << std::endl;

	// EXPECT FAILURE
	order_id_t o5(true);
	OrderInfo_ptr oi3 = mc.get(o5);	
	EXPECT_EQ(oi3, OrderInfo_ptr());
	//assert(oi3 != OrderInfo_ptr());	
}
示例#7
0
yes_no find_pivot(EDGE *left, EDGE *right, double *pivot_ptr)
{
    EDGE a, b, c, *p;

    a = *left;
    b = *(left + (right - left) / 2);
    c = *right;
    o3(a, b, c);

    if (a.reliab < b.reliab)
    {
        *pivot_ptr = b.reliab;
        return yes;
    }

    if (b.reliab < c.reliab)
    {
        *pivot_ptr = c.reliab;
        return yes;
    }

    for (p = left + 1; p <= right; ++p)
    {
        if (p->reliab != left->reliab)
        {
            *pivot_ptr = (p->reliab < left->reliab) ? left->reliab : p->reliab;
            return yes;
        }
    }
    return no;
}
示例#8
0
TEST(Obis, Obis_basic) {
	// empty Obis constructor
	Obis o1;
	ASSERT_TRUE(o1.isAllNotGiven());
	ASSERT_TRUE(!o1.isManufacturerSpecific());

	// 2nd constructor:
	Obis o2(0x1, 0x2, 0x3, 0x4, 0x5, 0x6);
	ASSERT_FALSE(o1 == o2);
	ASSERT_FALSE(o2.isAllNotGiven());
	ASSERT_EQ(o2, o2); // check comparison op.
	// 3rd constructor:
	Obis o3("1-2:3.4.5*6");
	ASSERT_EQ(o2, o3);
}
示例#9
0
void test_CTypedPtrMap()
{
    typedef ::CTypedPtrMap< ::CMapStringToPtr, ::CString, int *> rng_t;
    boost::function_requires< boost::ForwardRangeConcept<rng_t> >();

    rng_t rng;
    ::CString o0(_T('a')), o1(_T('c')), o2(_T('f')), o3(_T('q')), o4(_T('g'));
    int d0, d1, d2, d3, d4;
    std::map< ::CString, int * > data;
    data[o0] = &d0, data[o1] = &d1, data[o2] = &d2, data[o3] = &d3, data[o4] = &d4;

    BOOST_CHECK( brdm::test_init_map(rng, data) );
    BOOST_CHECK( ::test_mfc_map(rng, data) );
    BOOST_CHECK( brdm::test_emptiness(rng) );
}
TEST( RefVectorTests, castedPtrRange )
{
	PseudoInterface o1( 1 ), o2( 2 ), o3( 3 );
	o1.serviceRetain();
	o2.serviceRetain();
	o3.serviceRetain();

	co::RefVector<PseudoInterface> refVec;
	refVec.push_back( &o1 );
	refVec.push_back( &o2 );
	refVec.push_back( &o3 );

	co::Range<co::IService* const> range( refVec );
	EXPECT_EQ( range.getSize(), 3 );

	// invalid usage sample (causes compile-time error):
	//co::Range<co::INamespace*> invalidRange( refVec );
}
示例#11
0
TEST(Obis, Obis_strparsing) {
	Obis o1(0x1, 0x1, 97, 97, 0xff, 0xff); // 97 = SC_F
	Obis o2("1-1:F.F");
	ASSERT_EQ(o1, o2);

	Obis o3(0x1, 0x1, 96, 98, 0xff, 0xff); // 96 = SC_C, 98 = SC_L
	Obis o4("1-1:C.L");
	ASSERT_EQ(o3, o4);

	Obis o5(0x1, 0x1, 96, 99, 0xff, 0xff); // 96 = SC_C, 99 = SC_P
	Obis o6("1-1:C.P");
	ASSERT_EQ(o5, o6);

	ASSERT_THROW(Obis o7("1-1:x:y"), vz::VZException);
	Obis o8("power-l1");
	ASSERT_EQ(Obis("1-0:21.7"), o8);

}
int  main()
{

	Observer::ConcreteSubject s;  // subject 를 생성 한다.

	//subject 들을 등록 시켜 준다 
	Observer::ConcreteObserver o1(&s,"A");
	Observer::ConcreteObserver o2(&s,"B"); 
	Observer::ConcreteObserver o3(&s,"C");

	s.Attach(&o1);
	s.Attach(&o2);
	s.Attach(&o3);
	s.Setstate("ABC");
	s.Notify();


	return 0;
}
示例#13
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);
}
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();
	}
}
示例#15
0
    /** HopperScreen, OnInit:
     *  Detailed description.
     *  @param argc TODO
     * @param argv TODO
     * @return TODO
     */
    bool HopperScreen::OnInit( int argc, char* argv[] ){
        // Master()->GetMainCanvas();
        CMainCanvas* m_pMainCanvas = Master()->GetMainCanvas();

        //m_pBackground = CCanvas::CreateRGBCompatible(NULL, 1024, 768 - 320);
        //m_pBackground = CCanvas::CreateRGBCompatible(NULL, NULL, NULL);
        // Todo: c:\program files\graphviz 2.28\bin\LIBFREETYPE-6.DLL copy from DEPS
        m_pArialfont = m_Loader.FL_LOADFONT("Fonts/ARIAL.TTF", 24);
        //m_pArialfont =
        // TTF_OpenFont("E:/Projects/C++/Humbug/projects/Humbug/Resources/Fonts/ARIAL.TTF", 24);
        mcol = CColor::White();
        SDL_Surface* tmpfsurf = ( m_Loader.FL_LOADIMG("Intro/HopperScreenBg.png") );

        //SDL_SetColorKey(tmpfsurf, SDL_TRUE, 0xff00ff);
        //SDL_SetColorKey(m_pMainCanvas->GetSurface(), SDL_TRUE, 0xff00ff);
        //SDL_SetSurfaceAlphaMod(tmpfsurf, 0);
        //SDL_SetSurfaceAlphaMod(m_pMainCanvas->GetSurface(), 128);
        m_pBackground.reset( new CCanvas( tmpfsurf ) );

        //CCanvas tmpCanvas( tmpfsurf );
        m_Loader.FreeLast();

        //m_pMainCanvas->Blit(m_pMainCanvas->GetDimension(), tmpCanvas, tmpCanvas.GetDimension());
        //m_pBackground->Blit(m_pBackground->GetDimension(), tmpCanvas, tmpCanvas.GetDimension());
        m_pMainCanvas->AddUpdateRect( m_pBackground->GetDimension() );

        //"\r\n"
        CColor m_colText = CColor::White();
        std::ostringstream outstring;
        outstring << "Jedzia";
        outstring << " .................... ";
        outstring << "328.123.847";

        CText* text = new CText(m_pArialfont, outstring.str(), m_colText);

        //const boost::function<void(CCanvas*, int)> textMo = mtextfloat;
        //text->AddAnimator(boost::ref( mtextfloat ));
        text->AddAnimator( WavyTextFloat(64) );
        m_pScrollText.reset(text);

        // ### Sprites ###
        m_pSprEye = new CSprite(m_Loader, "Sprites/male_sprites.png", m_pMainCanvas, CPoint(64, 0),
                CRectangle(0, 0, 64, 64) );
        m_pSprMgr->AddSprite(m_pSprEye, "mytag", hspriv::EyeMover(160, 8));
        //m_pSprMgr->AddSprite(m_pSprEye, boost::ref( pimpl_->eyemover ) );
        //m_pSprMgr->AddSprite(m_pSprEye);
        CSprite* m_pSprWormler = new CSprite(m_Loader, "Sprites/wormtiles.png", m_pMainCanvas, CPoint(0, 64),
                CRectangle(0, 0, 256, 64) );
        m_pSprWormler->SetColorAndAlpha(0xff00ff, 128);
        m_pSprMgr->AddSprite(m_pSprWormler, "mytag", hspriv::EyeMover(260, 40));

        //_CrtSetBreakAlloc(pimpl_->allocReqNum+4);
        //_crtBreakAlloc = pimpl_->allocReqNum+4;

        shost::ScriptHost shost;
        //shost.RunScript2(m_Loader.FL_LOADASSTRING("Lua/hello.lua"));
        // shost.RunScript(m_Loader.FL_LOADASSTRING("Lua/funcret.lua"));
        //shost.RunScript4(m_Loader.FL_LOADASSTRING("Lua/iowrite.lua"));
        //shost.RunScript(m_Loader.FL_LOADASSTRING("Lua/globalclass.lua"));
        //shost.RunScript6( m_Loader.FL_LOADASSTRING("Lua/globalclass.lua") );
		//shost.RunScript7( m_Loader.FL_LOADASSTRING("Lua/--FREE--.lua") );

		typedef shost::LuaScript<int, double, double> ScriptType;
		ScriptType::Script s = shost.generate<int, double, double>( m_Loader.FL_LOADASSTRING(
			"Lua/sprite1.lua"), "Ticks", "X", "Y" );
		pimpl_->script = s;

        world.FPS = CApplication::FramesCap();
        CRectangle screenRect = m_pMainCanvas->GetDimension();
        world.ScreenX = screenRect.GetW();
        world.ScreenY = screenRect.GetH();

		// Todo maybe an functor to initialize more global stuff
		(*s->AddStatic(world))("World")
			.def("greet", &greetHopper)
			.def_readonly("FPS", &World::FPS)
			.def_readonly("ScreenX", &World::ScreenX)
			.def_readonly("ScreenY", &World::ScreenY);



		ScriptType::Script sprInit = shost.generate<int, double, double>( m_Loader.FL_LOADASSTRING(
			"Sprites/male_sprites.spr"), "Ticks", "X", "Y" );
		//ScriptType::Script sprInit = shost.generate<int, double, double>( m_Loader.FL_LOADASSTRING(
		//	"Sprites/male_sprites.spr"), "Ticks", "X", "Y" );

		TestClass st(12,99);

		(*sprInit->AddStatic(st))("TestClass", "tc")
			.def(luabind::constructor<std::vector<int> >())
			.def(luabind::constructor<int, int>())
			.def("get", &TestClass::get);

		//boost::shared_ptr<shost::LuaScript::register_binder<SpriteFrame >>& bla=
		int xyz = 55;

		typedef shost::LuaVarCapsule<luabind::class_<SpriteFrame>> SprCapsule;
		SprCapsule maleSpriteCap = shost::makeFarm(sprInit,
		(*sprInit->Register<SpriteFrame>())("SpriteFrame")
			.def(luabind::constructor<int, int>())
			.def("X", &SpriteFrame::X)
			.def("Y", &SpriteFrame::Y));

		(*sprInit->Register<SpriteMovieOld>())("SpriteMovieOld")
			.def(luabind::constructor<std::string, SpriteFrame>())
			.def("X", &SpriteMovieOld::X)
			.def("Y", &SpriteMovieOld::Y);

		(*sprInit->Register<SpriteMovie>())("SpriteMovie")
			.def(luabind::constructor<std::string, std::vector<SpriteFrame>>())
			.def("X", &SpriteMovie::X)
			.def("Y", &SpriteMovie::Y);

		//luabind::class_<SpriteFrame>& xasd = maleSpriteCap.Value();
		//SprCapsule::ObjType mmy(1,2);
		//mmy.X();

		/*luabind::module(sprInit->L())
			[
				luabind::class_<TestClass>("TestClass_")
				.def(luabind::constructor<std::vector<int> >())
				.def(luabind::constructor<int, int>())
				.def("get", &TestClass::get)
			];*/


		int success = sprInit->run_script(99);

		luabind::object o3(luabind::globals(sprInit->L())["tcx"]);
		if (o3)
		{
			// is_valid
			// ...

			int luatype = luabind::type(o3);
			if (luabind::type(o3) == LUA_TUSERDATA)
			{
				TestClass otherValue = luabind::object_cast<TestClass>(o3);
				int abc = 4;
				abc++;
			}
		}

		SpriteFrame otherValue2(0,0);
		bool success3 = maleSpriteCap.GetLuaValue("spf", otherValue2);
		SpriteFrame otherValuex = maleSpriteCap.GetLuaValue("spf");

		SpriteFrame otherValue3(0,0);
		bool fsuccess = sprInit->GetLuaValue<SpriteFrame>("spf", otherValue3);

		luabind::object o4(luabind::globals(sprInit->L())["spf"]);
		if (o4)
		{
			// is_valid
			// ...

			int luatype = luabind::type(o4);
			if (luabind::type(o4) == LUA_TUSERDATA)
			{
				SpriteFrame otherValue = luabind::object_cast<SpriteFrame>(o4);
				int abc = 4;
				abc++;
			}
		}




		//SpriteMovie otherValue3(0,0);
		//fsuccess = sprInit->GetLuaValue<SpriteMovie>("spMovie", otherValue3);
		SpriteMovieOld smovieOld = sprInit->GetLuaValue<SpriteMovieOld>("spMovieOld");
		SpriteMovie smovie = sprInit->GetLuaValue<SpriteMovie>("spMovie");

		//int *x = new int(666);

        return Screen::OnInit(argc, argv);
    } // OnInit
示例#16
0
int main(int argc, const char* argv[])
{
	try
	{
		//init park
		Park disneyWorld("Disney World",10,15,100);
		//init operators
		Operator o1(Person("Keren", 19, 1.85));
		Operator o2(Person("Daniel", 21, 1.75));
		Operator o3(Person("Amir", 26, 1.60));
		Operator o4(Person("Eytan", 28, 1.80));

		disneyWorld += o1;
		disneyWorld += o2;
		disneyWorld += o3;
		disneyWorld += o4;
		
		//init facilities
		bool ageTypes[] = {true, true, false};
		WaterSlide waterSlide(Facility("KAMIKAZA", 2 , ageTypes, &o1), 800);
		ageTypes[2] = true;
		RollerCoaster rollerCoasterA(Facility("BALERINE", 30, ageTypes, &o2), 4, 0);
		ageTypes[0] = false;
		RollerCoaster rollerCoasterB(Facility("ANACONDA", 16, ageTypes, &o3), 30, 2);
		ageTypes[2] = false;
		Facility f("HYDRA", 12, ageTypes, &o4);
		WaterRollerCoaster waterRollerCoaster(WaterSlide(f,1000), RollerCoaster(f, 40, 7));

		disneyWorld += waterSlide;
		disneyWorld += rollerCoasterA;
		disneyWorld += rollerCoasterB;
		disneyWorld += waterRollerCoaster;

		//create persons to enter park
		Person p1("Adam",13,1.25);
		Person p2("Adir", 21, 1.55);
		Person p3("Adi", 27, 1.68);
		Person p4("Adva", 72, 1.45);

		Guest& g1 = disneyWorld.buyTicket(p1, Guest::CHILD, Guest::THRILLED,"09/09/2015");
		Guest& g2 = disneyWorld.buyTicket(p2, Guest::ADULT, Guest::HAPPY,"09/09/2015" ,true);
		Guest& g3 = disneyWorld.buyTicket(p3, Guest::ADULT, Guest::HAPPY,"08/09/2015");
		Guest& g4 = disneyWorld.buyTicket(p4, Guest::CHILD, Guest::AFRAID,"05/09/2015");

		//add guest to facility
		waterSlide += g1;
		waterSlide += g2;
		waterSlide.start(); //start() should remove all guests

		waterSlide += g3;
		waterSlide += g4;
		waterSlide.start();

		rollerCoasterA += g1;
		rollerCoasterA += g2;
		rollerCoasterA += g3;
		rollerCoasterA += g4;

		waterRollerCoaster += g1;
		waterRollerCoaster += g2;
		waterRollerCoaster += g3;
		waterRollerCoaster += g4;

		cout << disneyWorld << endl;
		rollerCoasterA.start();
		waterRollerCoaster.start();
		cout << disneyWorld << endl;
	}
	catch(const char* msg)
	{
		cout << "Problem occured..." << endl;
		cout << msg << endl;
		cout << "Finishing.." << endl;
	}
}
/*  
 * START THE VM 
 */
void startVM(Vm* vm)
{
    vm->PC = 0;

    while (charArrayToInt(0,2,vm->IR) != 99)
    {
        nextInstruction(vm);

        switch (charArrayToInt(0,2,vm->IR)) 
        {
            case 0:
                o0(vm);
                break;
            case 1: 
                o1(vm);
                break;
            case 2:
                o2(vm);
                break;
            case 3:
                o3(vm);
                break;
            case 4:
                o4(vm);
                break;
            case 5:
                o5(vm);
                break;
            case 6:
                o6(vm);
                break;
            case 7:
                o7(vm);
                break;
            case 8:
                o8(vm);
                break;
            case 9:
                o9(vm);
                break;
            case 10:
                o10(vm);
                break;
            case 11:
                o11(vm);
                break;
            case 12:
                o12(vm);
                break;
            case 13:
                o13(vm);
                break;
            case 14:
                o14(vm);
                break;
            case 15:
                o15(vm);
                break;
            case 16:
                o16(vm);
                break;
            case 17:
                o17(vm);
                break;
            case 18:
                o18(vm);
                break;
            case 19:
                o19(vm);
                break;
            case 20:
                o20(vm);
                break;
            case 21:
                o21(vm);
                break;
            case 22:
                o22(vm);
                break;
            case 23:
                o23(vm);
                break;
            case 24:
                o24(vm);
                break;
            case 25:
                o25(vm);
                break;
            case 26:
                o26(vm);
                break;
            case 27:
                o27(vm);
                break;
            case 28:
                o28(vm);
                break;
            case 29:
                o29(vm);
                break;
            case 30:
                o30(vm);
                break;
            case 31:
                o31(vm);
                break;
            case 32:
                o32(vm);
                break;
            case 33:
                o33(vm);
                break;
            case 34:
                o34(vm);
                break;
            case 35:
                o35(vm);
                break;
            case 99:
                o99(vm);
                break;
            default:
                // Code
                break;
        }
        displayVmFinal(vm);
    }
}
示例#18
0
文件: main.cpp 项目: AaronO/lightwave
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 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));

}
示例#20
0
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()
{
  bi::endian_log = false;

  //  make sure some simple things work

  bi::big32_t o1(1);
  bi::big32_t o2(2L);
  bi::big32_t o3(3LL);
  bi::big64_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.

  bi::endian_log = true;

  std::clog << "set up test values\n";
  bi::big32_t      big(12345);
  bi::ulittle16_t  ulittle(10);
  bi::big64_t      result;


  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 * ulittle\n";
  result = big * ulittle;

  std::clog << "\nbig *= ulittle\n";
  big *= ulittle;

  std::clog << "\nresult = ulittle * big\n";
  result = ulittle * 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 = ulittle * 5\n";
  result = ulittle * 5;

  std::clog << "\nresult = 5 * ulittle\n";
  result = 5 * ulittle;

  std::clog << "\nresult = 5 * 10\n";
  result = 5 * 10;
  std::clog << "\n";

  bi::endian_log = false;

  //  test from Roland Schwarz that detected ambiguities
  unsigned u;
  bi::ulittle32_t u1;
  bi::ulittle32_t u2;

  u = 1;
  u1 = 1;
  u2 = u1 + u;

  //  one more wrinkle
  bi::ulittle16_t u3(3);
  u3 = 3;
  u2 = u1 + u3;
    
  //  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 0;
}
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();
}
示例#23
0
int main ()
{
	SingleParticle2dx::ConfigContainer* config = SingleParticle2dx::ConfigContainer::Instance();
	
	int n = config->getParticleSize();
	
	config->setProjectionMethod(4);
	config->setCacheProjections(false);
	config->setParallelProjection(false);
	config->setProjectionMaskingMethod(0);
	config->setRefinementMethod(0);
	config->setTrialAngleGenerator(4);
	config->setBackprojectionMethod(0);
	config->setLPProjectionRadius(n);
	
	SingleParticle2dx::DataStructures::Reconstruction3d rec3d(n,n,n);
	
	SingleParticle2dx::Utilities::UtilityFunctions::generateInitialModelForInitRef(rec3d);
	
	rec3d.scale(1/1.34);
	
	SingleParticle2dx::Utilities::UtilityFunctions::setProgressBar( 33 );
	
	SingleParticle2dx::DataStructures::ParticleContainer c_dummy;
	rec3d.forceProjectionPreparation(c_dummy);
	
	SingleParticle2dx::DataStructures::Projection2d proj1(n,n);
	SingleParticle2dx::DataStructures::Projection2d proj2(n,n);
	SingleParticle2dx::DataStructures::Projection2d proj3(n,n);
	
	SingleParticle2dx::DataStructures::Orientation o1(0,0,0);
	SingleParticle2dx::DataStructures::Orientation o2(0,90,0);
	SingleParticle2dx::DataStructures::Orientation o3(0,90,90);
	
	rec3d.calculateProjection(o1, proj1);
	rec3d.calculateProjection(o2, proj2);
	rec3d.calculateProjection(o3, proj3);
	
	if(config->getShowSights())
	{	
		proj1.setMidddleTarget();
		proj2.setMidddleTarget();
		proj3.setMidddleTarget();
	}
	
	SingleParticle2dx::Utilities::UtilityFunctions::setProgressBar( 66 );
	
	std::string cont_folder_name = config->getContainerName() + "/Div_output/";
	std::string filename_p1 = cont_folder_name + "init_topview.mrc";
	std::string filename_p2 = cont_folder_name + "init_sideview1.mrc";
	std::string filename_p3 = cont_folder_name + "init_sideview2.mrc";
	
	proj1.writeToFile(filename_p1);
	proj2.writeToFile(filename_p2);
	proj3.writeToFile(filename_p3);
	
	SingleParticle2dx::Utilities::UtilityFunctions::generateImageOutput(filename_p1, "Top View", config->getScriptName(), false, false);
	SingleParticle2dx::Utilities::UtilityFunctions::generateImageOutput(filename_p2, "Side View X", config->getScriptName(), false, false);
	SingleParticle2dx::Utilities::UtilityFunctions::generateImageOutput(filename_p3, "Side View Y", config->getScriptName(), false, false);
	
	rec3d.writeToFile(config->getContainerName() + "/Rec_3d/Init3DFromMRC.map");
	SingleParticle2dx::Utilities::UtilityFunctions::generateImageOutput(config->getContainerName() + "/Rec_3d/Init3DFromMRC.map", "Initial 3D Reference", config->getScriptName(), true, true);
	
	SingleParticle2dx::Utilities::UtilityFunctions::setProgressBar( 100 );
	
	return 0;
}
示例#24
0
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;
}
示例#25
0
int main(int argc, char **argv){
    Operand o1(6);
    Operand o2(8);
    Operand o3(4);
    Operand o4(5);
    Operand o5(3);
    Mult m(&o1,&o2);
    Add a(&m,&o3);
    Add a2(&o2,&o3);
    Sqr sq(&a2);
    Div div(&m,&o3);
    Add a3(&div,&o4);
    Sqr sq2(&o5);
    Sub sub(&a3,&sq2);
    std::cout<<a.evaluate()<<std::endl;
    std::cout<<sq.evaluate()<<std::endl;
    std::cout<<sub.evaluate()<<std::endl<<std::endl;
    
    InsertSort iSort;
    Lcontainer lcon(&iSort);
    lcon.add_element(&o1);
    lcon.add_element(&sub);
    lcon.add_element(&div);
    lcon.add_element(&sq2);
    lcon.add_element(&m);
    std::cout<<lcon.at(0)->evaluate()<<std::endl;
    std::cout<<lcon.at(1)->evaluate()<<std::endl<<std::endl;

    lcon.print();
    std::cout<<std::endl;

    lcon.swap(0,1);
    lcon.print();
    std::cout<<std::endl;

    std::cout<<"Sorting list with ascending insertion sort"<<std::endl;
    lcon.sort();
    lcon.print();
    std::cout<<std::endl;


    std::cout<<"Sorting list with descending bubble sort"<<std::endl;
    BubbleSort bSort;
    lcon.set_sort_function(&bSort);
    lcon.sort();
    lcon.print();
    std::cout<<std::endl;

    Vcontainer vcon(&iSort);
    vcon.add_element(&a2);
    vcon.add_element(&sq2);
    vcon.add_element(&m);
    vcon.add_element(&div);
    vcon.add_element(&a3);
    vcon.add_element(&a);

    std::cout<<"Sorting vector with ascending insertion sort"<<std::endl;
    vcon.sort();
    vcon.print();
    std::cout<<std::endl;

    std::cout<<"Sorting vector with descending bubble sort"<<std::endl;
    vcon.set_sort_function(&bSort);
    vcon.sort();
    vcon.print();
    std::cout<<std::endl;

}
示例#26
0
int main(int argc, char **args)
{
	int res = ERR_SUCCESS;

#ifdef WITH_PETSC
	PetscInitialize(&argc, &args, (char *) PETSC_NULL, PETSC_NULL);
#endif

	if (argc < 2) error("Not enough parameters.");

	printf("* Loading mesh '%s'\n", args[1]);
	Mesh mesh1;
	H3DReader mesh_loader;
	if (!mesh_loader.load(args[1], &mesh1)) error("Loading mesh file '%s'\n", args[1]);

#if defined RHS2

	Ord3 order(P_INIT_X, P_INIT_Y, P_INIT_Z);
	printf("  - Setting uniform order to (%d, %d, %d)\n", order.x, order.y, order.z);
	
	// Create an H1 space with default shapeset.
	printf("* Setting the space up\n");
	H1Space space(&mesh1, bc_types, essential_bc_values, order);

	int ndofs = space.assign_dofs();
	printf("  - Number of DOFs: %d\n", ndofs);

	printf("* Calculating a solution\n");

	// duplicate the mesh
	Mesh mesh2;
	mesh2.copy(mesh1);
	// do some changes
	mesh2.refine_all_elements(H3D_H3D_H3D_REFT_HEX_XYZ);
	mesh2.refine_all_elements(H3D_H3D_H3D_REFT_HEX_XYZ);

	Solution fsln(&mesh2);
	fsln.set_const(-6.0);
#else
	// duplicate the mesh
	Mesh mesh2;
	mesh2.copy(mesh1);

	Mesh mesh3;
	mesh3.copy(mesh1);

	// change meshes
	mesh1.refine_all_elements(H3D_REFT_HEX_X);
	mesh2.refine_all_elements(H3D_REFT_HEX_Y);
	mesh3.refine_all_elements(H3D_REFT_HEX_Z);

	printf("* Setup spaces\n");
	Ord3 o1(2, 2, 2);
	printf("  - Setting uniform order to (%d, %d, %d)\n", o1.x, o1.y, o1.z);
	H1Space space1(&mesh1, bc_types_1, essential_bc_values_1, o1);

	Ord3 o2(2, 2, 2);
	printf("  - Setting uniform order to (%d, %d, %d)\n", o2.x, o2.y, o2.z);
	H1Space space2(&mesh2, bc_types_2, essential_bc_values_2, o2);

	Ord3 o3(1, 1, 1);
	printf("  - Setting uniform order to (%d, %d, %d)\n", o3.x, o3.y, o3.z);
	H1Space space3(&mesh3, bc_types_3, essential_bc_values_3, o3);

	int ndofs = 0;
	ndofs += space1.assign_dofs();
	ndofs += space2.assign_dofs(ndofs);
	ndofs += space3.assign_dofs(ndofs);
	printf("  - Number of DOFs: %d\n", ndofs);
#endif

#if defined WITH_UMFPACK
	MatrixSolverType matrix_solver = SOLVER_UMFPACK; 
#elif defined WITH_PETSC
	MatrixSolverType matrix_solver = SOLVER_PETSC; 
#elif defined WITH_MUMPS
	MatrixSolverType matrix_solver = SOLVER_MUMPS; 
#endif

#ifdef RHS2
	WeakForm wf;
	wf.add_matrix_form(bilinear_form<double, scalar>, bilinear_form<Ord, Ord>, HERMES_SYM);
	wf.add_vector_form(linear_form<double, scalar>, linear_form<Ord, Ord>, HERMES_ANY_INT, &fsln);

	// Initialize discrete problem.
	bool is_linear = true;
	DiscreteProblem dp(&wf, &space, is_linear);
#elif defined SYS3
	WeakForm wf(3);
	wf.add_matrix_form(0, 0, biform_1_1<double, scalar>, biform_1_1<Ord, Ord>, HERMES_SYM);
	wf.add_matrix_form(0, 1, biform_1_2<double, scalar>, biform_1_2<Ord, Ord>, HERMES_NONSYM);
	wf.add_vector_form(0, liform_1<double, scalar>, liform_1<Ord, Ord>);

	wf.add_matrix_form(1, 1, biform_2_2<double, scalar>, biform_2_2<Ord, Ord>, HERMES_SYM);
	wf.add_matrix_form(1, 2, biform_2_3<double, scalar>, biform_2_3<Ord, Ord>, HERMES_NONSYM);
	wf.add_vector_form(1, liform_2<double, scalar>, liform_2<Ord, Ord>);

	wf.add_matrix_form(2, 2, biform_3_3<double, scalar>, biform_3_3<Ord, Ord>, HERMES_SYM);

	// Initialize discrete problem.
	bool is_linear = true;
	DiscreteProblem dp(&wf, Hermes::vector<Space *>(&space1, &space2, &space3), is_linear);
#endif
	// Time measurement.
	TimePeriod cpu_time;
	cpu_time.tick();
  
	// 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 stiffness matrix and load vector.
	dp.assemble(matrix, rhs);

	// Solve the linear system. If successful, obtain the solution.
	info("Solving the linear problem.");
	bool solved = solver->solve();

	// Time measurement.
	cpu_time.tick();
	// Print timing information.
	info("Solution and mesh with polynomial orders saved. Total running time: %g s", cpu_time.accumulated());

	// Time measurement.
	TimePeriod sln_time;
	sln_time.tick();

	if (solved) {
#ifdef RHS2
		// Solve the linear system. If successful, obtain the solution.
		info("Solving the linear problem.");
                Solution sln(&mesh1);
		Solution::vector_to_solution(solver->get_solution(), &space, &sln);

		// Set exact solution.
		ExactSolution ex_sln(&mesh1, exact_solution);

		// Norm.
		double h1_sln_norm = h1_norm(&sln);
		double h1_err_norm = h1_error(&sln, &ex_sln);
		printf("  - H1 solution norm:   % le\n", h1_sln_norm);
		printf("  - H1 error norm:      % le\n", h1_err_norm);

		double l2_sln_norm = l2_norm(&sln);
		double l2_err_norm = l2_error(&sln, &ex_sln);
		printf("  - L2 solution norm:   % le\n", l2_sln_norm);
		printf("  - L2 error norm:      % le\n", l2_err_norm);

		if (h1_err_norm > EPS || l2_err_norm > EPS) {
			// Calculated solution is not enough precise.
			res = ERR_FAILURE;
		}
#elif defined SYS3
		// Solution 1.
		Solution sln1(&mesh1);
		Solution sln2(&mesh2);
		Solution sln3(&mesh3);

		Solution::vector_to_solution(solver->get_solution(), &space1, &sln1);
		Solution::vector_to_solution(solver->get_solution(), &space2, &sln2);
		Solution::vector_to_solution(solver->get_solution(), &space3, &sln3);

		ExactSolution esln1(&mesh1, exact_sln_fn_1);
		ExactSolution esln2(&mesh2, exact_sln_fn_2);
		ExactSolution esln3(&mesh3, exact_sln_fn_3);

		// Norm.
		double h1_err_norm1 = h1_error(&sln1, &esln1);
		double h1_err_norm2 = h1_error(&sln2, &esln2);
		double h1_err_norm3 = h1_error(&sln3, &esln3);

		double l2_err_norm1 = l2_error(&sln1, &esln1);
		double l2_err_norm2 = l2_error(&sln2, &esln2);
		double l2_err_norm3 = l2_error(&sln3, &esln3);

		printf("  - H1 error norm:      % le\n", h1_err_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;
		}

		printf("  - H1 error norm:      % le\n", h1_err_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;
		}

		printf("  - H1 error norm:      % le\n", h1_err_norm3);
		printf("  - L2 error norm:      % le\n", l2_err_norm3);
		if (h1_err_norm3 > EPS || l2_err_norm3 > EPS) {
			// Calculated solution is not enough precise.
			res = ERR_FAILURE;
		}
#endif

#ifdef RHS2
		out_fn_vtk(&sln, "solution");
#elif defined SYS3
		out_fn_vtk(&sln1, "sln1");
		out_fn_vtk(&sln2, "sln2");
		out_fn_vtk(&sln3, "sln3");
#endif
	}
	else
		res = ERR_FAILURE;

	// Print timing information.
	info("Solution and mesh with polynomial orders saved. Total running time: %g s", sln_time.accumulated());

	// Clean up.
	delete matrix;
	delete rhs;
	delete solver;

	return res;
}