EnergySourceContainer
EnergySourceHelper::Install (NodeContainer c) const
{
  EnergySourceContainer container;
  for (NodeContainer::Iterator i = c.Begin (); i != c.End (); ++i)
    {
      Ptr<EnergySource> src = DoInstall (*i);
      container.Add (src);
      /*
       * Check if EnergySourceContainer is already aggregated to target node. If
       * not, create a new EnergySourceContainer and aggregate it to node.
       */
      Ptr<EnergySourceContainer> EnergySourceContrainerOnNode =
        (*i)->GetObject<EnergySourceContainer> ();
      if (EnergySourceContrainerOnNode == NULL)
        {
          ObjectFactory fac;
          fac.SetTypeId ("ns3::EnergySourceContainer");
          EnergySourceContrainerOnNode = fac.Create<EnergySourceContainer> ();
          EnergySourceContrainerOnNode->Add (src);
          (*i)->AggregateObject (EnergySourceContrainerOnNode);
        }
      else
        {
          EnergySourceContrainerOnNode->Add (src);  // append new EnergySource
        }
    }
  return container;
}
Ejemplo n.º 2
0
void SuifEnv::init() {
  ObjectFactory* of = new SuifEnvObjectFactory;
  set_object_factory( of );
  of -> init( this );

  AggregateMetaClass*
        suifObjectMC = of->create_object_meta_class(
                                 SuifObject::get_class_name(),
                                 sizeof( SuifObject ),
                                 SuifObject::constructorFunction,
            (AggregateMetaClass*)of->lookupMetaClass( Object::get_class_name() ) );

  PointerMetaClass* pointerToSuifObjectR = of->get_pointer_meta_class( suifObjectMC, false );

  suifObjectMC -> add_field_description( "parent", pointerToSuifObjectR, OFFSETOF( SuifObject, parent ) );

  // Brick::init_meta_class(this);

  input_sub_system = new InputSubSystemDefaultImplementation( this );
  output_subsystem = new OutputSubSystemDefaultImplementation( this );
  cloneSubSystem = new CloneSubSystemDefaultImplementation( this );
  _dll_subsystem = new DLLSubSystem( this );
  _module_subsystem = new ModuleSubSystem( this );
  _error_subsystem = new ErrorSubSystem( this );
  _print_subsystem = new PrintSubSystem( this );
}
Ejemplo n.º 3
0
Object* ObjectManager::createInstance(lua_State* L, const String& className, const String& name)
{
	int luaReference = ScriptManager::getSingleton().getLuaClass(className);
	if (luaReference == 0) 
	{
		throw new Ogre::Exception(0, "Lua class '" + className + "' not found", __FILE__);
	}
	
	// põe a classe da pilha
	lua_getref(L, luaReference);
	int idx = lua_gettop(L);

	const String type(LuaHelper::getTableStringField(L, idx, "type"));

	ObjectFactory* factory = this->getObjectFactory(type);
	if (factory == NULL)
	{
		throw new Ogre::Exception(0, "no factory registered for type '" + type + "'", __FILE__);
	}

	Object* obj = factory->createInstance(L, luaReference, name);
	obj->setClassName(className);

	// register the object
	objects[name] = obj;

	return obj;
}
Ejemplo n.º 4
0
void Display::displayRequirements(CmdParser c)
{
	try
	{
		Verbose v(true);
		Verbose::show("******** REQUIREMENT 4 ********");
		Verbose::show("Refer to files Message.h and Message.cpp\n");
		Verbose::show("******** REQUIREMENT 6 ********");
		Verbose::show("Refer to files Communiation.h and Communication.cpp\n");
		Verbose::show("******** REQUIREMENT 8 ********");
		Verbose::show("Refer to files Executive.h, Display.h, Display.cpp and Executive.cpp\n");
		Verbose::show("******** DEMONSTRATING REQUIREMENT 3, 5 & 7 ********\n");
		ObjectFactory of;
		IRecvr *recv = of.createRecvr(stoi(c.getSelfPortNo()));
		ISendr *sender = of.createSendr();
		IMessage *msg = of.createMessage();
		Peer *peer_ = new Peer(sender,recv,msg);
		peer_->start();
		std::cout.flush();
		Verbose::show("\n\n  Press Enter to Exit.");
		std::cin.get();
		peer_->stop();
		
	}
	catch (exception ex)
	{
		string s = ex.what();
		Verbose::show("Exception thrown: "+s);
	}
	


}
Ejemplo n.º 5
0
    GeometryShader::GeometryShader(const CompiledShaderByteCode& compiledShader, const StreamOutputInitializers& soInitializers)
    {
        if (compiledShader.GetStage() != ShaderStage::Null) {
            assert(compiledShader.GetStage() == ShaderStage::Geometry);

            auto byteCode = compiledShader.GetByteCode();

            intrusive_ptr<ID3D::GeometryShader> underlying;
            if (soInitializers._outputBufferCount == 0) {

                underlying = ObjectFactory().CreateGeometryShader(byteCode.first, byteCode.second);

            } else {

                assert(soInitializers._outputBufferCount <= D3D11_SO_BUFFER_SLOT_COUNT);
                D3D11_SO_DECLARATION_ENTRY nativeDeclaration[D3D11_SO_STREAM_COUNT * D3D11_SO_OUTPUT_COMPONENT_COUNT];
                auto delcCount = BuildNativeDeclaration(nativeDeclaration, dimof(nativeDeclaration), soInitializers);

                ObjectFactory objFactory;
                auto featureLevel = objFactory.GetUnderlying()->GetFeatureLevel();
                underlying = objFactory.CreateGeometryShaderWithStreamOutput( 
                    byteCode.first, byteCode.second,
                    nativeDeclaration, delcCount,
                    soInitializers._outputBufferStrides, soInitializers._outputBufferCount,
                        //      Note --     "NO_RASTERIZED_STREAM" is only supported on feature level 11. For other feature levels
                        //                  we must disable the rasterization step some other way
                    (featureLevel>=D3D_FEATURE_LEVEL_11_0)?D3D11_SO_NO_RASTERIZED_STREAM:0);

            }

            _underlying = std::move(underlying);
        }
    }
