• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

C++ Singleton类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了C++中Singleton的典型用法代码示例。如果您正苦于以下问题:C++ Singleton类的具体用法?C++ Singleton怎么用?C++ Singleton使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



在下文中一共展示了Singleton类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C++代码示例。

示例1: ClientThread

DWORD WINAPI Server::ClientThread(LPVOID lpParam) //(insert to DEQUE) use MUTEX
{
	Singleton* log = Singleton::Instance();
	log->Add("Thread: Client runing");

	SOCKET sock = (SOCKET)lpParam; //Get socket

	while(f)
	{
		//recv DATA, create STRUCTURE and (insert to DEQUE)MUTEX
		//Send will be in APPLY THREAD
		if ( recv(sock,rdata.ch,sizeof(DWORD),0) != -1 ) //Wait data //save data to union
		{
			Message tmp;
			tmp.s = sock;
			tmp.data = rdata.i;

			WaitForSingleObject(hMutex,INFINITE);
			deque_data.push_back(tmp);
			ReleaseMutex(hMutex);
		}
		else
		{
			break;
		}
	}
	
	log->Add("Thread: Client stoped");
	return 0;
}
开发者ID:VIC373,项目名称:Source,代码行数:30,代码来源:Server.cpp


示例2: main

int main(void)
{
	HANDLE hE = CreateEvent(NULL,false,true,L"{@0001_Start_Program_Event}");
	if ( GetLastError() == ERROR_ALREADY_EXISTS ) 
	{	//program running
		return 0;
	}

	Singleton* log = Singleton::Instance();
	
	Server server;
	if ( server.Activate() )
	{
		cout << "ok" << endl;
	}

	int k = 10; 
	while (k)
	{
		system("cls");
		log->Show();
		system("@pause");
		k--;
		if (k == 1)
		{
			server.Deactivate(); //END THREADS
		}
	}
	system("@Pause");
	return 0;
}
开发者ID:VIC373,项目名称:Source,代码行数:31,代码来源:Server.cpp


示例3: main

int main(int argc , char *argv [])
{
	Singleton *singletonObj = Singleton ::GetInstance();
	cout<<singletonObj->GetTest()<<endl;

	return 0;
}
开发者ID:YuuFish,项目名称:LoveCode,代码行数:7,代码来源:SingletonDemo.cpp


示例4: disconnect

AnalitikaArtikliLista::~AnalitikaArtikliLista()
{
    disconnect(sm, SIGNAL(currentRowChanged(QModelIndex,QModelIndex)), this, SLOT(selectionChanged(QModelIndex,QModelIndex)));
    disconnect(header, SIGNAL(sectionResized(int, int, int)), this, SLOT(procSectionResized(int, int, int)));
    disconnect(header_2, SIGNAL(sectionResized(int, int, int)), this, SLOT(procSectionResizedDetail(int, int, int)));


    Singleton *s = Singleton::Instance();
    QStringList tempVals = s->saveWidthList(colWidth);
    s->Set_Faktura_HeaderState(tempVals);
    QStringList tempdetailVals = s->saveWidthList(colDetailWidth);
    s->Set_FakturaDetail_HeaderState(tempdetailVals);


    delete ui;
    delete model;
    delete header;
    delete model_2;
    delete header_2;
    delete b;
    b = 0;
    delete bc;
    bc = 0;
    delete bd;
    bd = 0;
}
开发者ID:srgank,项目名称:sterna_x,代码行数:26,代码来源:analitikaartiklilista.cpp


示例5: main

int main()
{
	Singleton* instance = Singleton::get();
	std::cout << instance->showData() << std::endl;

	return 0;
}
开发者ID:oswego,项目名称:DesignPattern,代码行数:7,代码来源:SingletonDesignPattern.cpp


示例6: setExecutor

void setExecutor(
    std::shared_ptr<Exe> executor,
    Singleton<std::weak_ptr<Exe>>& sExecutor,
    Singleton<RWSpinLock, LockTag>& sExecutorLock) {
  RWSpinLock::WriteHolder guard(sExecutorLock.get());
  *sExecutor.get() = std::move(executor);
}
开发者ID:Herysutrisno,项目名称:folly,代码行数:7,代码来源:GlobalExecutor.cpp


示例7: main

int main()
{
  Singleton *singleton = Singleton::getInstance();
  singleton->singletonOperation();

  return 0;
}
开发者ID:adousj,项目名称:design-patterns,代码行数:7,代码来源:main.cpp


示例8: getExecutor

std::shared_ptr<Exe> getExecutor(
    Singleton<std::weak_ptr<Exe>>& sExecutor,
    Singleton<std::shared_ptr<DefaultExe>>& sDefaultExecutor,
    Singleton<RWSpinLock, LockTag>& sExecutorLock) {
  std::shared_ptr<Exe> executor;
  auto singleton = sExecutor.try_get();
  auto lock = sExecutorLock.try_get();

  {
    RWSpinLock::ReadHolder guard(lock.get());
    if ((executor = sExecutor.try_get()->lock())) {
      return executor;
    }
  }


  RWSpinLock::WriteHolder guard(lock.get());
  executor = singleton->lock();
  if (!executor) {
    std::weak_ptr<Exe> defaultExecutor = *sDefaultExecutor.try_get().get();
    executor = defaultExecutor.lock();
    sExecutor.try_get().get()->swap(defaultExecutor);
  }
  return executor;
}
开发者ID:AmineCherrai,项目名称:wangle,代码行数:25,代码来源:GlobalExecutor.cpp


示例9: main

