触发器类 , 指针函数

//
/***************************************************
 ***************************************************
  Trigger.cpp -- interface of the 'Trigger' general purpose TickTock Trigger
  version 1.0.8, Jan 15th, 2016

  Copyright (C) 2015-2016 Acheld CHEN

  This software is provided 'as-is', without any express or implied
  warranty.  In no event will the authors be held liable for any damages
  arising from the use of this software.

  Permission is granted to anyone to use this software for any purpose,
  including commercial applications, and to alter it and redistribute it
  freely, subject to the following restrictions:

  1. The origin of this software must not be misrepresented; you must not
     claim that you wrote the original software. If you use this software
     in a product, an acknowledgment in the product documentation would be
     appreciated but is not required.
  2. Altered source versions must be plainly marked as such, and must not be
     misrepresented as being the original software.
  3. This notice may not be removed or altered from any source distribution.

  Acheld CHEN       
  http://blog.csdn.net/acheld
  
 ***************************************************
 ****************************************************/

#include "StdAfx.h"
#include "Trigger.h"


CTrigger::CTrigger(void)
{
	m_pFnTrigger = NULL;
}


CTrigger::~CTrigger(void)
{
}



void CTrigger::InitTrigger( CTrigger* &pTrigger )
{
	pTrigger = NULL;
	if (!pTrigger)
	{
		pTrigger = new CTrigger();
	}
}

void CTrigger::TickTock()
{
	if (m_pFnTrigger){
		m_pFnTrigger(m_lpParam,m_dwPtr);
	}
}


//
//
/***************************************************
  Trigger.h -- interface of the 'Trigger' general purpose TickTock Trigger
  version 1.0.8, Jan 15th, 2016
  Acheld CHEN       
  http://blog.csdn.net/acheld

 ****************************************************/
#pragma once
//*******************************
//trigger timer function ,point function
//define one kind of the point function,create one new object function
//set this function as the params
//when some conditions satisfy ,call this function
//then can do some thing in this function
//*********************************
#include "TimeCount.h"


typedef void(* pFn_Trigger)(LPVOID lpParam, DWORD_PTR dwPtr);

void TockTrigger(LPVOID lpParam, DWORD_PTR dwPtr);
void TickTrigger(LPVOID lpParam, DWORD_PTR dwPtr);
//Tock(Qpart1,lpSpendTime);


class CTrigger
{
protected:
	CTrigger(void);
	~CTrigger(void);
public:
	static void InitTrigger(CTrigger* &pTrigger);
	void SetTrigger(pFn_Trigger pTrigger){
		m_pFnTrigger = pTrigger;
	}
	void TickTock();

	void SetlpParam(LPVOID lpParam){
		m_lpParam = lpParam;
	}
	LPVOID GetlpParam(){
		return m_lpParam;
	}

	void SetdwPtr(DWORD_PTR dwPtr){
		m_dwPtr = dwPtr;
	}
	DWORD_PTR GetdwPtr(){
		return m_dwPtr;
	}
protected:
	pFn_Trigger m_pFnTrigger;
	LPVOID m_lpParam;
	DWORD_PTR m_dwPtr;

};

extern CTrigger* g_Trigger;


你可能感兴趣的:(指针函数,触发函数类)