Ejemplo n.º 6
0
bool ObjectManager::frameEnded(const Ogre::FrameEvent& evt)
{
	// Step the world and then synchronise the scene nodes with it, 
	// we could get this to do this automatically, but we 
	// can't be sure of what order the frame listeners will fire in
	if (mStepper->step(evt.timeSinceLastFrame))
    {
		std::vector<Object*>::iterator eraseIter = eraseQueue.begin();
		while (eraseIter != eraseQueue.end())
		{
			ObjectFactory* factory = this->getObjectFactory((*eraseIter)->getTypeName());
			assert(factory != NULL);
			factory->destroyInstance(*eraseIter);			
			eraseIter++;
		}		
		eraseQueue.clear();

		mWorld->synchronise(); 

		std::map<std::string, Object*>::iterator iter = objects.begin();
		while (iter != objects.end())
		{			
			if (iter->second != NULL)
			{
				iter->second->update(evt.timeSinceLastFrame);
			}
			iter++;
		}
    }

	return true;
}
void TestObjectSerialization3()
{
	ObjectFactory<Serializable> factory;

	//factory.Register("ObjectA", new ObjectCreator<ObjectA, Serializable>());
	factory.Register("ObjectD", new ObjectCreator<ObjectD, Serializable>());


	ObjectD d = ObjectD();
	d.Set(6, 7, 8, "ObjectD baby");
	d.AccessA().Set(1, 2, 3, "ObjectA baby");
	
	BinaryFileStream stream;

	stream.StartWrite("test3.txt");
	d.Save(stream);
	stream.SerializeQueue();
	stream.Close();

	std::vector<Serializable *> load;

	stream.StartRead("test3.txt", factory);
	ObjectD * loaded = stream.GetNext<ObjectD*>();

	stream.Close();
	loaded->Print();
	delete loaded;
}
Ejemplo n.º 8
0
 void freePlugIn(ExecutableAgent* pPlugin)
 {
    ObjectFactory* pFact = Service<ApplicationServices>()->getObjectFactory();
    if (pFact != NULL)
    {
       pFact->destroyObject(pPlugin, TypeConverter::toString<ExecutableAgent>());
    }
 }
Ejemplo n.º 9
0
 void freeWizard(WizardObject* pWizard)
 {
    ObjectFactory* pFact = Service<ApplicationServices>()->getObjectFactory();
    if (pFact != NULL)
    {
       pFact->destroyObject(pWizard, TypeConverter::toString<WizardObject>());
    }
 }
Ejemplo n.º 10
0
//-----------------------------------------------------------------------------
int ctkAbstractLibraryFactoryTest1(int argc, char * argv [] )
{
  QApplication app(argc, argv);

  ObjectFactory factory;
  factory.registerItems();

  return EXIT_SUCCESS;
}
Ejemplo n.º 11
0
ObjectFactory * CreateObjectFactory()
{
    ObjectFactory * factory = new ObjectFactory();
	factory->RegisterObject(new WallObject());
	factory->RegisterObject(new HeatObject());
	factory->RegisterObject(new WindowObject());
	factory->RegisterObject(new Probe());
	factory->RegisterObject(new StoneWallObject());
    return factory;
}
Ejemplo n.º 12
0
void Uninitialize()
{
    ObjectFactory *instance = ObjectFactory::getInstance();

    if (instance == NULL)
    {
        VMF_EXCEPTION(InternalErrorException, "Can't get Object factory instance");
    }

    std::shared_ptr<IDataSourceFactory> emptyDataSourceFactoryPtr;
    instance->setDataSourceFactory(emptyDataSourceFactoryPtr);
}
Ejemplo n.º 13
0
    PixelShader::PixelShader(const CompiledShaderByteCode& compiledShader)
    {
        ObjectFactory objFactory;
        if (compiledShader.DynamicLinkingEnabled())
            _classLinkage = objFactory.CreateClassLinkage();

        if (compiledShader.GetStage() != ShaderStage::Null) {
            assert(compiledShader.GetStage() == ShaderStage::Pixel);
            auto byteCode = compiledShader.GetByteCode();
            _underlying = objFactory.CreatePixelShader(byteCode.first, byteCode.second, _classLinkage.get());
        }
    }
