From 33fef4a17290e7872293d8cc173bec826f24001c Mon Sep 17 00:00:00 2001 From: Mike Buland Date: Wed, 3 May 2006 02:56:51 +0000 Subject: Added the new singleton class template. Very cool, now I need to switch all my singletons to using it. --- src/http.cpp | 2 +- src/singleton.h | 46 ++++++++++++++++++++++++++++++ src/test/httpsrv/httpconnectionmonitor.cpp | 11 +++++-- 3 files changed, 56 insertions(+), 3 deletions(-) create mode 100644 src/singleton.h (limited to 'src') diff --git a/src/http.cpp b/src/http.cpp index 11950b7..19122c3 100644 --- a/src/http.cpp +++ b/src/http.cpp @@ -146,7 +146,7 @@ bool Http::buildResponse( short nResponseCode, const char *sResponse ) time( &curTime ); gmtime_r( &curTime, &tResTime ); - sServerStr = "YFHttp/0.0.1"; + sServerStr = "libbu++ Http/0.0.1"; bResPersistant = false; //char buf[30]; diff --git a/src/singleton.h b/src/singleton.h new file mode 100644 index 0000000..c69e6f1 --- /dev/null +++ b/src/singleton.h @@ -0,0 +1,46 @@ +#ifndef SINGLETON_H +#define SINGLETON_H + +#include + +/** + * Provides singleton functionality in a modular sort of way. Make this the + * base class of any other class and you immediately gain singleton + * functionality. Be sure to make your constructor and various functions use + * intellegent scoping. Cleanup and instantiation are performed automatically + * for you at first use and program exit. There are two things that you must + * do when using this template, first is to inherit from it with the name of + * your class filling in for T and then make this class a friend of your class. + *@code + * // Making the Single Singleton: + * class Single : public Singleton + * { + * friend class Singleton; + * protected: + * Single(); + * ... + * }; + @endcode + * You can still add public functions and variables to your new Singleton child + * class, but your constructor should be protected (hence the need for the + * friend decleration). + *@author Mike Buland + */ +template +class Singleton +{ +protected: + Singleton() {}; + +private: + Singleton( const Singleton& ); + +public: + static T &getInstance() + { + static T i; + return i; + } +}; + +#endif diff --git a/src/test/httpsrv/httpconnectionmonitor.cpp b/src/test/httpsrv/httpconnectionmonitor.cpp index 4eb6817..eaadb36 100644 --- a/src/test/httpsrv/httpconnectionmonitor.cpp +++ b/src/test/httpsrv/httpconnectionmonitor.cpp @@ -49,15 +49,22 @@ bool HttpConnectionMonitor::onNewConnection( Connection *pCon ) else { printf("Non get: %s\n", hp.getRequestTypeStr() ); + pCon->appendOutput("HTTP/1.1 100 Continue\r\n\r\n"); } pCon->writeOutput(); + //for( int j = 0; j < 50; j++ ) + { + pCon->readInput( 1, 0 ); + //printf("Size so far: %d\n", pCon->getInputAmnt() ); + } if( pCon->hasInput() ) { std::string s( pCon->getInput(), pCon->getInputAmnt() ); - printf("Reamining data\n==============\n%s\n==============\n", - s.c_str() ); + pCon->printInputDebug(); + //printf("Reamining data\n==============\n%s\n==============\n", + // s.c_str() ); } pCon->disconnect(); -- cgit v1.2.3