|
From: <axl...@us...> - 2008-12-03 12:22:21
|
Revision: 28
http://hgengine.svn.sourceforge.net/hgengine/?rev=28&view=rev
Author: axlecrusher
Date: 2008-12-03 11:43:29 +0000 (Wed, 03 Dec 2008)
Log Message:
-----------
Add instance counter and functions to convert strings to upper
Modified Paths:
--------------
Mercury2/src/MercuryUtil.h
Added Paths:
-----------
Mercury2/src/MercuryUtil.cpp
Added: Mercury2/src/MercuryUtil.cpp
===================================================================
--- Mercury2/src/MercuryUtil.cpp (rev 0)
+++ Mercury2/src/MercuryUtil.cpp 2008-12-03 11:43:29 UTC (rev 28)
@@ -0,0 +1,35 @@
+#include <MercuryUtil.h>
+
+std::string ToUpper(const std::string& s)
+{
+ std::string t = s;
+ for (int i = 0; i < s.length(); ++i)
+ {
+ t[i] = toupper(t[i]);
+ }
+ return t;
+}
+
+/***************************************************************************
+ * Copyright (C) 2008 by Joshua Allen *
+ * *
+ * *
+ * All rights reserved. *
+ * *
+ * Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: *
+ * * Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. *
+ * * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. *
+ * * Neither the name of the <ORGANIZATION> nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission. *
+ * *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS *
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT *
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR *
+ * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR *
+ * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, *
+ * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, *
+ * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR *
+ * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF *
+ * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING *
+ * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS *
+ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. *
+ ***************************************************************************/
Modified: Mercury2/src/MercuryUtil.h
===================================================================
--- Mercury2/src/MercuryUtil.h 2008-12-03 11:40:01 UTC (rev 27)
+++ Mercury2/src/MercuryUtil.h 2008-12-03 11:43:29 UTC (rev 28)
@@ -2,6 +2,7 @@
#define MERCURYUTIL_H
#include <stdlib.h>
+#include <string>
/*#ifndef NULL
#define NULL 0
#endif*/
@@ -9,13 +10,50 @@
#define SAFE_DELETE( x ) { if (x) { delete x; } x = NULL; }
#define SAFE_DELETE_ARRAY( x ) { if (x) { delete[] x; } x = NULL; }
-#if defined(__GNUC__)
-#define M_ALIGN(n) __attribute__((aligned(n)))
-#else
-#define M_ALIGN(n)
-#endif
+#if defined(__GNUC__)
+#define M_ALIGN(n) __attribute__((aligned(n)))
+#else
+#define M_ALIGN(n)
+#endif
+std::string ToUpper(const std::string& s);
+//This counter is used with singletons to
+//ensure proper destruction order of the
+//singleton
+#include <stdio.h>
+template<typename T>
+class InstanceCounter
+{
+ public:
+ InstanceCounter(const std::string& name)
+ :m_name(name)
+ {
+ if (m_count == 0)
+ {
+ printf("Creating instance %s\n", m_name.c_str());
+ m_instance = &T::GetInstance();
+ }
+ ++m_count;
+ }
+ ~InstanceCounter()
+ {
+ --m_count;
+ if (m_count == 0)
+ {
+ printf("Destroying instance %s\n", m_name.c_str());
+ SAFE_DELETE(m_instance);
+ }
+ }
+ private:
+ static unsigned long m_count;
+ std::string m_name;
+ T* m_instance;
+};
+
+template<typename T>
+ unsigned long InstanceCounter<T>::m_count = 0;
+
#endif
/* Copyright (c) 2008, Joshua Allen
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|