void TestObjectSerialization()
{
	ObjectFactory<Serializable> factory;

	factory.Register("ObjectA", new ObjectCreator<ObjectA, Serializable>());
	factory.Register("ObjectB", new ObjectCreator<ObjectB, Serializable>());
	factory.Register("ObjectC", new ObjectCreator<ObjectC, Serializable>());
	factory.Register("STLVectorObjectIO", new ObjectCreator<STLVectorObjectIO<ObjectA>, Serializable>());


	ObjectA a = ObjectA();
	a.Set(1, 2, 3, "ObjectA baby");

	ObjectB b = ObjectB();
	b.Set(6, 7, 8, "ObjectB baby");
	

	ObjectC c = ObjectC();
	c.Set(3, 4, 5, "ObjectC baby");

	b.data4 = &c;
	c.data4 = &b;

	BinaryFileStream stream;

	stream.StartWrite("test.txt");
	a.Save(stream);
	b.Save(stream);
	//c.Save(stream, true);
	stream.SerializeQueue();
	stream.Close();

	std::vector<Serializable *> load;

	stream.StartRead("test.txt", factory);
	//stream.LoadObjects(factory);

	ObjectA * loaded_a = stream.GetNext<ObjectA*>();
	ObjectB * loaded_b = stream.GetNext<ObjectB*>();
	ObjectC * loaded_c = stream.GetNext<ObjectC*>();

	stream.Close();

	loaded_a->Print();
	loaded_b->Print();
	loaded_c->Print();

	delete loaded_a;
	delete loaded_b;
	delete loaded_c;
}
Ejemplo n.º 15
0
void Initialize(std::shared_ptr<IDataSourceFactory> &dataSourceFactory)
{
    if (!dataSourceFactory)
    {
        VMF_EXCEPTION(IncorrectParamException, "Unable to initialize by empty DataSourceFactory instance");
    }

    ObjectFactory *instance = ObjectFactory::getInstance();

    if (instance == NULL)
    {
        VMF_EXCEPTION(InternalErrorException, "Can't get Object factory instance");
    }

    instance->setDataSourceFactory(dataSourceFactory);
}
Ejemplo n.º 16
0
WPFCppCliDemo::WPFCppCliDemo()
{
  // set up channel
  ObjectFactory* pObjFact = new ObjectFactory;
  pSendr_ = pObjFact->createSendr();
  pRecvr_ = pObjFact->createRecvr();
  pChann_ = pObjFact->createMockChannel(pSendr_, pRecvr_);
  pChann_->start();
  delete pObjFact;
  // client's receive thread
  recvThread = gcnew Thread(gcnew ThreadStart(this, &WPFCppCliDemo::getMessage));
  recvThread->Start();
  // set event handlers
  this->Loaded += 
    gcnew System::Windows::RoutedEventHandler(this, &WPFCppCliDemo::OnLoaded);
  this->Closing += 
    gcnew CancelEventHandler(this, &WPFCppCliDemo::Unloading);
  hSendButton->Click += gcnew RoutedEventHandler(this, &WPFCppCliDemo::sendMessage);
  hClearButton->Click += gcnew RoutedEventHandler(this, &WPFCppCliDemo::clear);
  hFolderBrowseButton->Click += gcnew RoutedEventHandler(this, &WPFCppCliDemo::browseForFolder);
  hConnectButton->Click += gcnew RoutedEventHandler(this, &WPFCppCliDemo::connect);
  hUploadBrowseButton->Click += gcnew RoutedEventHandler(this, &WPFCppCliDemo::uploadBrowseFolder);
  hUploadFileButton->Click += gcnew RoutedEventHandler(this, &WPFCppCliDemo::uploadFile);
  hDownloadBrowseButton->Click += gcnew RoutedEventHandler(this, &WPFCppCliDemo::downloadBrowseFolder);
  hDownloadFileButton->Click += gcnew RoutedEventHandler(this, &WPFCppCliDemo::downloadFile);
  hTextSearchButton->Click += gcnew RoutedEventHandler(this, &WPFCppCliDemo::textSearch);

  // set Window properties
  this->Title = "WPF C++/CLI Demo";
  this->Width = 800;
  this->Height = 600;
  // attach dock panel to Window
  this->Content = hDockPanel;
  hDockPanel->Children->Add(hStatusBar);
  hDockPanel->SetDock(hStatusBar, Dock::Bottom);
  hDockPanel->Children->Add(hGrid);

  // setup Window controls and views
  setUpTabControl();
  setUpStatusBar();
  setUpSendMessageView();
  setUpConnectionView();
  setUpFileUploadView();
  setUpFileDownloadView();
  setUpTextSearchView();
  setUpFileSearchView();
}
Ejemplo n.º 17
0
    GeometryShader::GeometryShader( const ResChar initializer[],
                                    const StreamOutputInitializers& soInitializers)
    {
            //
            //      We have to append the shader model to the resource name
            //      (if it's not already there)
            //
        ResChar temp[MaxPath];
        if (!XlFindStringI(initializer, "gs_")) {
            StringMeldInPlace(temp) << initializer << ":" GS_DefShaderModel;
            initializer = temp;
        }

        intrusive_ptr<ID3D::GeometryShader> underlying;

        if (soInitializers._outputBufferCount == 0) {

			const auto& compiledShader = ::Assets::GetAssetComp<CompiledShaderByteCode>(initializer);
            assert(compiledShader.GetStage() == ShaderStage::Geometry);
            auto byteCode = compiledShader.GetByteCode();
            underlying = ObjectFactory().CreateGeometryShader(byteCode.first, byteCode.second);

        } else {

            assert(soInitializers._outputBufferCount < D3D11_SO_BUFFER_SLOT_COUNT);
            D3D11_SO_DECLARATION_ENTRY nativeDeclaration[D3D11_SO_STREAM_COUNT * D3D11_SO_OUTPUT_COMPONENT_COUNT];
            auto delcCount = BuildNativeDeclaration(nativeDeclaration, dimof(nativeDeclaration), soInitializers);

            ObjectFactory objFactory;
            auto featureLevel = objFactory.GetUnderlying()->GetFeatureLevel();

			const auto& compiledShader = ::Assets::GetAssetComp<CompiledShaderByteCode>(initializer);
            assert(compiledShader.GetStage() == ShaderStage::Geometry);
            auto byteCode = compiledShader.GetByteCode();
            underlying = objFactory.CreateGeometryShaderWithStreamOutput( 
                byteCode.first, byteCode.second,
                nativeDeclaration, delcCount,
                soInitializers._outputBufferStrides, soInitializers._outputBufferCount,
                    //      Note --     "NO_RASTERIZED_STREAM" is only supported on feature level 11. For other feature levels
                    //                  we must disable the rasterization step some other way
                (featureLevel>=D3D_FEATURE_LEVEL_11_0)?D3D11_SO_NO_RASTERIZED_STREAM:0);

        }

            //  (creation successful; we can commit to member now)
        _underlying = std::move(underlying);
    }