int main()
{
	Singleton *s = Singleton::getInstance();
	s->printInfo();	

	Singleton *s2 = Singleton::getInstance();
	s2->printInfo();	

	Singleton *s3 = Singleton::getInstance();
	s3->printInfo();	

//	Singleton *s4 = new Singleton();

//	Singleton s5;


	/* 创建线程,在线程里也去调用Singleton::getInstance */
	pthread_t thread1ID;
	pthread_t thread2ID;

	pthread_create(&thread1ID, NULL, start_routine_thread1, NULL);
	pthread_create(&thread2ID, NULL, start_routine_thread2, NULL);

	sleep(3);

	return 0;
}
开发者ID:weidongshan,项目名称:cpp_projects,代码行数:27,代码来源:Singleton7.cpp


示例10: thread_routine

void* thread_routine(void* arg)
{
	std::cout << pthread_self() << std::endl;
	Singleton* pInstance = Singleton::GetInstance();
	pInstance->Print();
	// 多线程下无法释放内存,否则会导致程序宕掉,最终导致内存泄漏
	return NULL;
}
开发者ID:wx7217242,项目名称:practice,代码行数:8,代码来源:singleton1.cpp


示例11: main

int main(void){
	Singleton *instance = Singleton::getInstance();
	instance->setValue(35);
	cout << instance->getValue() << endl;
	Singleton *object = Singleton::getInstance();
	cout << object->getValue() << endl; 

}
开发者ID:chikashimiyama,项目名称:sandbox,代码行数:8,代码来源:test.cpp


示例12: main

int main() {
    Singleton *s = Singleton::getInstance();
    s->pulse();
    cout << "main: global_ptr is " << GlobalClass::instance()->get_value() << '\n';
    foo();
    bar();
    return 0;
}
开发者ID:walrus7521,项目名称:code,代码行数:8,代码来源:singleton.cpp


示例13:

void		Game::_broadcastPacket(PacketContainer* p, bool tcp)
{
	Singleton<NetworkManager>	*network = NULL;

	for (auto it = this->_clients.begin(); it != this->_clients.end(); ++it)
	{
		network->getInstance()->sendPacket(p->getPacketSerialised(), (*it)->getConnexion(), tcp);
	}
}
开发者ID:tolsac,项目名称:RTYPE,代码行数:9,代码来源:Game.cpp


示例14: setExecutor

void setExecutor(
    std::shared_ptr<Exe> executor,
    Singleton<std::weak_ptr<Exe>>& sExecutor,
    Singleton<RWSpinLock, LockTag>& sExecutorLock) {
  auto lock = sExecutorLock.try_get();
  RWSpinLock::WriteHolder guard(*lock);
  std::weak_ptr<Exe> executor_weak = executor;
  sExecutor.try_get().get()->swap(executor_weak);
}
开发者ID:AmineCherrai,项目名称:wangle,代码行数:9,代码来源:GlobalExecutor.cpp


示例15:

void *start_routine_thread2(void *arg)
{
	cout<<"this is thread 2 ..."<<endl;

	Singleton *s = Singleton::getInstance();
	s->printInfo();	
	
	return NULL;
}
开发者ID:weidongshan,项目名称:cpp_projects,代码行数:9,代码来源:Singleton7.cpp


示例16: main

int main(){
	//Singleton * trysingleton = new Singleton(10);   //wrong
	Singleton * singleton = Singleton::createInstance(10);
	Singleton * singleton2 = Singleton::createInstance(12);
	singleton->print();		
	singleton2->print();
	singleton->deleteInstance();
	singleton2->deleteInstance();
	return 0;
}
开发者ID:wuyilun,项目名称:Pattern,代码行数:10,代码来源:singleton.cpp


示例17: changeLevelChooser

static void changeLevelChooser(const void *self)
{
	Singleton<LevelLoader> gLevelLoader;
	
	const SpinEdit *spinedit = (const SpinEdit *) self;

	gLevelLoader->loadLevelByID(spinedit->value);
	
	sgLevel.lastPlayerIndex = MAX_SCORE_COLS;
}
开发者ID:FLUXparticle,项目名称:CGmadness,代码行数:10,代码来源:ScreenChoose.cpp


示例18: run

 void run()
 {
     const int kCount = 2;
     for(int ix = 0; ix != kCount; ++ix)
     {
         Singleton * temp;
         temp = Singleton::getInstance();
         temp->print();
      
     }
 }
开发者ID:Burnisher,项目名称:cplusplus-fundamental-knowledge,代码行数:11,代码来源:singleton.cpp


示例19: main

int
main() {
  Singleton *p = Singleton::CreateInstance();
  Singleton a(*p); // -- 복제 생성자 호출

  a.SetData(20);

  cout << "p->data = " << p->GetData() << endl; // -- p->data = 10
  cout << "a.data = " << a.GetData() << endl;   // -- a.data = 20

  return 0;
}
开发者ID:elongbug,项目名称:design_pattern,代码行数:12,代码来源:copyconst.C


示例20: myThreadCode

// myThreadCode ///////////////////////////////////////////////////////////////
void * myThreadCode (void * param) {
    
    Singleton * theInstance;
    
    theInstance = Singleton::Instance();
    
    
    sleep(1);
    theInstance->increaseShared();
    
    return NULL;
}
开发者ID:jsrivaya,项目名称:Coding-Examples,代码行数:13,代码来源:main.cpp



注:本文中的Singleton类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
C++ UtlHashMap类代码示例发布时间:2022-06-01
下一篇:
C++ SingleWindow类代码示例发布时间:2022-06-01
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap