View Single Post
  #4   Spotlight this post!  
Unread 12-04-2012, 10:59
rbmj rbmj is offline
Registered User
FRC #0612 (Chantilly Robotics)
Team Role: Alumni
 
Join Date: Apr 2011
Rookie Year: 2011
Location: DC Area/Fairfax County
Posts: 192
rbmj is a jewel in the roughrbmj is a jewel in the roughrbmj is a jewel in the rough
Re: Declaring the AxisCamera as a module level variable.

Since AxisCamera is a singleton, you can just call AxisCamera::GetInstance(NULL). It doesn't reconnect. Use the SOURCE

See?
Code:
AxisCamera &AxisCamera::GetInstance(const char *cameraIP)
{
	if (NULL == _instance) //_instance is a static variable of type AxisCamera*
	{
		_instance = new AxisCamera(cameraIP);

		_instance->m_videoServer = new PCVideoServer();
	}

	return *_instance;
}
Just make sure you're not the first one to call GetInstance, otherwise you're screwed. Static initialization order fiasco anyone? Yay intermittent segfaults!

Another way is to just have an inline function:

Code:
static inline AxisCamera& camera() {
   static AxisCamera& c = AxisCamera::GetInstance(IP);
   return c;
}
Yes it's nice to have encapsulation, but when the camera is a global singleton *anyway*, what's the point?

Last edited by rbmj : 12-04-2012 at 11:01.
Reply With Quote