Ejemplo n.º 18
0
void TEST_Serialization::LeafJoins()
{
	ObjectFactory<Serializable> factory;
	factory.Register("ObjectA", new ObjectCreator<ObjectA, Serializable>());
	factory.Register("ObjectC", new ObjectCreator<ObjectC, Serializable>());

	Stream * file = new BinaryFileStream();
	file->StartWrite("test9.txt");

	ObjectA * a = new ObjectA(1, 2, 3);
	ObjectC * c = new ObjectC(4, 5, 6, a);
	ObjectC * c2 = new ObjectC(7, 8, 9, a);

	*file << c;
	*file << c2;
	*file << a;

	file->Close();

	file->StartRead("test9.txt", factory);
	
	ObjectC * load_c;
	ObjectC * load_c2;
	ObjectA * load_a;
	file->Load(load_c);
	file->Load(load_c2);
	file->Load(load_a);

	load_c->a->Print();
	load_c2->a->Print();

	load_a->Set(12, 12, 12);

	load_c->a->Print();
	load_c2->a->Print();


	file->Close();
	delete file;
	delete c;
	delete c2;
	delete a;
	delete load_c;
	delete load_c2;
	delete load_a;
}
Ejemplo n.º 19
0
    void CustomGUIReader::init(std::string &className, int createFunc, int setPropsFunc)
    {
        _className = className;
        _createFunc = createFunc;
        _setPropsFunc = setPropsFunc;

        ObjectFactory* factoryCreate = ObjectFactory::getInstance();
        ObjectFactory::TInfo t;
        t._class = className;
        t._func = CC_CALLBACK_0(CustomGUIReader::createInstance, this);
        factoryCreate->registerType(t);

        auto guiReader = GUIReader::getInstance();
        auto objMap = guiReader->getParseObjectMap();
        (*objMap)[className] = this;
        auto callbackMap = guiReader->getParseCallBackMap();
        (*callbackMap)[className] = parseselector(CustomGUIReader::setCustomProps);
    }
Ejemplo n.º 20
0
Archivo: test.cpp Proyecto: otita/cg
int main(int argc, const char *argv[]) {
  using namespace std;
  using namespace otita::cg;

  WindowFactory *wFactory = WindowFactory::getInstance();
  Window *window = wFactory->createWindowOrDie(640, 480, "Test");
  WindowFactory::deleteInstance();

  window->setKeyboardDelegate(new MyKeyDelegate);

  World *world = new World();
  ObjectFactory *oFactory = ObjectFactory::getInstance();
//  world->addObject(
//    oFactory->createTriangle(
//      {
//      -0.6, -0.4,
//      0.6,  -0.4,
//      0.,    0.6,
//      }
//    )
//  );
  world->addObject(
    oFactory->createCircle(
      {
      0., 0.,
      },
      1.
    )
  );
  ObjectFactory::deleteInstance();

  window->setWorld(world);

  while (!window->shouldClose()) {
    window->clear();
    window->draw();
    window->swapBuffers();
  }

  delete world;
  delete window;

  return 0;
}
int main()
{
  ObjectFactory objFact;
  ISendr* pSendr = objFact.createSendr();
  IRecvr* pRecvr = objFact.createRecvr();
  IMockChannel* pMockChannel = objFact.createMockChannel(pSendr, pRecvr);
  pMockChannel->start();
  pSendr->postMessage("Hello World");
  pSendr->postMessage("CSE687 - Object Oriented Design");
  Message msg = pRecvr->getMessage();
  std::cout << "\n  received message = \"" << msg << "\"";
  msg = pRecvr->getMessage();
  std::cout << "\n  received message = \"" << msg << "\"";
  pSendr->postMessage("stopping");
  msg = pRecvr->getMessage();
  std::cout << "\n  received message = \"" << msg << "\"";
  pMockChannel->stop();
  pSendr->postMessage("quit");
  std::cin.get();
}
Ejemplo n.º 22
0
 ExecutableAgent* createPlugIn(const char* pName, int batch)
 {
    std::string name(pName == NULL ? "" : pName);
    ObjectFactory* pFact = Service<ApplicationServices>()->getObjectFactory();
    ExecutableAgent* pPlugin =
       reinterpret_cast<ExecutableAgent*>(pFact->createObject(TypeConverter::toString<ExecutableAgent>()));
    if (pPlugin == NULL)
    {
       setLastError(SIMPLE_WRONG_TYPE);
       return NULL;
    }
    pPlugin->instantiate(name, std::string(), NULL, (batch != 0));
    if (pPlugin->getPlugIn() == NULL)
    {
       freePlugIn(pPlugin);
       setLastError(SIMPLE_NOT_FOUND);
       return NULL;
    }
    pPlugin->createProgressDialog(true);
    pPlugin->setAutoArg(false);
    setLastError(SIMPLE_NO_ERROR);
    return pPlugin;
 }
Ejemplo n.º 23
0
void TEST_Serialization::Inheritance()
{
	ObjectFactory<Serializable> factory;
	factory.Register("ObjectB", new ObjectCreator<ObjectB, Serializable>());

	Stream * file = new BinaryFileStream();
	file->StartWrite("test8.txt");

	ObjectB * b = new ObjectB(1, 2, 3, 1337);

	*file << b;

	file->Close();

	file->StartRead("test8.txt", factory);
	
	ObjectB * load_b;
	file->Load(load_b);

	file->Close();
	delete file;
	delete b;
	delete load_b;
}
Ejemplo n.º 24
0
void TestObjectFactory::init( SuifEnv* suif ) {
  _object_factory = suif->get_object_factory();
  ObjectFactory *of = _object_factory;

  MetaClass* intMetaClass = of->lookupMetaClass("int");
  assert( intMetaClass );
  AggregateMetaClass* meta_SuifObject = of->find_aggregate_meta_class(SuifObject::get_class_name());

  AggregateMetaClass* testX = 0;
  testX = of->create_object_meta_class( TestX::get_class_name(),
                                        sizeof( TestX ),
                                        TestX::constructorFunction,
                                        meta_SuifObject );
  PointerMetaClass* owningPointerToTestX = of->get_pointer_meta_class( testX, true );


  testX-> add_field_description( "i", intMetaClass, OFFSETOF(TestX,i) );
  testX-> add_field_description( "x1", owningPointerToTestX, OFFSETOF(TestX,x1) );
  testX-> add_field_description( "x2", owningPointerToTestX, OFFSETOF(TestX,x2) );

  STLMetaClass* meta_TestX_vector =of-> get_stl_meta_class("LIST:suif_vector<TestX*>",
                               new STLDescriptor< suif_vector<TestX*> >( owningPointerToTestX ) );
  PointerMetaClass* meta_TestX_owner = of->get_pointer_meta_class(meta_TestX_vector,true,true);

  testX-> add_field_description( "_vector", meta_TestX_owner, OFFSETOF(TestX,_vector) );


  testX->add_virtual_field( "int", "i" );
  testX->add_virtual_field( "pointers", "x1;x2" );
  testX->add_virtual_field( "TestX", "x1/*;x2/*" );
  testX->add_virtual_field( "int-indirect", "i;x1/i;x2/i" );
  testX->add_virtual_field( "vectorPtr", "_vector" );
  testX->add_virtual_field( "vector", "_vector/*" );
  testX->add_virtual_field( "vectorContents", "_vector/*/*" );

  // ------------ make meta class for TestY -------------
  AggregateMetaClass* testY = 0;

  testY = of->create_object_meta_class( TestY::get_class_name(),
                                        sizeof( TestY ),
                                        TestY::constructorFunction,
                                        testX );
  testY-> add_field_description( "x3", owningPointerToTestX, OFFSETOF(TestY,x3) );


  testY->add_virtual_field( "int", "i" );
  testY->add_virtual_field( "pointers", "^;x3" );
  testY->add_virtual_field( "TestX", "^;x3/*" );

}
Ejemplo n.º 25
0
 IndexBuffer::IndexBuffer(const ObjectFactory& factory, const void* data, size_t byteCount)
 {
     if (byteCount!=0) {
         D3D11_BUFFER_DESC desc;
         desc.ByteWidth = (UINT)byteCount;
         desc.Usage = D3D11_USAGE_IMMUTABLE;
         desc.BindFlags = D3D11_BIND_INDEX_BUFFER;
         desc.CPUAccessFlags = 0;
         desc.MiscFlags = 0;
         desc.StructureByteStride = 0;
         D3D11_SUBRESOURCE_DATA subresData;
         subresData.pSysMem = data;
         subresData.SysMemPitch = subresData.SysMemSlicePitch = 0;
         _underlying = factory.CreateBuffer(&desc, &subresData);
     }
 }
Ejemplo n.º 26
0
 ConstantBuffer::ConstantBuffer(
     const ObjectFactory& factory,
     const void* data, size_t byteCount, bool immutable)
 {
     if (byteCount!=0) {
         D3D11_BUFFER_DESC desc;
         desc.ByteWidth = (UINT)byteCount;
         if (data && immutable) {
             desc.Usage = D3D11_USAGE_IMMUTABLE;
             desc.CPUAccessFlags = 0;
         } else {
             desc.Usage = D3D11_USAGE_DYNAMIC;
             desc.CPUAccessFlags = D3D11_CPU_ACCESS_WRITE;
         }
         desc.BindFlags = D3D11_BIND_CONSTANT_BUFFER;
         
         desc.MiscFlags = 0;
         desc.StructureByteStride = 0;
         D3D11_SUBRESOURCE_DATA subresData;
         subresData.pSysMem = data;
         subresData.SysMemPitch = subresData.SysMemSlicePitch = 0;
         _underlying = factory.CreateBuffer(&desc, data?(&subresData):nullptr);
     }
 }
