Ejemplo n.º 1
0
int main(int argc, char *argv[])
{
    Prototype *p = new ConcretePrototype();
	Prototype *p2 = p->clone();
	
    return 0;
}
Ejemplo n.º 2
0
int main(int argc, char* argv[])
{
	/*以下区块为一个测试,测试不用原型模式克隆对象,直接生成对象赋值,
	个人感觉和原型方法区别不是很大。唯一的区别需要知道具体类。抽象基类不能实例化,就算基类不是抽象的,
	仅凭基类以及子类的一个实例(不知道具体子类名)想得到一个与子类对象一样的实例是很困难的*/
	/*
	ConcretePrototype cp1(101,"wang",23);
    //ConcretePrototype cp2;
	//cp2=cp1;
    //上两句等效于
  	ConcretePrototype cp2(cp1);
	cp1.setName("zhang");
	cp1.show();	cp2.show();
	//*/
	Prototype* p = new ConcretePrototype(101,"wang",23);
	/*new ConcretePrototype(101,"wang",23); 可以是从其他渠道传递过来的
	也就是说,我们无需知道具体的类,只有拥有他的抽象接口,和一个具体的实例对象,
	我们就可以得到一个与其同样的对象,加以应用。这样,无论在系统运行时需要操作那个具体类,
	都可以动态制定
	*/
	Prototype* p1 = p->Clone();
	p->show(); p1->show();
	p->setName("li");
    p->show(); p1->show();
	printf("Hello World!\n");
	return 0;
}
Ejemplo n.º 3
0
const variable* ASObject::findVariableByMultiname(const multiname& name, GET_VARIABLE_OPTION opt, Class_base* cls)
{
	//Get from the current object without considering borrowed properties
	const variable* var=findGettable(name);

	if(!var && cls)
	{
		//Look for borrowed traits before
		var=cls->findBorrowedGettable(name);
	}

	if(!var && cls)
	{
		//Check prototype chain
		Prototype* proto = cls->prototype.getPtr();
		while(proto)
		{
			var = proto->getObj()->findGettable(name);
			if(var)
				break;
			proto = proto->prevPrototype.getPtr();
		}
	}
	return var;
}
Ejemplo n.º 4
0
bool ASObject::hasPropertyByMultiname(const multiname& name, bool considerDynamic, bool considerPrototype)
{
	//We look in all the object's levels
	uint32_t validTraits=DECLARED_TRAIT;
	if(considerDynamic)
		validTraits|=DYNAMIC_TRAIT;

	if(Variables.findObjVar(name, NO_CREATE_TRAIT, validTraits)!=NULL)
		return true;

	if(classdef && classdef->borrowedVariables.findObjVar(name, NO_CREATE_TRAIT, DECLARED_TRAIT)!=NULL)
		return true;

	//Check prototype inheritance chain
	if(getClass() && considerPrototype)
	{
		Prototype* proto = getClass()->prototype.getPtr();
		while(proto)
		{
			if(proto->getObj()->findGettable(name) != NULL)
				return true;
			proto=proto->prevPrototype.getPtr();
		}
	}

	//Must not ask for non borrowed traits as static class member are not valid
	return false;
}
Ejemplo n.º 5
0
int main() {
    Prototype  proto("hello");
    Prototype clone = proto;

    cout << "clone : " << clone.GetId() << endl;

    return 0;
}
Ejemplo n.º 6
0
void test_prototype()
{
	Prototype* p = new ConcretePrototype;
	Prototype* p1 = p->Clone();

	delete p;
	delete p1;
}
void PrototypeDialog::loadFWObject(FWObject *o)
{
    obj=o;
    Prototype *s = dynamic_cast<Prototype*>(obj);
    assert(s!=NULL);

    init=true;

    fillLibraries(libs,obj);

    obj_name->setText( QString::fromUtf8(s->getName().c_str()) );
    comment->setText( QString::fromUtf8(s->getComment().c_str()) );



    apply->setEnabled( false );
    init=false;
}
Ejemplo n.º 8
0
void IrGen::visit(Prototype& proto) {
  std::vector<llvm::Type*> doubles(proto.getParamNames().size(),
    llvm::Type::getDoubleTy(context));
  
  auto fnType = llvm::FunctionType::get(returnType, doubles, false);
  
  auto fn = llvm::Function::Create(fnType,
                                   llvm::Function::ExternalLinkage,
                                   proto.getName(),
                                   module);
  
  auto paramNameIter = proto.getParamNames().begin();
  for (auto& arg : fn->args()) {
    arg.setName(*paramNameIter++);
  }
  
  values.push(fn);
}
Ejemplo n.º 9
0
void Routine::replace_signature (CALLINGSTD_TYPE callstd_type)
{
    Prototype prototype = REPLACEMENT::make_prototype (this->name ().c_str (), callstd_type);

    typedef typename
    Switch <REPLACEMENT::arg_count,
           Case <0, Impl::Replace_Signature0 <REPLACEMENT>,
           Case <1, Impl::Replace_Signature1 <REPLACEMENT>,
           Case <2, Impl::Replace_Signature2 <REPLACEMENT>,
           Case <3, Impl::Replace_Signature3 <REPLACEMENT> > > > > >::result_type
           impl_type;

    AFUNPTR funcptr = impl_type::execute (*this, prototype, callstd_type);

    // Store the orginal function pointer, and close the prototype.
    typedef typename REPLACEMENT::funcptr_type funcptr_type;
    REPLACEMENT::original_funcptr (reinterpret_cast <funcptr_type> (funcptr));

    prototype.close ();
}
Ejemplo n.º 10
0
void
BuildLayer::render(RenderSystem* renderSystem, int, int)
{
  if(NULL == mStation) return;

  renderSystem->enableColorTexture(true);
  renderSystem->setColorTexture(mPortTexture);
  renderSystem->setMesh(mPortMesh);
  
  if(STATE_ADD == mState || STATE_SELECTED == mState) {
    const set<Module*>& modules = mStation->getModules();
    for(set<Module*>::const_iterator iModule = modules.begin(); iModule != modules.end(); ++iModule) {
      Module* currentModule = *iModule;
      if(STATE_SELECTED == mState && mSelectedModule == currentModule) continue;
      Matrix moduleTransform = currentModule->getTransform();
      Prototype* prototype = currentModule->getPrototype();
      
      const PortList& ports = prototype->getPorts();
      for(unsigned int iPort = 0; iPort < ports.size(); ++iPort) {
        if(!currentModule->isPortConnected(iPort)) {
          Matrix portTransform(ports[iPort]->getPosition(), ports[iPort]->getOrientation());
          Matrix combinedTransform = portTransform * moduleTransform;
          {
            renderSystem->renderMesh(combinedTransform);
          }          
        }
      }
    }
    if(MOUSEOVER_PORT == mMouseOver && mPrototype != NULL) {
      renderPrototype(renderSystem);
    }
  }

  if(STATE_SELECTED == mState && NULL != mSelectedModule) {
    renderSystem->enableAlphaBlending(true);  
    renderSystem->setColorTexture(mSelectedTexture);
    renderSystem->setMesh(mSelectedMesh);
    renderSystem->renderMesh(mSelectedModule->getTransform());
    renderSystem->enableAlphaBlending(false);  
  }  
}
Ejemplo n.º 11
0
int main( int argc, char* argv[] )
{
	Prototype* p = new ConcretePrototype();
	Prototype* p1 = p->Clone();

	//cout << "address p:  " << p << endl;
	//cout << "address p1: " << p1 << endl;

	if ( p )
	{
		delete p;
		p = NULL;
	}
	if ( p1 )
	{
		delete p1;
		p1 = NULL;
	}

	return 0;
}
Ejemplo n.º 12
0
///Prototype 原型模式提供了一个通过已存在对象进行新对象创建的接口
///实际上 Prototype 模式和 Builder 模式、 AbstractFactory 模式都是通过一个类(对象实例)来专门负责对象的创建工作(工厂对象), 它们之间的区别是:
///Builder 模式重在复杂对象的一步步创建 AbstractFactory 模式重在产生多个相互依赖类的对象,而 Prototype 模式重在从自身复制自己
void PrototypeTest() {
    Prototype* p = new ConcretePrototype();
    Prototype* p1 = p->Clone();
    delete p1;
}
Ejemplo n.º 13
0
 void Operation()
 {
   Prototype * p = _prototype->Clone();
   cout << "Using " << p->getType() << " created from prototype." << endl;
 }
