当前位置: 首页>>代码示例>>C++>>正文


C++ Singleton类代码示例

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


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


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