Ejemplo n.º 27
0
int main(int argc, char *argv[]) {
    QCoreApplication app(argc, argv);
    app.setAttribute(Qt::AA_Use96Dpi, true);

    // Setup our tests factory object.
    ObjectFactory testFactory;
    testFactory.registerClass<TestAwsAbstractClient>();
    testFactory.registerClass<TestAwsAbstractCredentials>();
    testFactory.registerClass<TestAwsAbstractRequest>();
    testFactory.registerClass<TestAwsAbstractResponse>();
    testFactory.registerClass<TestAwsAbstractSignature>();
    testFactory.registerClass<TestAwsAnonymousCredentials>();
    testFactory.registerClass<TestAwsBasicCredentials>();
    testFactory.registerClass<TestAwsEndpoint>();
    testFactory.registerClass<TestAwsRegion>();
    testFactory.registerClass<TestAwsSignatureV0>();
    testFactory.registerClass<TestAwsSignatureV1>();
    testFactory.registerClass<TestAwsSignatureV2>();
    testFactory.registerClass<TestAwsSignatureV3>();
    testFactory.registerClass<TestAwsSignatureV4>();
    testFactory.registerClass<TestSqsAddPermissionRequest>();
    testFactory.registerClass<TestSqsAddPermissionResponse>();
    testFactory.registerClass<TestSqsChangeMessageVisibilityBatchRequest>();
    testFactory.registerClass<TestSqsChangeMessageVisibilityBatchResponse>();
    testFactory.registerClass<TestSqsChangeMessageVisibilityRequest>();
    testFactory.registerClass<TestSqsChangeMessageVisibilityResponse>();
    testFactory.registerClass<TestSqsClient>();
    testFactory.registerClass<TestSqsCreateQueueRequest>();
    testFactory.registerClass<TestSqsCreateQueueResponse>();
    testFactory.registerClass<TestSqsDeleteMessageBatchRequest>();
    testFactory.registerClass<TestSqsDeleteMessageBatchResponse>();
    testFactory.registerClass<TestSqsDeleteMessageRequest>();
    testFactory.registerClass<TestSqsDeleteMessageResponse>();
    testFactory.registerClass<TestSqsDeleteQueueRequest>();
    testFactory.registerClass<TestSqsDeleteQueueResponse>();
    testFactory.registerClass<TestSqsError>();
    testFactory.registerClass<TestSqsGetQueueAttributesRequest>();
    testFactory.registerClass<TestSqsGetQueueAttributesResponse>();
    testFactory.registerClass<TestSqsGetQueueUrlRequest>();
    testFactory.registerClass<TestSqsGetQueueUrlResponse>();
    testFactory.registerClass<TestSqsListDeadLetterSourceQueuesRequest>();
    testFactory.registerClass<TestSqsListDeadLetterSourceQueuesResponse>();
    testFactory.registerClass<TestSqsListQueuesRequest>();
    testFactory.registerClass<TestSqsListQueuesResponse>();
    testFactory.registerClass<TestSqsPurgeQueueRequest>();
    testFactory.registerClass<TestSqsPurgeQueueResponse>();
    testFactory.registerClass<TestSqsReceiveMessageRequest>();
    testFactory.registerClass<TestSqsReceiveMessageResponse>();
    testFactory.registerClass<TestSqsRemovePermissionRequest>();
    testFactory.registerClass<TestSqsRemovePermissionResponse>();
    testFactory.registerClass<TestSqsRequest>();
    testFactory.registerClass<TestSqsResponse>();
    testFactory.registerClass<TestSqsSendMessageBatchRequest>();
    testFactory.registerClass<TestSqsSendMessageBatchResponse>();
    testFactory.registerClass<TestSqsSendMessageRequest>();
    testFactory.registerClass<TestSqsSendMessageResponse>();
    testFactory.registerClass<TestSqsSetQueueAttributesRequest>();
    testFactory.registerClass<TestSqsSetQueueAttributesResponse>();

    // If the user has specified a Test* class name, execute that test class only.
    for (int index = 1; index < argc; ++index) {
        if (qstrcmp(argv[index], "-classes") == 0) {
            foreach (const QByteArray &className, testFactory.uniqueKeys()) {
                fprintf(stdout, "%s\n", className.data());
            }
            return EXIT_SUCCESS;
        } else if (qstrncmp(argv[index], "Test", 4) == 0) {
Ejemplo n.º 28
0
void TEST_Serialization::SimpleSaveLoad()
{

	ObjectFactory<Serializable> factory;
	factory.Register("ObjectA", new ObjectCreator<ObjectA, Serializable>());

	
	ObjectA * save_pointer = new ObjectA(3, 4, 5);
	int save_int = 5;
	float save_float = 3.5f;
	double save_double = 3.5;
	char save_char = '5';
	bool save_bool = true;
	short save_short = 7;
	long save_long = 67;
	long double save_longdouble = 254.344;
	const char * save_string = "wee";
	unsigned int save_uint = 34;
	unsigned char save_uchar = '3';
	unsigned short save_ushort = 232;
	unsigned long save_ulong = 34 ;
	ObjectA save_object = ObjectA(6, 7, 8);

	ObjectA * load_pointer;
	int load_int = 0;
	float load_float = 0;
	double load_double = 0;
	char load_char = 0;
	bool load_bool = 0;
	short load_short = 0;
	long load_long = 0;
	long double load_longdouble = 0;
	char * load_string = 0;
	unsigned int load_uint = 0;
	unsigned char load_uchar = 0;
	unsigned short load_ushort = 0;
	unsigned long load_ulong = 0;
	ObjectA load_object;
	

	Stream  * file = new BinaryFileStream();
	file->StartWrite("test6.txt");

	file->Save(save_pointer);
	file->Save(save_int);
	file->Save(save_float);
	file->Save(save_double);
	file->Save(save_char);
	file->Save(save_bool);
	file->Save(save_short);
	file->Save(save_long);
	file->Save(save_longdouble);
	file->Save(save_string);
	file->Save(save_uint);
	file->Save(save_uchar);
	file->Save(save_ushort);
	file->Save(save_ulong);
	file->Save(save_object);

	file->Close();

	file->StartRead("test6.txt", factory);
	
	file->Load(load_pointer);
	file->Load(load_int);
	file->Load(load_float);
	file->Load(load_double);
	file->Load(load_char);
	file->Load(load_bool);
	file->Load(load_short);
	file->Load(load_long);
	file->Load(load_longdouble);
	file->Load(load_string);
	file->Load(load_uint);
	file->Load(load_uchar);
	file->Load(load_ushort);
	file->Load(load_ulong);
	file->Load(load_object);

	file->Close();
	delete file;
	
	Assert(save_int == load_int, "int equal");
	Assert(save_float == load_float, "float not equal");
	Assert(save_double == load_double, "double not equal");
	Assert(save_char == load_char, "char not equal");
	Assert(save_bool == load_bool, "bool not equal");
	Assert(save_short == load_short, "short not equal");
	Assert(save_long == load_long, "long not equal");
	Assert(save_longdouble == load_longdouble, "long not equal");
	Assert(strcmp(save_string, load_string) == 0, "strings not equal");
	Assert(save_uint == load_uint, "uint not equal");
	Assert(save_uchar == load_uchar, "uchar not equal");
	Assert(save_ushort == load_ushort, "ushort not equal");
	Assert(save_ulong == load_ulong, "ulong not equal");

	delete save_pointer;
	delete load_pointer;
	delete load_string;
}
Ejemplo n.º 29
0
int main(int argc, char** argv) {
	try {
		std::map<std::string, std::string> engines;
		ObjectFactory<std::string, Engine> engineFactory;

		ENGINE("groovie", "Groovie", Groovie::GroovieEngine);
		ENGINE("kyra2", "Legend of Kyrandia: Hand of Fate", Kyra::Kyra2Engine);
		ENGINE("scummv6", "SCUMM v6", Scumm::v6::Scummv6Engine);

		po::options_description visible("Options");
		visible.add_options()
			("help,h", "Produce this help message.")
			("engine,e", po::value<std::string>(), "Engine the script originates from.")
			("list,l", "List the supported engines.")
			("dump-disassembly,d", po::value<std::string>()->implicit_value(""), "Dump the disassembly to a file. Leave out filename to output to stdout.")
			("dump-graph,g", po::value<std::string>()->implicit_value(""), "Output the control flow graph in dot format to a file. Leave out filename to output to stdout.")
			("only-disassembly,D", "Stops after disassembly. Implies -d.")
			("only-graph,G", "Stops after control flow graph has been generated. Implies -g.")
			("show-unreachable,u", "Show the address and contents of unreachable groups in the script.")
			("variant,v", po::value<std::string>()->default_value(""), "Tell the engine that the script is from a specific variant. To see a list of variants supported by a specific engine, use the -h option and the -e option together.")
			("no-stack-effect,s", "Leave out the stack effect when printing raw instructions.");

		po::options_description args("");
		args.add(visible).add_options()
			("input-file", po::value<std::string>(), "Input file");

		po::positional_options_description fileArg;
		fileArg.add("input-file", -1);

		po::variables_map vm;
		try {
			// FIXME: If specified as the last parameter before the input file name, -d currently requires a filename to specified. -d must be specified earlier than that if outputting to stdout.
			po::store(po::command_line_parser(argc, argv).options(args).positional(fileArg).run(), vm);
			po::notify(vm);
		} catch (std::exception& e) {
			std::cout << e.what() << std::endl;
		}

		if (vm.count("list")) {
			std::cout << "Available engines:" << "\n";

			std::map<std::string, std::string>::iterator it;
			for (it = engines.begin(); it != engines.end(); it++)
				std::cout << (*it).first << " " << (*it).second << "\n";

			return 0;
		}

		if (vm.count("help") || !vm.count("input-file")) {
			std::cout << "Usage: " << argv[0] << " [option...] file" << "\n";
			std::cout << visible << "\n";
			if (vm.count("engine") && engines.find(vm["engine"].as<std::string>()) != engines.end()) {
				Engine *engine = engineFactory.create(vm["engine"].as<std::string>());
				std::vector<std::string> variants;
				engine->getVariants(variants);
				if (variants.empty()) {
					std::cout << engines[vm["engine"].as<std::string>()] << " does not use variants.\n";
				} else {
					std::cout << "Supported variants for " << engines[vm["engine"].as<std::string>()] << ":\n";
					for (std::vector<std::string>::iterator i = variants.begin(); i != variants.end(); ++i) {
						std::cout << "  " << *i << "\n";
					}
				}
				delete engine;
				std::cout << "\n";
			}
			std::cout << "Note: If outputting to stdout, -d or -g must NOT be specified immediately before the input file.\n";
			return 1;
		}

		if (!vm.count("engine")) {
			std::cout << "Engine must be specified.\n";
			return 2;
		} else if (engines.find(vm["engine"].as<std::string>()) == engines.end()) {
			std::cout << "Unknown engine.\n";
			return 2;
		}

		if (vm.count("no-stack-effect")) {
			setOutputStackEffect(false);
		}

		Engine *engine = engineFactory.create(vm["engine"].as<std::string>());
		engine->_variant = vm["variant"].as<std::string>();
		std::string inputFile = vm["input-file"].as<std::string>();

		// Disassembly
		InstVec insts;
		Disassembler *disassembler = engine->getDisassembler(insts);
		disassembler->open(inputFile.c_str());

		disassembler->disassemble();
		if (vm.count("dump-disassembly")) {
			std::streambuf *buf;
			std::ofstream of;

			if (vm["dump-disassembly"].as<std::string>() != "") {
				of.open(vm["dump-disassembly"].as<std::string>().c_str());
				buf = of.rdbuf();
			} else {
				buf = std::cout.rdbuf();
			}
			std::ostream out(buf);
			disassembler->dumpDisassembly(out);
		}

		if (!engine->supportsCodeFlow() || vm.count("only-disassembly") || insts.empty()) {
			if (!vm.count("dump-disassembly")) {
				disassembler->dumpDisassembly(std::cout);
			}
			delete disassembler;
			delete engine;
			return 0;
		}

		delete disassembler;

		// Control flow analysis
		ControlFlow *cf = new ControlFlow(insts, engine);
		cf->createGroups();
		Graph g = cf->analyze();

		if (vm.count("dump-graph")) {
			std::streambuf *buf;
			std::ofstream of;

			if (vm["dump-graph"].as<std::string>() != "") {
				of.open(vm["dump-graph"].as<std::string>().c_str());
				buf = of.rdbuf();
			} else {
				buf = std::cout.rdbuf();
			}
			std::ostream out(buf);
			boost::write_graphviz(out, g, boost::make_label_writer(get(boost::vertex_name, g)), boost::makeArrowheadWriter(get(boost::edge_attribute, g)), GraphProperties(engine, g));
		}

		if (!engine->supportsCodeGen() || vm.count("only-graph")) {
			if (!vm.count("dump-graph")) {
				boost::write_graphviz(std::cout, g, boost::make_label_writer(get(boost::vertex_name, g)), boost::makeArrowheadWriter(get(boost::edge_attribute, g)), GraphProperties(engine, g));
			}
			delete cf;
			delete engine;
			return 0;
		}

		// Post-processing of CFG
		engine->postCFG(insts, g);

		// Code generation
		CodeGenerator *cg = engine->getCodeGenerator(std::cout);
		cg->generate(g);

		if (vm.count("show-unreachable")) {
			std::vector<GroupPtr> unreachable;
			VertexRange vr = boost::vertices(g);
			for (VertexIterator v = vr.first; v != vr.second; ++v)
			{
				GroupPtr gr = boost::get(boost::vertex_name, g, *v);
				if (gr->_stackLevel == -1)
					unreachable.push_back(gr);
			}
			if (!unreachable.empty()) {
				for (size_t i = 0; i < unreachable.size(); i++) {
					if (i == 0) {
						if (unreachable.size() == 1)
							std::cout << boost::format("\n%d unreachable group detected.\n") % unreachable.size();
						else
							std::cout << boost::format("\n%d unreachable groups detected.\n") % unreachable.size();
					}
					std::cout << "Group " << (i + 1) << ":\n";
					ConstInstIterator inst = unreachable[i]->_start;
					do {
						std::cout << *inst;
					} while (inst++ != unreachable[i]->_end);
					std::cout << "----------\n";
				}
			}
		}

		// Free memory
		delete cf;
		delete cg;
		delete engine;
	} catch (UnknownOpcodeException &e) {
		std::cerr << "ERROR: " << e.what() << "\n";
		return 3;
	} catch (std::exception &e) {
		std::cerr << "ERROR: " << e.what() << "\n";
		return 4;
	}

	return 0;
}
Ejemplo n.º 30
0
void TEST_Serialization::SimpleSaveLoad1D()
{
	ObjectFactory<Serializable> factory;
	factory.Register("ObjectA", new ObjectCreator<ObjectA, Serializable>());


	ObjectA * save_pointer = new ObjectA();
	save_pointer->Set(1, 2, 3);
	int * save_int = new int[3];
	float * save_float = new float[3];
	double * save_double = new double[3];
	char * save_char = new char[3];
	bool * save_bool = new bool[3];
	short * save_short = new short[3];
	long * save_long = new long[3];
	long double * save_longdouble = new long double[3];
	unsigned int * save_uint = new unsigned int[3];
	unsigned char * save_uchar = new unsigned char[3];
	unsigned short * save_ushort = new unsigned short[3];
	unsigned long * save_ulong = new unsigned long[3];
	

	ObjectA * load_pointer = 0;
	int * load_int = 0;
	float * load_float = 0;
	double * load_double = 0;
	char * load_char = 0;
	bool * load_bool = 0;
	short * load_short = 0;
	long * load_long = 0;
	long double * load_longdouble = 0;
	unsigned int * load_uint = 0;
	unsigned char * load_uchar = 0;
	unsigned short * load_ushort = 0;
	unsigned long * load_ulong = 0;
	

	Stream  * file = new BinaryFileStream();
	file->StartWrite("test7.txt");

	file->Save(save_pointer);
	file->Save(save_int, 3);
	file->Save(save_float, 3);
	file->Save(save_double, 3);
	file->Save(save_char, 3);
	file->Save(save_bool, 3);
	file->Save(save_short, 3);
	file->Save(save_long, 3);
	file->Save(save_longdouble, 3);
	file->Save(save_uint, 3);
	file->Save(save_uchar, 3);
	file->Save(save_ushort, 3);
	file->Save(save_ulong, 3);
	

	file->Close();

	file->StartRead("test7.txt", factory);
	
	file->Load(load_pointer);
	file->Load(load_int);
	file->Load(load_float);
	file->Load(load_double);
	file->Load(load_char);
	file->Load(load_bool);
	file->Load(load_short);
	file->Load(load_long);
	file->Load(load_longdouble);
	file->Load(load_uint);
	file->Load(load_uchar);
	file->Load(load_ushort);
	file->Load(load_ulong);
	


	file->Close();
	delete file;


	delete save_pointer;
	delete [] save_int;
	delete [] save_float;
	delete [] save_double;
	delete [] save_char;
	delete [] save_bool;
	delete [] save_short;
	delete [] save_long;
	delete [] save_longdouble;
	delete [] save_uint;
	delete [] save_uchar;
	delete [] save_ushort;
	delete [] save_ulong;
	

	delete load_pointer;
	delete [] load_int;
	delete [] load_float;
	delete [] load_double;
	delete [] load_char;
	delete [] load_bool;
	delete [] load_short;
	delete [] load_long;
	delete [] load_longdouble;
	delete [] load_uint;
	delete [] load_uchar;
	delete [] load_ushort;
	delete [] load_ulong;
	
}