Ejemplo n.º 14
0
 Prototype(const Prototype& other) { setType(other.getType()); }
Ejemplo n.º 15
0
int main(int argc, char *argv[])
{
	CSingleton *one = CSingleton::getInstance();	

	cout << "<<< Factory pattern >>>" << endl;
	Factory *fact = new DeriveFactory();
	Product *p1 = fact->createProduct();
	p1->display();

	AbstractFactory *abs1One = new Group1Factory();
	abs1One->createProductA();
	abs1One->createProductB();

	AbstractFactory *abs2One = new Group2Factory();
	abs2One->createProductA();
	abs2One->createProductB();

	Reciever *pRev = new Reciever();
	Command *pComm = new SubCommand(pRev);
	Invoke in(pComm);
	in.Action();

	Command *pComm2 = new SimpleCommand<Reciever>(pRev, &Reciever::Action);
	pComm2->act();
	cout << "<<< Facade pattern >>>" << endl;
	Facade *fa = new Facade();
	fa->operate();

	cout << "<<< Flyweight pattern >>>" << endl;
	FlyweightFactory *fwFactory = new FlyweightFactory();
	fwFactory->GetFlyweight("hello")->opt("world");
	fwFactory->GetFlyweight("haha")->opt("!!!");
	fwFactory->GetFlyweight("hello")->opt("world2");

	cout << "<<< Proxy pattern >>>" << endl;
	SubSubject *pSub = new SubSubject();
	Proxy *p2 = new Proxy(pSub);
	p2->request();

	cout << "<<< prototype pattern >>>" << endl;
	Prototype *prot = new SubPrototype();	
	Prototype *prot2 = prot->clone();

	cout << "<<< observer pattern >>>" << endl;
	OSubject *pOSub = new SubOSubject();
	ObserverA *pObA = new ObserverA();
	ObserverB *pObB = new ObserverB();
	pOSub->attach(pObA);
	pOSub->attach(pObB);
	pOSub->SetState("old");
	pOSub->notify();
	pOSub->SetState("new");
	pOSub->notify();
	
	cout << "<<< visitor pattern >>>" << endl;
	Visitor *pV = new SubVisitorA();
	Element *pE = new ElementA();
	pE->accept(pV);

	cout << "<<< state pattern >>>" << endl;
	State *pS = new StateA();
	Context *pSub3 = new Context(pS);
	pSub3->Operate();
	pSub3->Operate();
	pSub3->Operate();
	return 0;
}
Ejemplo n.º 16
0
int main(void)
{
     Prototype *p = new ConcretePrototype();
     Prototype *pl = p->Clone();
     return 0;
}