You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@activemq.apache.org by ch...@apache.org on 2006/07/28 10:22:55 UTC
svn commit: r426431 [13/14] - in /incubator/activemq/branches/activemq-4.0:
activemq-core/src/gram/script/
activemq-core/src/main/java/org/apache/activemq/kaha/impl/
activemq-core/src/main/java/org/apache/activemq/openwire/v1/
activemq-core/src/test/ja...
Modified: incubator/activemq/branches/activemq-4.0/openwire-cpp/src/main/cpp/ppr/thread/Semaphore.hpp
URL: http://svn.apache.org/viewvc/incubator/activemq/branches/activemq-4.0/openwire-cpp/src/main/cpp/ppr/thread/Semaphore.hpp?rev=426431&r1=426430&r2=426431&view=diff
==============================================================================
--- incubator/activemq/branches/activemq-4.0/openwire-cpp/src/main/cpp/ppr/thread/Semaphore.hpp (original)
+++ incubator/activemq/branches/activemq-4.0/openwire-cpp/src/main/cpp/ppr/thread/Semaphore.hpp Fri Jul 28 01:22:48 2006
@@ -1,240 +1,240 @@
-/*
- * Copyright 2006 The Apache Software Foundation or its licensors, as
- * applicable.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-#ifndef Ppr_Semaphore_hpp_
-#define Ppr_Semaphore_hpp_
-
-#if defined MACOSX
-#include <errno.h>
-#include <time.h>
-#include <pthread.h>
-#elif defined(__unix__) || defined(unix)
-#ifndef unix
-#define unix
-#endif
-#include <errno.h>
-#include <time.h>
-#include <semaphore.h>
-#endif
-#if defined(WIN32) || defined(__CYGWIN__) && !defined unix
-#if ( !defined(_WIN32_WINNT) || _WIN32_WINNT < 0x0400)
-#pragma message "Unsupported platform, Windows NT 4.0 or later required"
-#endif
-#include <windows.h>
-#endif
-
-#ifdef _MSC_VER
-#pragma warning( disable : 4100) // warning C4100: unreferenced formal parameter
-#endif
-
-namespace apache
-{
- namespace ppr
- {
- namespace thread
- {
-
-/*
- *
- */
-class Semaphore
-{
-private:
-#ifdef MACOSX
- // MacOSX lacks support for timedwait() on a semaphore. Need to build a semaphore upon a condition.
- pthread_cond_t cond;
- pthread_mutex_t mutex;
- int counter;
-#elif defined unix
- sem_t semaphore ;
-#else
- HANDLE semaphore ;
-#endif
-
-public:
- Semaphore(int initialSize = 0) ;
- ~Semaphore() ;
-
- void notify() ;
- void notify(int count) ;
- void wait() ;
- bool wait(int timeout_sec, time_t now = -1) ;
- bool trywait() ;
-} ;
-
-// Optimize all methods via inline code
-
-inline Semaphore::Semaphore(int initialSize)
-{
-#ifdef MACOSX
- pthread_cond_init (&cond, NULL);
- pthread_mutex_init (&mutex, NULL);
- counter = initialSize;
-#elif defined unix
- sem_init(&semaphore, 0 /* local to process */, initialSize) ;
-#else
- semaphore = CreateSemaphore(NULL, initialSize, 1000000, NULL) ;
-#endif
-}
-
-inline Semaphore::~Semaphore()
-{
-#ifdef MACOSX
- pthread_mutex_destroy (&mutex);
- pthread_cond_destroy (&cond);
-#elif defined unix
- sem_destroy(&semaphore) ;
-#else
- CloseHandle(semaphore) ;
-#endif
-}
-
-inline void Semaphore::notify()
-{
-#ifdef MACOSX
- pthread_mutex_lock (&mutex);
- ++counter;
- pthread_cond_signal (&cond);
- pthread_mutex_unlock (&mutex);
-#elif defined unix
- sem_post(&semaphore) ;
-#else
- ReleaseSemaphore(semaphore, 1, NULL) ;
-#endif
-}
-
-inline void Semaphore::notify(int count)
-{
-#ifdef MACOSX
- pthread_mutex_lock (&mutex);
- counter += count;
- pthread_cond_signal (&cond);
- pthread_mutex_unlock (&mutex);
-#elif defined unix
- while( count != 0 )
- {
- sem_post(&semaphore) ;
- --count ;
- }
-#else
- ReleaseSemaphore(semaphore, count, NULL) ;
-#endif
-}
-
-inline void Semaphore::wait()
-{
-#ifdef MACOSX
- pthread_mutex_lock (&mutex);
- while (counter == 0) {
- pthread_cond_wait (&cond, &mutex);
- }
- --counter;
- pthread_mutex_unlock (&mutex);
-#elif defined unix
- sem_wait(&semaphore) ;
-#else
- DWORD rc = WaitForSingleObject(semaphore, INFINITE) ;
- assert(rc == WAIT_OBJECT_0) ;
-#endif
-}
-
-/*
- * Waits specified number of seconds until it gives up. Returns false
- * if semaphore is signaled, true when timeout is reached.
- */
-inline bool Semaphore::wait(int timeout, time_t now)
-{
-#ifdef MACOSX
- if (now == -1) time(&now) ;
- timespec ts ;
- ts.tv_sec = now + timeout ;
- ts.tv_nsec = 0 ;
-
- pthread_mutex_lock (&mutex);
- while (counter == 0) {
- if (pthread_cond_timedwait (&cond, &mutex, &ts) == ETIMEDOUT) {
- pthread_mutex_unlock (&mutex);
- return true;
- }
- }
- --counter;
- pthread_mutex_unlock (&mutex);
- return true;
-#elif defined unix
- if (now == -1)
- time(&now) ;
-
- timespec ts ;
- ts.tv_sec = now + timeout ;
- ts.tv_nsec = 0 ;
-
- do
- {
- int rc = sem_timedwait(&semaphore, &ts) ;
-
- if (rc == 0)
- return false ;
-
- int errvalue = errno ;
-
- // Timeout occurred?
- if ( errvalue == ETIMEDOUT)
- return true ;
-
- assert(errvalue != EDEADLK) ;
- assert(errvalue != EINVAL) ;
- }
- while( true ) ;
-
- return true ;
-#else
- DWORD rc = WaitForSingleObject(semaphore, timeout * 1000) ;
- return (rc == WAIT_OBJECT_0 ? false : true) ;
-#endif
-}
-
-/*
- * Returns false if some error occured or semaphore has zero count, true
- * if semaphore successfully was decreased.
- */
-inline bool Semaphore::trywait()
-{
-#ifdef MACOSX
- pthread_mutex_lock (&mutex);
- if (counter == 0) {
- pthread_mutex_unlock (&mutex);
- return false;
- } else {
- --counter;
- pthread_mutex_unlock (&mutex);
- return true;
- }
-#elif defined unix
- int rc = sem_trywait(&semaphore) ;
- return ( rc == 0 ) ? true : false ;
-#else
- DWORD rc = WaitForSingleObject(semaphore, 0) ;
- return (rc == WAIT_OBJECT_0 ? true : false) ;
-#endif
-}
-
-/* namespace */
- }
- }
-}
-
-#endif /*Ppr_Semaphore_hpp_*/
-
+/*
+ * Copyright 2006 The Apache Software Foundation or its licensors, as
+ * applicable.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+#ifndef Ppr_Semaphore_hpp_
+#define Ppr_Semaphore_hpp_
+
+#if defined MACOSX
+#include <errno.h>
+#include <time.h>
+#include <pthread.h>
+#elif defined(__unix__) || defined(unix)
+#ifndef unix
+#define unix
+#endif
+#include <errno.h>
+#include <time.h>
+#include <semaphore.h>
+#endif
+#if defined(WIN32) || defined(__CYGWIN__) && !defined unix
+#if ( !defined(_WIN32_WINNT) || _WIN32_WINNT < 0x0400)
+#pragma message "Unsupported platform, Windows NT 4.0 or later required"
+#endif
+#include <windows.h>
+#endif
+
+#ifdef _MSC_VER
+#pragma warning( disable : 4100) // warning C4100: unreferenced formal parameter
+#endif
+
+namespace apache
+{
+ namespace ppr
+ {
+ namespace thread
+ {
+
+/*
+ *
+ */
+class Semaphore
+{
+private:
+#ifdef MACOSX
+ // MacOSX lacks support for timedwait() on a semaphore. Need to build a semaphore upon a condition.
+ pthread_cond_t cond;
+ pthread_mutex_t mutex;
+ int counter;
+#elif defined unix
+ sem_t semaphore ;
+#else
+ HANDLE semaphore ;
+#endif
+
+public:
+ Semaphore(int initialSize = 0) ;
+ ~Semaphore() ;
+
+ void notify() ;
+ void notify(int count) ;
+ void wait() ;
+ bool wait(int timeout_sec, time_t now = -1) ;
+ bool trywait() ;
+} ;
+
+// Optimize all methods via inline code
+
+inline Semaphore::Semaphore(int initialSize)
+{
+#ifdef MACOSX
+ pthread_cond_init (&cond, NULL);
+ pthread_mutex_init (&mutex, NULL);
+ counter = initialSize;
+#elif defined unix
+ sem_init(&semaphore, 0 /* local to process */, initialSize) ;
+#else
+ semaphore = CreateSemaphore(NULL, initialSize, 1000000, NULL) ;
+#endif
+}
+
+inline Semaphore::~Semaphore()
+{
+#ifdef MACOSX
+ pthread_mutex_destroy (&mutex);
+ pthread_cond_destroy (&cond);
+#elif defined unix
+ sem_destroy(&semaphore) ;
+#else
+ CloseHandle(semaphore) ;
+#endif
+}
+
+inline void Semaphore::notify()
+{
+#ifdef MACOSX
+ pthread_mutex_lock (&mutex);
+ ++counter;
+ pthread_cond_signal (&cond);
+ pthread_mutex_unlock (&mutex);
+#elif defined unix
+ sem_post(&semaphore) ;
+#else
+ ReleaseSemaphore(semaphore, 1, NULL) ;
+#endif
+}
+
+inline void Semaphore::notify(int count)
+{
+#ifdef MACOSX
+ pthread_mutex_lock (&mutex);
+ counter += count;
+ pthread_cond_signal (&cond);
+ pthread_mutex_unlock (&mutex);
+#elif defined unix
+ while( count != 0 )
+ {
+ sem_post(&semaphore) ;
+ --count ;
+ }
+#else
+ ReleaseSemaphore(semaphore, count, NULL) ;
+#endif
+}
+
+inline void Semaphore::wait()
+{
+#ifdef MACOSX
+ pthread_mutex_lock (&mutex);
+ while (counter == 0) {
+ pthread_cond_wait (&cond, &mutex);
+ }
+ --counter;
+ pthread_mutex_unlock (&mutex);
+#elif defined unix
+ sem_wait(&semaphore) ;
+#else
+ DWORD rc = WaitForSingleObject(semaphore, INFINITE) ;
+ assert(rc == WAIT_OBJECT_0) ;
+#endif
+}
+
+/*
+ * Waits specified number of seconds until it gives up. Returns false
+ * if semaphore is signaled, true when timeout is reached.
+ */
+inline bool Semaphore::wait(int timeout, time_t now)
+{
+#ifdef MACOSX
+ if (now == -1) time(&now) ;
+ timespec ts ;
+ ts.tv_sec = now + timeout ;
+ ts.tv_nsec = 0 ;
+
+ pthread_mutex_lock (&mutex);
+ while (counter == 0) {
+ if (pthread_cond_timedwait (&cond, &mutex, &ts) == ETIMEDOUT) {
+ pthread_mutex_unlock (&mutex);
+ return true;
+ }
+ }
+ --counter;
+ pthread_mutex_unlock (&mutex);
+ return true;
+#elif defined unix
+ if (now == -1)
+ time(&now) ;
+
+ timespec ts ;
+ ts.tv_sec = now + timeout ;
+ ts.tv_nsec = 0 ;
+
+ do
+ {
+ int rc = sem_timedwait(&semaphore, &ts) ;
+
+ if (rc == 0)
+ return false ;
+
+ int errvalue = errno ;
+
+ // Timeout occurred?
+ if ( errvalue == ETIMEDOUT)
+ return true ;
+
+ assert(errvalue != EDEADLK) ;
+ assert(errvalue != EINVAL) ;
+ }
+ while( true ) ;
+
+ return true ;
+#else
+ DWORD rc = WaitForSingleObject(semaphore, timeout * 1000) ;
+ return (rc == WAIT_OBJECT_0 ? false : true) ;
+#endif
+}
+
+/*
+ * Returns false if some error occured or semaphore has zero count, true
+ * if semaphore successfully was decreased.
+ */
+inline bool Semaphore::trywait()
+{
+#ifdef MACOSX
+ pthread_mutex_lock (&mutex);
+ if (counter == 0) {
+ pthread_mutex_unlock (&mutex);
+ return false;
+ } else {
+ --counter;
+ pthread_mutex_unlock (&mutex);
+ return true;
+ }
+#elif defined unix
+ int rc = sem_trywait(&semaphore) ;
+ return ( rc == 0 ) ? true : false ;
+#else
+ DWORD rc = WaitForSingleObject(semaphore, 0) ;
+ return (rc == WAIT_OBJECT_0 ? true : false) ;
+#endif
+}
+
+/* namespace */
+ }
+ }
+}
+
+#endif /*Ppr_Semaphore_hpp_*/
+
Propchange: incubator/activemq/branches/activemq-4.0/openwire-cpp/src/main/cpp/ppr/thread/Semaphore.hpp
------------------------------------------------------------------------------
svn:eol-style = native
Modified: incubator/activemq/branches/activemq-4.0/openwire-cpp/src/main/cpp/ppr/thread/SimpleMutex.hpp
URL: http://svn.apache.org/viewvc/incubator/activemq/branches/activemq-4.0/openwire-cpp/src/main/cpp/ppr/thread/SimpleMutex.hpp?rev=426431&r1=426430&r2=426431&view=diff
==============================================================================
--- incubator/activemq/branches/activemq-4.0/openwire-cpp/src/main/cpp/ppr/thread/SimpleMutex.hpp (original)
+++ incubator/activemq/branches/activemq-4.0/openwire-cpp/src/main/cpp/ppr/thread/SimpleMutex.hpp Fri Jul 28 01:22:48 2006
@@ -1,158 +1,158 @@
-/*
- * Copyright 2006 The Apache Software Foundation or its licensors, as
- * applicable.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-#ifndef Ppr_SimpleMutex_hpp_
-#define Ppr_SimpleMutex_hpp_
-
-#ifdef unix
-#include <pthread.h>
-#endif
-#if defined(WIN32) || defined(__CYGWIN__) && !defined unix
-#if ( !defined(_WIN32_WINNT) || _WIN32_WINNT < 0x0400)
-#pragma message "Unsupported platform, Windows NT 4.0 or later required"
-#endif
-#include <windows.h>
-#endif
-#include <assert.h>
-
-#ifndef LOCKED_SCOPE
-#define LOCKED_SCOPE(M) ::apache::ppr::thread::SimpleMutex::Lock _scope_lock_ (M)
-#define LOCKED_SCOPE_UNLOCK _scope_lock_.unlock()
-#define LOCKED_SCOPE_RELOCK _scope_lock_.relock()
-#endif
-
-
-namespace apache
-{
- namespace ppr
- {
- namespace thread
- {
-
-/*
- *
- */
-class SimpleMutex
-{
-public:
- class Lock {
- private:
- SimpleMutex* mutex;
- bool locked;
- public:
- Lock (SimpleMutex& mutex) : mutex (&mutex), locked (true) {
- mutex.lock();
- }
- Lock (p<SimpleMutex>& mutex) : mutex (getptr(mutex)), locked (true) {
- mutex->lock();
- }
- Lock (SimpleMutex* mutex) : mutex (mutex), locked (true) {
- mutex->lock();
- }
- ~Lock () {
- if (locked) mutex->unlock();
- }
- public:
- void unlock () {
- if (locked) {
- mutex->unlock();
- locked = false;
- }
- }
- void relock () {
- if (!locked) {
- mutex->lock();
- locked = true;
- }
- }
- };
-private:
-#ifdef unix
- pthread_mutex_t mutex ;
-#else
- CRITICAL_SECTION mutex ;
-#endif
-
-public:
- SimpleMutex() ;
- virtual ~SimpleMutex() ;
-
- bool trylock() ;
- void lock() ;
- void unlock() ;
-} ;
-
-// Optimize all methods via inline code
-
-inline SimpleMutex::SimpleMutex()
-{
-#ifdef unix
- pthread_mutexattr_t attr ;
- pthread_mutexattr_init(&attr) ;
- pthread_mutexattr_settype(&attr, PTHREAD_MUTEX_RECURSIVE) ;
- pthread_mutex_init(&mutex, &attr) ;
- pthread_mutexattr_destroy(&attr) ;
-#else
- InitializeCriticalSection(&mutex) ;
-#endif
-}
-
-inline SimpleMutex::~SimpleMutex()
-{
-#ifdef unix
- pthread_mutex_destroy(&mutex) ;
-#else
- DeleteCriticalSection(&mutex) ;
-#endif
-}
-
-inline bool SimpleMutex::trylock()
-{
-#ifdef unix
- int try_l = pthread_mutex_trylock(&mutex) ;
- if (try_l == 0)
- return true;
- else
- return false ;
-#else
- return (TryEnterCriticalSection(&mutex) != 0) ;
-#endif
-}
-
-inline void SimpleMutex::lock()
-{
-#ifdef unix
- pthread_mutex_lock(&mutex) ;
-#else
- EnterCriticalSection(&mutex) ;
-#endif
-}
-
-inline void SimpleMutex::unlock()
-{
-#ifdef unix
- pthread_mutex_unlock(&mutex) ;
-#else
- LeaveCriticalSection(&mutex) ;
-#endif
-}
-
-/* namespace */
- }
- }
-}
-
-#endif /*Ppr_SimpleMutex_hpp_*/
+/*
+ * Copyright 2006 The Apache Software Foundation or its licensors, as
+ * applicable.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+#ifndef Ppr_SimpleMutex_hpp_
+#define Ppr_SimpleMutex_hpp_
+
+#ifdef unix
+#include <pthread.h>
+#endif
+#if defined(WIN32) || defined(__CYGWIN__) && !defined unix
+#if ( !defined(_WIN32_WINNT) || _WIN32_WINNT < 0x0400)
+#pragma message "Unsupported platform, Windows NT 4.0 or later required"
+#endif
+#include <windows.h>
+#endif
+#include <assert.h>
+
+#ifndef LOCKED_SCOPE
+#define LOCKED_SCOPE(M) ::apache::ppr::thread::SimpleMutex::Lock _scope_lock_ (M)
+#define LOCKED_SCOPE_UNLOCK _scope_lock_.unlock()
+#define LOCKED_SCOPE_RELOCK _scope_lock_.relock()
+#endif
+
+
+namespace apache
+{
+ namespace ppr
+ {
+ namespace thread
+ {
+
+/*
+ *
+ */
+class SimpleMutex
+{
+public:
+ class Lock {
+ private:
+ SimpleMutex* mutex;
+ bool locked;
+ public:
+ Lock (SimpleMutex& mutex) : mutex (&mutex), locked (true) {
+ mutex.lock();
+ }
+ Lock (p<SimpleMutex>& mutex) : mutex (getptr(mutex)), locked (true) {
+ mutex->lock();
+ }
+ Lock (SimpleMutex* mutex) : mutex (mutex), locked (true) {
+ mutex->lock();
+ }
+ ~Lock () {
+ if (locked) mutex->unlock();
+ }
+ public:
+ void unlock () {
+ if (locked) {
+ mutex->unlock();
+ locked = false;
+ }
+ }
+ void relock () {
+ if (!locked) {
+ mutex->lock();
+ locked = true;
+ }
+ }
+ };
+private:
+#ifdef unix
+ pthread_mutex_t mutex ;
+#else
+ CRITICAL_SECTION mutex ;
+#endif
+
+public:
+ SimpleMutex() ;
+ virtual ~SimpleMutex() ;
+
+ bool trylock() ;
+ void lock() ;
+ void unlock() ;
+} ;
+
+// Optimize all methods via inline code
+
+inline SimpleMutex::SimpleMutex()
+{
+#ifdef unix
+ pthread_mutexattr_t attr ;
+ pthread_mutexattr_init(&attr) ;
+ pthread_mutexattr_settype(&attr, PTHREAD_MUTEX_RECURSIVE) ;
+ pthread_mutex_init(&mutex, &attr) ;
+ pthread_mutexattr_destroy(&attr) ;
+#else
+ InitializeCriticalSection(&mutex) ;
+#endif
+}
+
+inline SimpleMutex::~SimpleMutex()
+{
+#ifdef unix
+ pthread_mutex_destroy(&mutex) ;
+#else
+ DeleteCriticalSection(&mutex) ;
+#endif
+}
+
+inline bool SimpleMutex::trylock()
+{
+#ifdef unix
+ int try_l = pthread_mutex_trylock(&mutex) ;
+ if (try_l == 0)
+ return true;
+ else
+ return false ;
+#else
+ return (TryEnterCriticalSection(&mutex) != 0) ;
+#endif
+}
+
+inline void SimpleMutex::lock()
+{
+#ifdef unix
+ pthread_mutex_lock(&mutex) ;
+#else
+ EnterCriticalSection(&mutex) ;
+#endif
+}
+
+inline void SimpleMutex::unlock()
+{
+#ifdef unix
+ pthread_mutex_unlock(&mutex) ;
+#else
+ LeaveCriticalSection(&mutex) ;
+#endif
+}
+
+/* namespace */
+ }
+ }
+}
+
+#endif /*Ppr_SimpleMutex_hpp_*/
Propchange: incubator/activemq/branches/activemq-4.0/openwire-cpp/src/main/cpp/ppr/thread/SimpleMutex.hpp
------------------------------------------------------------------------------
svn:eol-style = native
Modified: incubator/activemq/branches/activemq-4.0/openwire-cpp/src/main/cpp/ppr/thread/Thread.cpp
URL: http://svn.apache.org/viewvc/incubator/activemq/branches/activemq-4.0/openwire-cpp/src/main/cpp/ppr/thread/Thread.cpp?rev=426431&r1=426430&r2=426431&view=diff
==============================================================================
--- incubator/activemq/branches/activemq-4.0/openwire-cpp/src/main/cpp/ppr/thread/Thread.cpp (original)
+++ incubator/activemq/branches/activemq-4.0/openwire-cpp/src/main/cpp/ppr/thread/Thread.cpp Fri Jul 28 01:22:48 2006
@@ -1,188 +1,188 @@
-/*
- * Copyright 2006 The Apache Software Foundation or its licensors, as
- * applicable.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-#include <memory> // auto_ptr
-#ifdef unix
-#include <errno.h> // EINTR
-#else
-#include <process.h> // _endthreadex
-#endif
-#include "ppr/thread/Thread.hpp"
-
-using namespace apache::ppr::thread;
-
-struct InternalThreadParam
-{
- p<Thread> threadObject ;
-} ;
-
-#ifdef unix
-static struct ThreadStaticInitializer {
- // Thread Attribute member
- pthread_attr_t threadAttribute;
- // Static Initializer:
- ThreadStaticInitializer() {
- pthread_attr_init (&threadAttribute);
- pthread_attr_setdetachstate (&threadAttribute, PTHREAD_CREATE_JOINABLE);
- }
-} threadStaticInitializer;
-#endif
-
-/*
- *
- */
-Thread::Thread() : started (false), joined (false)
-{
-}
-
-/*
- *
- */
-Thread::~Thread()
-{
-}
-
-/*
- *
- */
-void Thread::start() throw (runtime_error)
-{
- if( this->started )
- throw runtime_error ("Thread already started");
-
- auto_ptr<InternalThreadParam> threadParam (new InternalThreadParam()) ;
- threadParam->threadObject = smartify(this) ; // smartify() turns this-pointer into a smart pointer.
-#ifdef unix
- int err = pthread_create(
- &this->threadHandle,
- &threadStaticInitializer.threadAttribute,
- internal_thread_function,
- threadParam.get() ) ;
- if( err != 0 )
- throw runtime_error ("Coud not start thread") ;
-#else
- this->threadHandle = CreateThread(NULL, 0, internal_thread_function, threadParam.get(), 0, NULL) ;
- if (this->threadHandle == NULL)
- throw runtime_error ("Coud not start thread") ;
-#endif
- started = true ;
- threadParam.release() ; // (Does not delete threadParam).
- // threadParam is deleted in internal_thread_function() after when run() has returned.
-}
-
-p<exception> Thread::join()
-{
- if( !this->started )
- throw runtime_error ("Thread::join() called without having called Thread::start()");
-
- if( !this->joined )
-#ifdef unix
- pthread_join(this->threadHandle, NULL) ;
-#else
- WaitForSingleObject (this->threadHandle, INFINITE) ;
-#endif
- this->joined = true ;
- return threwnException ;
-}
-
-void Thread::sleep(int millisecs)
-{
-#ifdef unix
- struct timespec rec, rem ;
- rec.tv_sec = millisecs / 1000 ;
- rec.tv_nsec = (millisecs % 1000) * 1000000 ;
- while ( nanosleep( &rec, &rem ) == EINTR ) ;
-#else
- Sleep (millisecs) ;
-#endif
-}
-
-#ifdef unix
-void* Thread::internal_thread_function (void* param)
-#else
-unsigned long WINAPI Thread::internal_thread_function (void* param)
-#endif
-{
- InternalThreadParam* itp = (InternalThreadParam*) param ;
- try
- {
- itp->threadObject->run() ;
- }
- catch (exception* e)
- {
- itp->threadObject->threwnException = newptr (e) ;
- }
- catch (exception& e)
- {
- itp->threadObject->threwnException = new exception (e) ;
- }
- catch (p<exception> e)
- {
- itp->threadObject->threwnException = e ;
- }
- catch (...)
- {
- itp->threadObject->threwnException = new runtime_error ("An unknown exception was thrown") ;
- }
- p<Thread> threadObject = itp->threadObject ;
- delete itp ;
-#ifdef unix
- return NULL ;
-#else
- // Return 0 if no exception was threwn. Otherwise -1.
- unsigned long retval = (threadObject->threwnException == NULL ? 0 : -1) ;
- _endthreadex(retval) ; // Needed when using threads and CRT in Windows. Otherwise memleak can appear.
- return retval ;
-#endif
-}
-
-#ifdef UNITTEST
-
-#include <iostream>
-
-class MyThread : public Thread
-{
-public:
- bool throwException;
-protected:
- virtual void run () throw (p<exception>)
- {
- cout << "Running thread" << endl;
- if (throwException) {
- cout << "Throwing exception" << endl;
- throw p<exception> (new runtime_error ("Oops, something went wrong"));
- } else {
- cout << "Not throwing exception" << endl;
- }
- }
-};
-
-void testThread()
-{
- p<MyThread> t1 = new MyThread();
- p<MyThread> t2 = new MyThread();
- t1->throwException = false;
- t2->throwException = true;
- t1->start();
- t2->start();
- p<exception> e1 = t1->join();
- p<exception> e2 = t2->join();
- assert (e1 == NULL);
- assert (e2 != NULL);
- assert (strcmp (e2->what(), "Oops, something went wrong") == 0);
-}
-
-#endif // UNITTEST
+/*
+ * Copyright 2006 The Apache Software Foundation or its licensors, as
+ * applicable.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+#include <memory> // auto_ptr
+#ifdef unix
+#include <errno.h> // EINTR
+#else
+#include <process.h> // _endthreadex
+#endif
+#include "ppr/thread/Thread.hpp"
+
+using namespace apache::ppr::thread;
+
+struct InternalThreadParam
+{
+ p<Thread> threadObject ;
+} ;
+
+#ifdef unix
+static struct ThreadStaticInitializer {
+ // Thread Attribute member
+ pthread_attr_t threadAttribute;
+ // Static Initializer:
+ ThreadStaticInitializer() {
+ pthread_attr_init (&threadAttribute);
+ pthread_attr_setdetachstate (&threadAttribute, PTHREAD_CREATE_JOINABLE);
+ }
+} threadStaticInitializer;
+#endif
+
+/*
+ *
+ */
+Thread::Thread() : started (false), joined (false)
+{
+}
+
+/*
+ *
+ */
+Thread::~Thread()
+{
+}
+
+/*
+ *
+ */
+void Thread::start() throw (runtime_error)
+{
+ if( this->started )
+ throw runtime_error ("Thread already started");
+
+ auto_ptr<InternalThreadParam> threadParam (new InternalThreadParam()) ;
+ threadParam->threadObject = smartify(this) ; // smartify() turns this-pointer into a smart pointer.
+#ifdef unix
+ int err = pthread_create(
+ &this->threadHandle,
+ &threadStaticInitializer.threadAttribute,
+ internal_thread_function,
+ threadParam.get() ) ;
+ if( err != 0 )
+ throw runtime_error ("Coud not start thread") ;
+#else
+ this->threadHandle = CreateThread(NULL, 0, internal_thread_function, threadParam.get(), 0, NULL) ;
+ if (this->threadHandle == NULL)
+ throw runtime_error ("Coud not start thread") ;
+#endif
+ started = true ;
+ threadParam.release() ; // (Does not delete threadParam).
+ // threadParam is deleted in internal_thread_function() after when run() has returned.
+}
+
+p<exception> Thread::join()
+{
+ if( !this->started )
+ throw runtime_error ("Thread::join() called without having called Thread::start()");
+
+ if( !this->joined )
+#ifdef unix
+ pthread_join(this->threadHandle, NULL) ;
+#else
+ WaitForSingleObject (this->threadHandle, INFINITE) ;
+#endif
+ this->joined = true ;
+ return threwnException ;
+}
+
+void Thread::sleep(int millisecs)
+{
+#ifdef unix
+ struct timespec rec, rem ;
+ rec.tv_sec = millisecs / 1000 ;
+ rec.tv_nsec = (millisecs % 1000) * 1000000 ;
+ while ( nanosleep( &rec, &rem ) == EINTR ) ;
+#else
+ Sleep (millisecs) ;
+#endif
+}
+
+#ifdef unix
+void* Thread::internal_thread_function (void* param)
+#else
+unsigned long WINAPI Thread::internal_thread_function (void* param)
+#endif
+{
+ InternalThreadParam* itp = (InternalThreadParam*) param ;
+ try
+ {
+ itp->threadObject->run() ;
+ }
+ catch (exception* e)
+ {
+ itp->threadObject->threwnException = newptr (e) ;
+ }
+ catch (exception& e)
+ {
+ itp->threadObject->threwnException = new exception (e) ;
+ }
+ catch (p<exception> e)
+ {
+ itp->threadObject->threwnException = e ;
+ }
+ catch (...)
+ {
+ itp->threadObject->threwnException = new runtime_error ("An unknown exception was thrown") ;
+ }
+ p<Thread> threadObject = itp->threadObject ;
+ delete itp ;
+#ifdef unix
+ return NULL ;
+#else
+ // Return 0 if no exception was threwn. Otherwise -1.
+ unsigned long retval = (threadObject->threwnException == NULL ? 0 : -1) ;
+ _endthreadex(retval) ; // Needed when using threads and CRT in Windows. Otherwise memleak can appear.
+ return retval ;
+#endif
+}
+
+#ifdef UNITTEST
+
+#include <iostream>
+
+class MyThread : public Thread
+{
+public:
+ bool throwException;
+protected:
+ virtual void run () throw (p<exception>)
+ {
+ cout << "Running thread" << endl;
+ if (throwException) {
+ cout << "Throwing exception" << endl;
+ throw p<exception> (new runtime_error ("Oops, something went wrong"));
+ } else {
+ cout << "Not throwing exception" << endl;
+ }
+ }
+};
+
+void testThread()
+{
+ p<MyThread> t1 = new MyThread();
+ p<MyThread> t2 = new MyThread();
+ t1->throwException = false;
+ t2->throwException = true;
+ t1->start();
+ t2->start();
+ p<exception> e1 = t1->join();
+ p<exception> e2 = t2->join();
+ assert (e1 == NULL);
+ assert (e2 != NULL);
+ assert (strcmp (e2->what(), "Oops, something went wrong") == 0);
+}
+
+#endif // UNITTEST
Propchange: incubator/activemq/branches/activemq-4.0/openwire-cpp/src/main/cpp/ppr/thread/Thread.cpp
------------------------------------------------------------------------------
svn:eol-style = native
Modified: incubator/activemq/branches/activemq-4.0/openwire-cpp/src/main/cpp/ppr/thread/Thread.hpp
URL: http://svn.apache.org/viewvc/incubator/activemq/branches/activemq-4.0/openwire-cpp/src/main/cpp/ppr/thread/Thread.hpp?rev=426431&r1=426430&r2=426431&view=diff
==============================================================================
--- incubator/activemq/branches/activemq-4.0/openwire-cpp/src/main/cpp/ppr/thread/Thread.hpp (original)
+++ incubator/activemq/branches/activemq-4.0/openwire-cpp/src/main/cpp/ppr/thread/Thread.hpp Fri Jul 28 01:22:48 2006
@@ -1,133 +1,133 @@
-/*
- * Copyright 2006 The Apache Software Foundation or its licensors, as
- * applicable.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-#ifndef Ppr_Thread_hpp_
-#define Ppr_Thread_hpp_
-
-#ifdef unix
-#include <pthread.h>
-#else
-#include <windows.h>
-#endif
-
-#include <stdexcept>
-#include <assert.h>
-#include "ppr/util/ifr/p"
-
-
-namespace apache
-{
- namespace ppr
- {
- namespace thread
- {
- using namespace std;
- using namespace ifr;
-
-
-/**
-*/
-struct IThread : Interface
-{
- /** Creates a system thread and starts it in a joinable mode.
- @exception runtime_error is thrown if the system could
- not start the thread.
- */
- virtual void start() throw (runtime_error) = 0;
-
- /** Wait til the thread exits. This is when the run()
- method has returned or has threwn an exception.
- If an exception was threwn in the run() method,
- join() will return the threwn exception. Otherwise
- (if run() returned normally), join() will
- return NULL.
- */
- virtual p<exception> join() = 0;
-};
-
-/**
- *
- */
-class Thread : public IThread
-{
-private:
-#ifdef unix
- pthread_t threadHandle ;
-#else
- HANDLE threadHandle ;
-#endif
- /// true if thread is started.
- bool started;
- /// true if thread is joined
- bool joined;
- /// Exception threwn by run().
- p<exception> threwnException;
-public:
- /** Construct.
- */
- Thread() ;
- /** Destruct.
- */
- virtual ~Thread() ;
-
- /** Creates a system thread and starts it in a joinable mode.
- @exception runtime_error is thrown if the system could
- not start the thread.
- */
- virtual void start() throw (runtime_error);
-
- /** Wait til the thread exits. This is when the run()
- method has returned or has threwn an exception.
- If an exception was threwn in the run() method,
- join() will return the threwn exception. Otherwise
- (if run() returned normally), join() will
- return NULL.
- */
- virtual p<exception> join() ;
-public:
- /** Halts execution of the calling thread for a specified no of millisec.
-
- Note that this method is a static method that applies to the
- calling thread and not to the thread object.
- */
- static void sleep(int millisecs) ;
-protected:
- /** Derive from Thread and implement this method. This method will be
- called by the thread that is created by start().
-
- If an exception is threwn, the exception instance will be returned
- by join(). If the same exception instance (and not a copy of it)
- should be returned by join(), the implementation must throw
- a pointer to heap where the exception resides like this:
- throw p<exception> (new MyException());
- */
- virtual void run () throw (p<exception>) = 0;
-
-private:
- // Internal thread handling
-#ifdef unix
- static void* internal_thread_function (void* param);
-#else
- static unsigned long WINAPI internal_thread_function (void* param);
-#endif
-} ;
-
-/* namespace */
- }
- }
-}
-
-#endif /*Ppr_Thread_hpp_*/
+/*
+ * Copyright 2006 The Apache Software Foundation or its licensors, as
+ * applicable.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+#ifndef Ppr_Thread_hpp_
+#define Ppr_Thread_hpp_
+
+#ifdef unix
+#include <pthread.h>
+#else
+#include <windows.h>
+#endif
+
+#include <stdexcept>
+#include <assert.h>
+#include "ppr/util/ifr/p"
+
+
+namespace apache
+{
+ namespace ppr
+ {
+ namespace thread
+ {
+ using namespace std;
+ using namespace ifr;
+
+
+/**
+*/
+struct IThread : Interface
+{
+ /** Creates a system thread and starts it in a joinable mode.
+ @exception runtime_error is thrown if the system could
+ not start the thread.
+ */
+ virtual void start() throw (runtime_error) = 0;
+
+ /** Wait til the thread exits. This is when the run()
+ method has returned or has threwn an exception.
+ If an exception was threwn in the run() method,
+ join() will return the threwn exception. Otherwise
+ (if run() returned normally), join() will
+ return NULL.
+ */
+ virtual p<exception> join() = 0;
+};
+
+/**
+ *
+ */
+class Thread : public IThread
+{
+private:
+#ifdef unix
+ pthread_t threadHandle ;
+#else
+ HANDLE threadHandle ;
+#endif
+ /// true if thread is started.
+ bool started;
+ /// true if thread is joined
+ bool joined;
+ /// Exception threwn by run().
+ p<exception> threwnException;
+public:
+ /** Construct.
+ */
+ Thread() ;
+ /** Destruct.
+ */
+ virtual ~Thread() ;
+
+ /** Creates a system thread and starts it in a joinable mode.
+ @exception runtime_error is thrown if the system could
+ not start the thread.
+ */
+ virtual void start() throw (runtime_error);
+
+ /** Wait til the thread exits. This is when the run()
+ method has returned or has threwn an exception.
+ If an exception was threwn in the run() method,
+ join() will return the threwn exception. Otherwise
+ (if run() returned normally), join() will
+ return NULL.
+ */
+ virtual p<exception> join() ;
+public:
+ /** Halts execution of the calling thread for a specified no of millisec.
+
+ Note that this method is a static method that applies to the
+ calling thread and not to the thread object.
+ */
+ static void sleep(int millisecs) ;
+protected:
+ /** Derive from Thread and implement this method. This method will be
+ called by the thread that is created by start().
+
+ If an exception is threwn, the exception instance will be returned
+ by join(). If the same exception instance (and not a copy of it)
+ should be returned by join(), the implementation must throw
+ a pointer to heap where the exception resides like this:
+ throw p<exception> (new MyException());
+ */
+ virtual void run () throw (p<exception>) = 0;
+
+private:
+ // Internal thread handling
+#ifdef unix
+ static void* internal_thread_function (void* param);
+#else
+ static unsigned long WINAPI internal_thread_function (void* param);
+#endif
+} ;
+
+/* namespace */
+ }
+ }
+}
+
+#endif /*Ppr_Thread_hpp_*/
Propchange: incubator/activemq/branches/activemq-4.0/openwire-cpp/src/main/cpp/ppr/thread/Thread.hpp
------------------------------------------------------------------------------
svn:eol-style = native
Modified: incubator/activemq/branches/activemq-4.0/openwire-cpp/src/main/cpp/ppr/util/Endian.hpp
URL: http://svn.apache.org/viewvc/incubator/activemq/branches/activemq-4.0/openwire-cpp/src/main/cpp/ppr/util/Endian.hpp?rev=426431&r1=426430&r2=426431&view=diff
==============================================================================
--- incubator/activemq/branches/activemq-4.0/openwire-cpp/src/main/cpp/ppr/util/Endian.hpp (original)
+++ incubator/activemq/branches/activemq-4.0/openwire-cpp/src/main/cpp/ppr/util/Endian.hpp Fri Jul 28 01:22:48 2006
@@ -1,92 +1,92 @@
-/*
- * Copyright 2006 The Apache Software Foundation or its licensors, as
- * applicable.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-#ifndef Ppr_Endian_hpp_
-#define Ppr_Endian_hpp_
-
-#ifdef unix
-#include <netinet/in.h>
-#else
-#include <Winsock2.h>
-#endif
-#include "ppr/util/ifr/endian"
-
-// Use these if the compiler does not support _intXX
-#ifdef NEEDS_INT_DEFINED
-#define _int16 short
-#define _int32 int
-#define _int64 long long
-#endif
-
-namespace apache
-{
- namespace ppr
- {
- namespace util
- {
-
-// Macros and helpers for endian conversion
-#ifdef IFR_IS_BIG_ENDIAN
-inline unsigned int htoni (unsigned int i) { return i; }
-inline unsigned long long htonll (unsigned long long ll) { return ll; }
-inline float htonf (float f) { return f; }
-inline double htond (double d) { return d; }
-inline unsigned int ntohi (unsigned int i) { return i; }
-inline unsigned long long ntohll (unsigned long long ll) { return ll; }
-inline float ntohf (float f) { return f; }
-inline double ntohd (double d) { return d; }
-#else // !IFR_IS_BIG_ENDIAN
-
-inline unsigned int htoni (unsigned int i) {
- return
- ( i << 24 ) & 0xFF000000 |
- ( i << 8 ) & 0x00FF0000 |
- ( i >> 8 ) & 0x0000FF00 |
- ( i >> 24 ) & 0x000000FF;
-}
-
-inline unsigned long long htonll (unsigned long long ll) {
- return
- ( ll << 56 ) & 0xFF00000000000000ULL |
- ( ll << 40 ) & 0x00FF000000000000ULL |
- ( ll << 24 ) & 0x0000FF0000000000ULL |
- ( ll << 8 ) & 0x000000FF00000000ULL |
- ( ll >> 8 ) & 0x00000000FF000000ULL |
- ( ll >> 24 ) & 0x0000000000FF0000ULL |
- ( ll >> 40 ) & 0x000000000000FF00ULL |
- ( ll >> 56 ) & 0x00000000000000FFULL;
-}
-inline float htonf (float f) {
- unsigned int i = htoni( *(unsigned int *)&f ) ;
- return *(float *)&i ;
-}
-inline double htond (double d) {
- unsigned long long ll = htonll( *(unsigned long long *)&d ) ;
- return *(double *)&ll ;
-}
-inline unsigned int ntohi (unsigned int i) { return htoni (i); }
-inline unsigned long long ntohll (unsigned long long ll) { return htonll (ll); }
-inline float ntohf (float f) { return htonf (f); }
-inline double ntohd (double d) { return htond (d); }
-
-#endif // IFR_IS_BIG_ENDIAN
-
-/* namespace */
- }
- }
-}
-
-#endif /*Ppr_Endian_hpp_*/
+/*
+ * Copyright 2006 The Apache Software Foundation or its licensors, as
+ * applicable.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+#ifndef Ppr_Endian_hpp_
+#define Ppr_Endian_hpp_
+
+#ifdef unix
+#include <netinet/in.h>
+#else
+#include <Winsock2.h>
+#endif
+#include "ppr/util/ifr/endian"
+
+// Use these if the compiler does not support _intXX
+#ifdef NEEDS_INT_DEFINED
+#define _int16 short
+#define _int32 int
+#define _int64 long long
+#endif
+
+namespace apache
+{
+ namespace ppr
+ {
+ namespace util
+ {
+
+// Macros and helpers for endian conversion
+#ifdef IFR_IS_BIG_ENDIAN
+inline unsigned int htoni (unsigned int i) { return i; }
+inline unsigned long long htonll (unsigned long long ll) { return ll; }
+inline float htonf (float f) { return f; }
+inline double htond (double d) { return d; }
+inline unsigned int ntohi (unsigned int i) { return i; }
+inline unsigned long long ntohll (unsigned long long ll) { return ll; }
+inline float ntohf (float f) { return f; }
+inline double ntohd (double d) { return d; }
+#else // !IFR_IS_BIG_ENDIAN
+
+inline unsigned int htoni (unsigned int i) {
+ return
+ ( i << 24 ) & 0xFF000000 |
+ ( i << 8 ) & 0x00FF0000 |
+ ( i >> 8 ) & 0x0000FF00 |
+ ( i >> 24 ) & 0x000000FF;
+}
+
+inline unsigned long long htonll (unsigned long long ll) {
+ return
+ ( ll << 56 ) & 0xFF00000000000000ULL |
+ ( ll << 40 ) & 0x00FF000000000000ULL |
+ ( ll << 24 ) & 0x0000FF0000000000ULL |
+ ( ll << 8 ) & 0x000000FF00000000ULL |
+ ( ll >> 8 ) & 0x00000000FF000000ULL |
+ ( ll >> 24 ) & 0x0000000000FF0000ULL |
+ ( ll >> 40 ) & 0x000000000000FF00ULL |
+ ( ll >> 56 ) & 0x00000000000000FFULL;
+}
+inline float htonf (float f) {
+ unsigned int i = htoni( *(unsigned int *)&f ) ;
+ return *(float *)&i ;
+}
+inline double htond (double d) {
+ unsigned long long ll = htonll( *(unsigned long long *)&d ) ;
+ return *(double *)&ll ;
+}
+inline unsigned int ntohi (unsigned int i) { return htoni (i); }
+inline unsigned long long ntohll (unsigned long long ll) { return htonll (ll); }
+inline float ntohf (float f) { return htonf (f); }
+inline double ntohd (double d) { return htond (d); }
+
+#endif // IFR_IS_BIG_ENDIAN
+
+/* namespace */
+ }
+ }
+}
+
+#endif /*Ppr_Endian_hpp_*/
Propchange: incubator/activemq/branches/activemq-4.0/openwire-cpp/src/main/cpp/ppr/util/Endian.hpp
------------------------------------------------------------------------------
svn:eol-style = native
Modified: incubator/activemq/branches/activemq-4.0/openwire-cpp/src/main/cpp/ppr/util/Guid.cpp
URL: http://svn.apache.org/viewvc/incubator/activemq/branches/activemq-4.0/openwire-cpp/src/main/cpp/ppr/util/Guid.cpp?rev=426431&r1=426430&r2=426431&view=diff
==============================================================================
--- incubator/activemq/branches/activemq-4.0/openwire-cpp/src/main/cpp/ppr/util/Guid.cpp (original)
+++ incubator/activemq/branches/activemq-4.0/openwire-cpp/src/main/cpp/ppr/util/Guid.cpp Fri Jul 28 01:22:48 2006
@@ -1,86 +1,86 @@
-/*
- * Copyright 2006 The Apache Software Foundation or its licensors, as
- * applicable.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-#include "ppr/util/Guid.hpp"
-
-using namespace apache::ppr::util;
-
-Guid::Guid()
-{
- // no-op
-}
-
-/*
- * Creates a new UUID string.
- */
-unsigned char* Guid::getGuid()
-{
- unsigned char* buffer = new unsigned char[16] ;
-
-#if defined(WIN32) || defined(__CYGWIN__)
- GUID guid = GUID_NULL ;
-
- // Create GUID
- CoCreateGuid(&guid) ;
- if( guid == GUID_NULL )
- {
- // TODO: exception
- //cerr << "Failed to create an UUID" << endl ;
- return NULL ;
- }
- // Store GUID in internal buffer
- memcpy(buffer, &guid, 16) ;
-
-#else
- uuid_t uuid ;
-
- // Create UUID
- uuid_generate(uuid) ;
-
- // Store UUID in internal buffer
- memcpy(buffer, uuid, 16) ;
-#endif
-
- return buffer ;
-}
-
-/*
- *
- */
-p<string> Guid::getGuidString()
-{
- unsigned char* buffer = NULL ;
- char* result = NULL ;
- p<string> guidStr ;
-
- buffer = getGuid() ;
- result = new char[40] ;
-
- // Format into a string
- sprintf(result, "%02x%02x%02x%02x-%02x%02x-%02x%02x-%02x%02x-%02x%02x%02x%02x%02x%02x",
- buffer[0], buffer[1], buffer[2], buffer[3],
- buffer[4], buffer[5], buffer[6], buffer[7],
- buffer[8], buffer[9], buffer[10], buffer[11],
- buffer[12], buffer[13], buffer[14], buffer[15]) ;
-
- guidStr = new string(result) ;
-
- // Clean up
- delete result ;
- delete buffer ;
-
- return guidStr ;
-}
+/*
+ * Copyright 2006 The Apache Software Foundation or its licensors, as
+ * applicable.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+#include "ppr/util/Guid.hpp"
+
+using namespace apache::ppr::util;
+
+Guid::Guid()
+{
+ // no-op
+}
+
+/*
+ * Creates a new UUID string.
+ */
+unsigned char* Guid::getGuid()
+{
+ unsigned char* buffer = new unsigned char[16] ;
+
+#if defined(WIN32) || defined(__CYGWIN__)
+ GUID guid = GUID_NULL ;
+
+ // Create GUID
+ CoCreateGuid(&guid) ;
+ if( guid == GUID_NULL )
+ {
+ // TODO: exception
+ //cerr << "Failed to create an UUID" << endl ;
+ return NULL ;
+ }
+ // Store GUID in internal buffer
+ memcpy(buffer, &guid, 16) ;
+
+#else
+ uuid_t uuid ;
+
+ // Create UUID
+ uuid_generate(uuid) ;
+
+ // Store UUID in internal buffer
+ memcpy(buffer, uuid, 16) ;
+#endif
+
+ return buffer ;
+}
+
+/*
+ *
+ */
+p<string> Guid::getGuidString()
+{
+ unsigned char* buffer = NULL ;
+ char* result = NULL ;
+ p<string> guidStr ;
+
+ buffer = getGuid() ;
+ result = new char[40] ;
+
+ // Format into a string
+ sprintf(result, "%02x%02x%02x%02x-%02x%02x-%02x%02x-%02x%02x-%02x%02x%02x%02x%02x%02x",
+ buffer[0], buffer[1], buffer[2], buffer[3],
+ buffer[4], buffer[5], buffer[6], buffer[7],
+ buffer[8], buffer[9], buffer[10], buffer[11],
+ buffer[12], buffer[13], buffer[14], buffer[15]) ;
+
+ guidStr = new string(result) ;
+
+ // Clean up
+ delete result ;
+ delete buffer ;
+
+ return guidStr ;
+}
Propchange: incubator/activemq/branches/activemq-4.0/openwire-cpp/src/main/cpp/ppr/util/Guid.cpp
------------------------------------------------------------------------------
svn:eol-style = native
Modified: incubator/activemq/branches/activemq-4.0/openwire-cpp/src/main/cpp/ppr/util/Guid.hpp
URL: http://svn.apache.org/viewvc/incubator/activemq/branches/activemq-4.0/openwire-cpp/src/main/cpp/ppr/util/Guid.hpp?rev=426431&r1=426430&r2=426431&view=diff
==============================================================================
--- incubator/activemq/branches/activemq-4.0/openwire-cpp/src/main/cpp/ppr/util/Guid.hpp (original)
+++ incubator/activemq/branches/activemq-4.0/openwire-cpp/src/main/cpp/ppr/util/Guid.hpp Fri Jul 28 01:22:48 2006
@@ -1,61 +1,61 @@
-/*
- * Copyright 2006 The Apache Software Foundation or its licensors, as
- * applicable.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-#ifndef Ppr_Guid_hpp_
-#define Ppr_Guid_hpp_
-
-#include <string>
-#include <ppr/util/ifr/p>
-
-#ifdef unix
-#include <sys/param.h>
-#endif
-#include <stdio.h>
-#include <assert.h>
-#if defined(WIN32) || defined(__CYGWIN__)
-#include <objbase.h>
-#else
-#include <uuid/uuid.h>
-#endif
-
-namespace apache
-{
- namespace ppr
- {
- namespace util
- {
- using namespace std;
- using namespace ifr;
-
-/*
- * Helper class that generates global unique identifiers.
- */
-class Guid
-{
-private:
- Guid() ; // This class shall never be instanciated.
-
-public:
- static unsigned char* getGuid() ;
- static p<string> getGuidString() ;
-} ;
-
-/* namespace */
- }
- }
-}
-
-#endif /*Ppr_Guid_hpp_*/
+/*
+ * Copyright 2006 The Apache Software Foundation or its licensors, as
+ * applicable.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+#ifndef Ppr_Guid_hpp_
+#define Ppr_Guid_hpp_
+
+#include <string>
+#include <ppr/util/ifr/p>
+
+#ifdef unix
+#include <sys/param.h>
+#endif
+#include <stdio.h>
+#include <assert.h>
+#if defined(WIN32) || defined(__CYGWIN__)
+#include <objbase.h>
+#else
+#include <uuid/uuid.h>
+#endif
+
+namespace apache
+{
+ namespace ppr
+ {
+ namespace util
+ {
+ using namespace std;
+ using namespace ifr;
+
+/*
+ * Helper class that generates global unique identifiers.
+ */
+class Guid
+{
+private:
+ Guid() ; // This class shall never be instanciated.
+
+public:
+ static unsigned char* getGuid() ;
+ static p<string> getGuidString() ;
+} ;
+
+/* namespace */
+ }
+ }
+}
+
+#endif /*Ppr_Guid_hpp_*/
Propchange: incubator/activemq/branches/activemq-4.0/openwire-cpp/src/main/cpp/ppr/util/Guid.hpp
------------------------------------------------------------------------------
svn:eol-style = native
Modified: incubator/activemq/branches/activemq-4.0/openwire-cpp/src/main/cpp/ppr/util/Hex.cpp
URL: http://svn.apache.org/viewvc/incubator/activemq/branches/activemq-4.0/openwire-cpp/src/main/cpp/ppr/util/Hex.cpp?rev=426431&r1=426430&r2=426431&view=diff
==============================================================================
--- incubator/activemq/branches/activemq-4.0/openwire-cpp/src/main/cpp/ppr/util/Hex.cpp (original)
+++ incubator/activemq/branches/activemq-4.0/openwire-cpp/src/main/cpp/ppr/util/Hex.cpp Fri Jul 28 01:22:48 2006
@@ -1,52 +1,52 @@
-/*
- * Copyright 2006 The Apache Software Foundation or its licensors, as
- * applicable.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-#include "ppr/util/Hex.hpp"
-
-using namespace apache::ppr::util;
-
-/*
- *
- */
-Hex::Hex()
-{
- // no-op
-}
-
-/*
- *
- */
-Hex::~Hex()
-{
- // no-op
-}
-
-/*
- * Converts a byte array into a hex string.
- */
-p<string> Hex::toString(array<char> buffer)
-{
- array<char> result ((buffer.size() * 2) + 1);
- p<string> hexStr ;
-
- // Format into a string
- for( int i = 0 ; i < (int)buffer.size() ; i++ )
- sprintf(&result[i*2], "%02x", (unsigned char) buffer[i]) ;
-
- hexStr = new string(result.c_array(), result.size() - 1) ;
-
- return hexStr ;
-}
+/*
+ * Copyright 2006 The Apache Software Foundation or its licensors, as
+ * applicable.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+#include "ppr/util/Hex.hpp"
+
+using namespace apache::ppr::util;
+
+/*
+ *
+ */
+Hex::Hex()
+{
+ // no-op
+}
+
+/*
+ *
+ */
+Hex::~Hex()
+{
+ // no-op
+}
+
+/*
+ * Converts a byte array into a hex string.
+ */
+p<string> Hex::toString(array<char> buffer)
+{
+ array<char> result ((buffer.size() * 2) + 1);
+ p<string> hexStr ;
+
+ // Format into a string
+ for( int i = 0 ; i < (int)buffer.size() ; i++ )
+ sprintf(&result[i*2], "%02x", (unsigned char) buffer[i]) ;
+
+ hexStr = new string(result.c_array(), result.size() - 1) ;
+
+ return hexStr ;
+}
Propchange: incubator/activemq/branches/activemq-4.0/openwire-cpp/src/main/cpp/ppr/util/Hex.cpp
------------------------------------------------------------------------------
svn:eol-style = native
Modified: incubator/activemq/branches/activemq-4.0/openwire-cpp/src/main/cpp/ppr/util/Hex.hpp
URL: http://svn.apache.org/viewvc/incubator/activemq/branches/activemq-4.0/openwire-cpp/src/main/cpp/ppr/util/Hex.hpp?rev=426431&r1=426430&r2=426431&view=diff
==============================================================================
--- incubator/activemq/branches/activemq-4.0/openwire-cpp/src/main/cpp/ppr/util/Hex.hpp (original)
+++ incubator/activemq/branches/activemq-4.0/openwire-cpp/src/main/cpp/ppr/util/Hex.hpp Fri Jul 28 01:22:48 2006
@@ -1,52 +1,52 @@
-/*
- * Copyright 2006 The Apache Software Foundation or its licensors, as
- * applicable.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-#ifndef Ppr_Hex_hpp_
-#define Ppr_Hex_hpp_
-
-#include <string>
-#include <ppr/util/ifr/array>
-#include <ppr/util/ifr/p>
-
-namespace apache
-{
- namespace ppr
- {
- namespace util
- {
- using namespace std;
- using namespace ifr;
-
-/*
- * Helper class with conversion routines.
- */
-class Hex
-{
-private:
- Hex() ;
-
-public:
- ~Hex() ;
-
- static p<string> toString(array<char> buffer) ;
-} ;
-
-/* namespace */
- }
- }
-}
-
-#endif /*Ppr_Hex_hpp_*/
+/*
+ * Copyright 2006 The Apache Software Foundation or its licensors, as
+ * applicable.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+#ifndef Ppr_Hex_hpp_
+#define Ppr_Hex_hpp_
+
+#include <string>
+#include <ppr/util/ifr/array>
+#include <ppr/util/ifr/p>
+
+namespace apache
+{
+ namespace ppr
+ {
+ namespace util
+ {
+ using namespace std;
+ using namespace ifr;
+
+/*
+ * Helper class with conversion routines.
+ */
+class Hex
+{
+private:
+ Hex() ;
+
+public:
+ ~Hex() ;
+
+ static p<string> toString(array<char> buffer) ;
+} ;
+
+/* namespace */
+ }
+ }
+}
+
+#endif /*Ppr_Hex_hpp_*/
Propchange: incubator/activemq/branches/activemq-4.0/openwire-cpp/src/main/cpp/ppr/util/Hex.hpp
------------------------------------------------------------------------------
svn:eol-style = native
Modified: incubator/activemq/branches/activemq-4.0/openwire-cpp/src/main/cpp/ppr/util/MapItemHolder.cpp
URL: http://svn.apache.org/viewvc/incubator/activemq/branches/activemq-4.0/openwire-cpp/src/main/cpp/ppr/util/MapItemHolder.cpp?rev=426431&r1=426430&r2=426431&view=diff
==============================================================================
--- incubator/activemq/branches/activemq-4.0/openwire-cpp/src/main/cpp/ppr/util/MapItemHolder.cpp (original)
+++ incubator/activemq/branches/activemq-4.0/openwire-cpp/src/main/cpp/ppr/util/MapItemHolder.cpp Fri Jul 28 01:22:48 2006
@@ -1,380 +1,380 @@
-/*
- * Copyright 2006 The Apache Software Foundation or its licensors, as
- * applicable.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-#include "ppr/util/MapItemHolder.hpp"
-
-using namespace apache::ppr::util;
-
-#if defined (_MSC_VER) // Microsoft Visual Studio compiler
-#include <windows.h> // Defines LONG_PTR which is a long type with same size as a void*
-#else
-typedef long LONG_PTR; // Assume sizeof(long) == sizeof(void*)
-#endif
-
-
-// Constructors -----------------------------------------------------
-
-/*
- *
- */
-MapItemHolder::MapItemHolder()
-{
- this->value = NULL ;
- this->type = MapItemHolder::UNDEFINED ;
- this->flags = 0 ;
-}
-
-MapItemHolder::MapItemHolder(const MapItemHolder& other) :
- type (other.type),
- flags (other.flags)
-{
- if (flags & BIT_DESTRUCT) {
- // value is a ptr
- if ((flags & BIT_RELEASE_P_REFCOUNTED) == BIT_RELEASE_P_REFCOUNTED) {
- // value is a refcounted ptr
- this->value = other.value;
- if (value) addref (reinterpret_cast<refcounted*> (value));
- } else {
- // value is a standard ptr - handle specificly for each type:
- switch (type) {
- case DOUBLE:
- this->value = new double (other.getDouble());
- break;
- case LONG:
- this->value = new long long (other.getLong());
- break;
- default:
- assert (false); // Unknown type that requires heap allocation...
- }
- }
- } else {
- this->value = other.value;
- }
-}
-
-MapItemHolder&
-MapItemHolder::operator = (const MapItemHolder& other)
-{
- // Destruct us:
- this->~MapItemHolder();
-
- // Constuct us identical to how our copy constructor does:
- this->type = other.type;
- this->flags = other.flags;
-
- if (flags & BIT_DESTRUCT) {
- // value is a ptr
- if ((flags & BIT_RELEASE_P_REFCOUNTED) == BIT_RELEASE_P_REFCOUNTED) {
- // value is a refcounted ptr
- this->value = other.value;
- if (value) addref (reinterpret_cast<refcounted*> (value));
- } else {
- // value is a standard ptr - handle specificly for each type:
- switch (type) {
- case DOUBLE:
- this->value = new double (other.getDouble());
- break;
- case LONG:
- this->value = new long long (other.getLong());
- break;
- default:
- assert (false); // Unknown type that requires heap allocation...
- }
- }
- } else {
- this->value = other.value;
- }
- return *this;
-}
-
-
-/*
- *
- */
-MapItemHolder::MapItemHolder(bool value)
-{
- this->value = (value ? (void*) 1 : NULL);
- this->type = MapItemHolder::BOOLEAN ;
- this->flags = 0 ;
-}
-
-/*
- *
- */
-MapItemHolder::MapItemHolder(char value)
-{
- this->value = (void*) (LONG_PTR) value;
- this->type = MapItemHolder::BYTE ;
- this->flags = 0 ;
-}
-
-/*
- *
- */
-MapItemHolder::MapItemHolder(array<char> value)
-{
- this->value = static_cast<refcounted*> (getptr (array_help::get_array (value)));
- if (value != NULL) addref(value) ;
- this->type = MapItemHolder::BYTEARRAY ;
- this->flags =
- MapItemHolder::BIT_RELEASE_P_REFCOUNTED; // Tells destructor to release value
-}
-
-/*
- *
- */
-MapItemHolder::MapItemHolder(double value)
-{
- this->value = new double(value) ;
- this->type = MapItemHolder::DOUBLE ;
- this->flags =
- MapItemHolder::BIT_DESTRUCT; // Tells destructor to delete value
-}
-
-/*
- *
- */
-MapItemHolder::MapItemHolder(float value)
-{
- this->value = (void*) (LONG_PTR) value;
- this->type = MapItemHolder::FLOAT ;
- this->flags = 0 ;
-}
-
-/*
- *
- */
-MapItemHolder::MapItemHolder(int value)
-{
- this->value = (void*) (LONG_PTR) value;
- this->type = MapItemHolder::INTEGER ;
- this->flags = 0 ;
-}
-
-/*
- *
- */
-MapItemHolder::MapItemHolder(long long value)
-{
- this->value = new long long(value) ;
- this->type = MapItemHolder::LONG ;
- this->flags =
- MapItemHolder::BIT_DESTRUCT; // Tells destructor to delete value
-}
-
-/*
- *
- */
-MapItemHolder::MapItemHolder(short value)
-{
- this->value = (void*) (LONG_PTR) value;
- this->type = MapItemHolder::SHORT ;
- this->flags = 0 ;
-}
-
-/*
- *
- */
-MapItemHolder::MapItemHolder(p<string> value)
-{
- this->value = p_help::get_rc (value);
- if (value != NULL) addref(value) ;
- this->type = MapItemHolder::STRING ;
- this->flags =
- MapItemHolder::BIT_RELEASE_P_REFCOUNTED; // Tells destructor to release value
-}
-
-/*
- *
- */
-MapItemHolder::MapItemHolder(const char* value)
-{
- p<string> val = new string (value);
- this->value = p_help::get_rc (val);
- addref(val) ;
- this->type = MapItemHolder::STRING ;
- this->flags =
- MapItemHolder::BIT_RELEASE_P_REFCOUNTED; // Tells destructor to release value
-}
-
-/*
- *
- */
-MapItemHolder::~MapItemHolder()
-{
- if (flags & BIT_DESTRUCT) {
- // value must be destructed or released
- if ((flags & BIT_RELEASE_P_REFCOUNTED) == BIT_RELEASE_P_REFCOUNTED) {
- // value is a p<refcounted> - release it
- if (value) release (reinterpret_cast<refcounted*> (value));
- } else {
- // value is a primitive type allocated with new() - delete it.
- delete (int*) value ;
- }
- }
-}
-
-
-// Attribute methods ------------------------------------------------
-
-/*
- *
- */
-int MapItemHolder::getType() const
-{
- return type ;
-}
-
-/*
- *
- */
-bool MapItemHolder::getBoolean() const throw (ConversionException)
-{
- if( type == BOOLEAN )
- return ((LONG_PTR) value ? true : false);
- else
- throw ConversionException(__FILE__, __LINE__, "Cannot convert map item value to a boolean") ;
-}
-
-/*
- *
- */
-char MapItemHolder::getByte() const throw (ConversionException)
-{
- if( type == BYTE )
- return (char) (LONG_PTR) value;
- else
- throw ConversionException(__FILE__, __LINE__, "Cannot convert map item value to a byte") ;
-}
-
-/*
- *
- */
-array<char> MapItemHolder::getBytes() const throw (ConversionException)
-{
- if( type == BYTEARRAY ) {
- array<char> retval;
- array_help::get_array (retval) = smartify (
- static_cast<RCArray<char>*> (
- reinterpret_cast<refcounted*> (value)));
- if (retval != NULL) addref (retval);
- return retval;
- }
- else
- throw ConversionException(__FILE__, __LINE__, "Cannot convert map item value to a byte array") ;
-}
-
-/*
- *
- */
-double MapItemHolder::getDouble() const throw (ConversionException)
-{
- if( type == DOUBLE ) {
- return *(reinterpret_cast<double*> (value)) ;
- } else if ( type == FLOAT ) {
- return (double) (float) (LONG_PTR) value;
- } else
- throw ConversionException(__FILE__, __LINE__, "Cannot convert map item value to a double") ;
-}
-
-/*
- *
- */
-float MapItemHolder::getFloat() const throw (ConversionException)
-{
- if( type == FLOAT )
- return (float) (LONG_PTR) value;
- else
- throw ConversionException(__FILE__, __LINE__, "Cannot convert map item value to a float") ;
-}
-
-/*
- *
- */
-int MapItemHolder::getInt() const throw (ConversionException)
-{
- if( type & (INTEGER | SHORT | BYTE)) {
- return (int) (LONG_PTR) value;
- }
- else
- throw ConversionException(__FILE__, __LINE__, "Cannot convert map item value to an integer") ;
-}
-
-/*
- *
- */
-long long MapItemHolder::getLong() const throw (ConversionException)
-{
- if( type & (INTEGER | SHORT | BYTE)) {
- return (long long) (LONG_PTR) value;
- } else if ( type == LONG ) {
- return *(reinterpret_cast<long long*> (value)) ;
- } else
- throw ConversionException(__FILE__, __LINE__, "Cannot convert map item value to a long") ;
-}
-
-/*
- *
- */
-short MapItemHolder::getShort() const throw (ConversionException)
-{
- if( type & (SHORT | BYTE)) {
- return (short) (LONG_PTR) value;
- } else
- throw ConversionException(__FILE__, __LINE__, "Cannot convert map item value to a short") ;
-}
-
-/*
- *
- */
-p<string> MapItemHolder::getString() const throw (ConversionException)
-{
- p<string> retval ;
- char buffer[80] ;
-
- if (type == STRING) {
- p_help::set_rc (retval, value);
- p_help::set_obj (retval, static_cast<void_refcounter<string>*>(value)->obj_);
- if (retval != NULL) addref (retval);
- return retval;
- } else if (type == BOOLEAN) {
- sprintf(buffer, "%s", ( getBoolean() ? "true" : "false" ) ) ;
- retval = new string(buffer) ;
- return retval ;
- } else if (type & (BYTE | SHORT | INTEGER)) {
- sprintf(buffer, "%d", getInt() ) ;
- retval = new string(buffer) ;
- return retval ;
- } else if (type == LONG) {
-#ifdef unix
- sprintf(buffer, "%lld", getLong() ) ;
-#else
- sprintf(buffer, "%I64d", getLong() ) ;
-#endif
- retval = new string(buffer) ;
- return retval ;
- } else if (type == FLOAT) {
- sprintf(buffer, "%f", getFloat() ) ;
- retval = new string(buffer) ;
- return retval ;
- } else if (type == DOUBLE) {
- sprintf(buffer, "%lf", getDouble() ) ;
- retval = new string(buffer) ;
- return retval ;
- } else {
- throw ConversionException(__FILE__, __LINE__, "Cannot convert map item value to a string") ;
- }
-}
+/*
+ * Copyright 2006 The Apache Software Foundation or its licensors, as
+ * applicable.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+#include "ppr/util/MapItemHolder.hpp"
+
+using namespace apache::ppr::util;
+
+#if defined (_MSC_VER) // Microsoft Visual Studio compiler
+#include <windows.h> // Defines LONG_PTR which is a long type with same size as a void*
+#else
+typedef long LONG_PTR; // Assume sizeof(long) == sizeof(void*)
+#endif
+
+
+// Constructors -----------------------------------------------------
+
+/*
+ *
+ */
+MapItemHolder::MapItemHolder()
+{
+ this->value = NULL ;
+ this->type = MapItemHolder::UNDEFINED ;
+ this->flags = 0 ;
+}
+
+MapItemHolder::MapItemHolder(const MapItemHolder& other) :
+ type (other.type),
+ flags (other.flags)
+{
+ if (flags & BIT_DESTRUCT) {
+ // value is a ptr
+ if ((flags & BIT_RELEASE_P_REFCOUNTED) == BIT_RELEASE_P_REFCOUNTED) {
+ // value is a refcounted ptr
+ this->value = other.value;
+ if (value) addref (reinterpret_cast<refcounted*> (value));
+ } else {
+ // value is a standard ptr - handle specificly for each type:
+ switch (type) {
+ case DOUBLE:
+ this->value = new double (other.getDouble());
+ break;
+ case LONG:
+ this->value = new long long (other.getLong());
+ break;
+ default:
+ assert (false); // Unknown type that requires heap allocation...
+ }
+ }
+ } else {
+ this->value = other.value;
+ }
+}
+
+MapItemHolder&
+MapItemHolder::operator = (const MapItemHolder& other)
+{
+ // Destruct us:
+ this->~MapItemHolder();
+
+ // Constuct us identical to how our copy constructor does:
+ this->type = other.type;
+ this->flags = other.flags;
+
+ if (flags & BIT_DESTRUCT) {
+ // value is a ptr
+ if ((flags & BIT_RELEASE_P_REFCOUNTED) == BIT_RELEASE_P_REFCOUNTED) {
+ // value is a refcounted ptr
+ this->value = other.value;
+ if (value) addref (reinterpret_cast<refcounted*> (value));
+ } else {
+ // value is a standard ptr - handle specificly for each type:
+ switch (type) {
+ case DOUBLE:
+ this->value = new double (other.getDouble());
+ break;
+ case LONG:
+ this->value = new long long (other.getLong());
+ break;
+ default:
+ assert (false); // Unknown type that requires heap allocation...
+ }
+ }
+ } else {
+ this->value = other.value;
+ }
+ return *this;
+}
+
+
+/*
+ *
+ */
+MapItemHolder::MapItemHolder(bool value)
+{
+ this->value = (value ? (void*) 1 : NULL);
+ this->type = MapItemHolder::BOOLEAN ;
+ this->flags = 0 ;
+}
+
+/*
+ *
+ */
+MapItemHolder::MapItemHolder(char value)
+{
+ this->value = (void*) (LONG_PTR) value;
+ this->type = MapItemHolder::BYTE ;
+ this->flags = 0 ;
+}
+
+/*
+ *
+ */
+MapItemHolder::MapItemHolder(array<char> value)
+{
+ this->value = static_cast<refcounted*> (getptr (array_help::get_array (value)));
+ if (value != NULL) addref(value) ;
+ this->type = MapItemHolder::BYTEARRAY ;
+ this->flags =
+ MapItemHolder::BIT_RELEASE_P_REFCOUNTED; // Tells destructor to release value
+}
+
+/*
+ *
+ */
+MapItemHolder::MapItemHolder(double value)
+{
+ this->value = new double(value) ;
+ this->type = MapItemHolder::DOUBLE ;
+ this->flags =
+ MapItemHolder::BIT_DESTRUCT; // Tells destructor to delete value
+}
+
+/*
+ *
+ */
+MapItemHolder::MapItemHolder(float value)
+{
+ this->value = (void*) (LONG_PTR) value;
+ this->type = MapItemHolder::FLOAT ;
+ this->flags = 0 ;
+}
+
+/*
+ *
+ */
+MapItemHolder::MapItemHolder(int value)
+{
+ this->value = (void*) (LONG_PTR) value;
+ this->type = MapItemHolder::INTEGER ;
+ this->flags = 0 ;
+}
+
+/*
+ *
+ */
+MapItemHolder::MapItemHolder(long long value)
+{
+ this->value = new long long(value) ;
+ this->type = MapItemHolder::LONG ;
+ this->flags =
+ MapItemHolder::BIT_DESTRUCT; // Tells destructor to delete value
+}
+
+/*
+ *
+ */
+MapItemHolder::MapItemHolder(short value)
+{
+ this->value = (void*) (LONG_PTR) value;
+ this->type = MapItemHolder::SHORT ;
+ this->flags = 0 ;
+}
+
+/*
+ *
+ */
+MapItemHolder::MapItemHolder(p<string> value)
+{
+ this->value = p_help::get_rc (value);
+ if (value != NULL) addref(value) ;
+ this->type = MapItemHolder::STRING ;
+ this->flags =
+ MapItemHolder::BIT_RELEASE_P_REFCOUNTED; // Tells destructor to release value
+}
+
+/*
+ *
+ */
+MapItemHolder::MapItemHolder(const char* value)
+{
+ p<string> val = new string (value);
+ this->value = p_help::get_rc (val);
+ addref(val) ;
+ this->type = MapItemHolder::STRING ;
+ this->flags =
+ MapItemHolder::BIT_RELEASE_P_REFCOUNTED; // Tells destructor to release value
+}
+
+/*
+ *
+ */
+MapItemHolder::~MapItemHolder()
+{
+ if (flags & BIT_DESTRUCT) {
+ // value must be destructed or released
+ if ((flags & BIT_RELEASE_P_REFCOUNTED) == BIT_RELEASE_P_REFCOUNTED) {
+ // value is a p<refcounted> - release it
+ if (value) release (reinterpret_cast<refcounted*> (value));
+ } else {
+ // value is a primitive type allocated with new() - delete it.
+ delete (int*) value ;
+ }
+ }
+}
+
+
+// Attribute methods ------------------------------------------------
+
+/*
+ *
+ */
+int MapItemHolder::getType() const
+{
+ return type ;
+}
+
+/*
+ *
+ */
+bool MapItemHolder::getBoolean() const throw (ConversionException)
+{
+ if( type == BOOLEAN )
+ return ((LONG_PTR) value ? true : false);
+ else
+ throw ConversionException(__FILE__, __LINE__, "Cannot convert map item value to a boolean") ;
+}
+
+/*
+ *
+ */
+char MapItemHolder::getByte() const throw (ConversionException)
+{
+ if( type == BYTE )
+ return (char) (LONG_PTR) value;
+ else
+ throw ConversionException(__FILE__, __LINE__, "Cannot convert map item value to a byte") ;
+}
+
+/*
+ *
+ */
+array<char> MapItemHolder::getBytes() const throw (ConversionException)
+{
+ if( type == BYTEARRAY ) {
+ array<char> retval;
+ array_help::get_array (retval) = smartify (
+ static_cast<RCArray<char>*> (
+ reinterpret_cast<refcounted*> (value)));
+ if (retval != NULL) addref (retval);
+ return retval;
+ }
+ else
+ throw ConversionException(__FILE__, __LINE__, "Cannot convert map item value to a byte array") ;
+}
+
+/*
+ *
+ */
+double MapItemHolder::getDouble() const throw (ConversionException)
+{
+ if( type == DOUBLE ) {
+ return *(reinterpret_cast<double*> (value)) ;
+ } else if ( type == FLOAT ) {
+ return (double) (float) (LONG_PTR) value;
+ } else
+ throw ConversionException(__FILE__, __LINE__, "Cannot convert map item value to a double") ;
+}
+
+/*
+ *
+ */
+float MapItemHolder::getFloat() const throw (ConversionException)
+{
+ if( type == FLOAT )
+ return (float) (LONG_PTR) value;
+ else
+ throw ConversionException(__FILE__, __LINE__, "Cannot convert map item value to a float") ;
+}
+
+/*
+ *
+ */
+int MapItemHolder::getInt() const throw (ConversionException)
+{
+ if( type & (INTEGER | SHORT | BYTE)) {
+ return (int) (LONG_PTR) value;
+ }
+ else
+ throw ConversionException(__FILE__, __LINE__, "Cannot convert map item value to an integer") ;
+}
+
+/*
+ *
+ */
+long long MapItemHolder::getLong() const throw (ConversionException)
+{
+ if( type & (INTEGER | SHORT | BYTE)) {
+ return (long long) (LONG_PTR) value;
+ } else if ( type == LONG ) {
+ return *(reinterpret_cast<long long*> (value)) ;
+ } else
+ throw ConversionException(__FILE__, __LINE__, "Cannot convert map item value to a long") ;
+}
+
+/*
+ *
+ */
+short MapItemHolder::getShort() const throw (ConversionException)
+{
+ if( type & (SHORT | BYTE)) {
+ return (short) (LONG_PTR) value;
+ } else
+ throw ConversionException(__FILE__, __LINE__, "Cannot convert map item value to a short") ;
+}
+
+/*
+ *
+ */
+p<string> MapItemHolder::getString() const throw (ConversionException)
+{
+ p<string> retval ;
+ char buffer[80] ;
+
+ if (type == STRING) {
+ p_help::set_rc (retval, value);
+ p_help::set_obj (retval, static_cast<void_refcounter<string>*>(value)->obj_);
+ if (retval != NULL) addref (retval);
+ return retval;
+ } else if (type == BOOLEAN) {
+ sprintf(buffer, "%s", ( getBoolean() ? "true" : "false" ) ) ;
+ retval = new string(buffer) ;
+ return retval ;
+ } else if (type & (BYTE | SHORT | INTEGER)) {
+ sprintf(buffer, "%d", getInt() ) ;
+ retval = new string(buffer) ;
+ return retval ;
+ } else if (type == LONG) {
+#ifdef unix
+ sprintf(buffer, "%lld", getLong() ) ;
+#else
+ sprintf(buffer, "%I64d", getLong() ) ;
+#endif
+ retval = new string(buffer) ;
+ return retval ;
+ } else if (type == FLOAT) {
+ sprintf(buffer, "%f", getFloat() ) ;
+ retval = new string(buffer) ;
+ return retval ;
+ } else if (type == DOUBLE) {
+ sprintf(buffer, "%lf", getDouble() ) ;
+ retval = new string(buffer) ;
+ return retval ;
+ } else {
+ throw ConversionException(__FILE__, __LINE__, "Cannot convert map item value to a string") ;
+ }
+}
Propchange: incubator/activemq/branches/activemq-4.0/openwire-cpp/src/main/cpp/ppr/util/MapItemHolder.cpp
------------------------------------------------------------------------------
svn:eol-style = native
Modified: incubator/activemq/branches/activemq-4.0/openwire-cpp/src/main/cpp/ppr/util/MapItemHolder.hpp
URL: http://svn.apache.org/viewvc/incubator/activemq/branches/activemq-4.0/openwire-cpp/src/main/cpp/ppr/util/MapItemHolder.hpp?rev=426431&r1=426430&r2=426431&view=diff
==============================================================================
--- incubator/activemq/branches/activemq-4.0/openwire-cpp/src/main/cpp/ppr/util/MapItemHolder.hpp (original)
+++ incubator/activemq/branches/activemq-4.0/openwire-cpp/src/main/cpp/ppr/util/MapItemHolder.hpp Fri Jul 28 01:22:48 2006
@@ -1,102 +1,102 @@
-/*
- * Copyright 2006 The Apache Software Foundation or its licensors, as
- * applicable.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-#ifndef Ppr_MapItemHolder_hpp_
-#define Ppr_MapItemHolder_hpp_
-
-#include <string>
-#include <map>
-#include "ppr/ConversionException.hpp"
-#include "ppr/util/ifr/array"
-#include "ppr/util/ifr/p"
-
-// Turn off warning message for ignored exception specification
-#ifdef _MSC_VER
-#pragma warning( disable : 4290 )
-#endif
-
-namespace apache
-{
- namespace ppr
- {
- namespace util
- {
- using namespace apache::ppr;
- using namespace std;
- using namespace ifr;
-
-/*
- *
- */
-class MapItemHolder
-{
-private:
- void* value ;
- int type,
- flags ;
-
- const static int BIT_DESTRUCT = 0x01000000;
- const static int BIT_RELEASE_P_REFCOUNTED = BIT_DESTRUCT | 0x02000000;
- //const static int BIT_RELEASE_P_VOID = BIT_DESTRUCT | 0x04000000;
-
-public:
- const static int UNDEFINED = 0x00000000 ;
- const static int BOOLEAN = 0x00000001 ;
- const static int BYTE = 0x00000002 ;
- const static int BYTEARRAY = 0x00000004 ;
- const static int DOUBLE = 0x00000008 ;
- const static int FLOAT = 0x00000010 ;
- const static int INTEGER = 0x00000020 ;
- const static int LONG = 0x00000040 ;
- const static int SHORT = 0x00000080 ;
- const static int STRING = 0x00000100 ;
-
-public:
- MapItemHolder() ;
- MapItemHolder(const MapItemHolder& other) ;
- MapItemHolder& operator = (const MapItemHolder& other) ;
- MapItemHolder(bool value) ;
- MapItemHolder(char value) ;
- MapItemHolder(array<char> value) ;
- MapItemHolder(double value) ;
- MapItemHolder(float value) ;
- MapItemHolder(int value) ;
- MapItemHolder(long long value) ;
- MapItemHolder(short value) ;
- MapItemHolder(p<string> value) ;
- MapItemHolder(const char* value) ;
- ~MapItemHolder() ;
-
- int getType() const ;
- bool getBoolean() const throw (ConversionException) ;
- char getByte() const throw (ConversionException) ;
- array<char> getBytes() const throw (ConversionException) ;
- double getDouble() const throw (ConversionException) ;
- float getFloat() const throw (ConversionException) ;
- int getInt() const throw (ConversionException) ;
- long long getLong() const throw (ConversionException) ;
- short getShort() const throw (ConversionException) ;
- p<string> getString() const throw (ConversionException) ;
-} ;
-
-typedef map<string, MapItemHolder> PropertyMap ;
-
-/* namespace */
- }
- }
-}
-
-#endif /*Ppr_MapItemHolder_hpp_*/
+/*
+ * Copyright 2006 The Apache Software Foundation or its licensors, as
+ * applicable.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+#ifndef Ppr_MapItemHolder_hpp_
+#define Ppr_MapItemHolder_hpp_
+
+#include <string>
+#include <map>
+#include "ppr/ConversionException.hpp"
+#include "ppr/util/ifr/array"
+#include "ppr/util/ifr/p"
+
+// Turn off warning message for ignored exception specification
+#ifdef _MSC_VER
+#pragma warning( disable : 4290 )
+#endif
+
+namespace apache
+{
+ namespace ppr
+ {
+ namespace util
+ {
+ using namespace apache::ppr;
+ using namespace std;
+ using namespace ifr;
+
+/*
+ *
+ */
+class MapItemHolder
+{
+private:
+ void* value ;
+ int type,
+ flags ;
+
+ const static int BIT_DESTRUCT = 0x01000000;
+ const static int BIT_RELEASE_P_REFCOUNTED = BIT_DESTRUCT | 0x02000000;
+ //const static int BIT_RELEASE_P_VOID = BIT_DESTRUCT | 0x04000000;
+
+public:
+ const static int UNDEFINED = 0x00000000 ;
+ const static int BOOLEAN = 0x00000001 ;
+ const static int BYTE = 0x00000002 ;
+ const static int BYTEARRAY = 0x00000004 ;
+ const static int DOUBLE = 0x00000008 ;
+ const static int FLOAT = 0x00000010 ;
+ const static int INTEGER = 0x00000020 ;
+ const static int LONG = 0x00000040 ;
+ const static int SHORT = 0x00000080 ;
+ const static int STRING = 0x00000100 ;
+
+public:
+ MapItemHolder() ;
+ MapItemHolder(const MapItemHolder& other) ;
+ MapItemHolder& operator = (const MapItemHolder& other) ;
+ MapItemHolder(bool value) ;
+ MapItemHolder(char value) ;
+ MapItemHolder(array<char> value) ;
+ MapItemHolder(double value) ;
+ MapItemHolder(float value) ;
+ MapItemHolder(int value) ;
+ MapItemHolder(long long value) ;
+ MapItemHolder(short value) ;
+ MapItemHolder(p<string> value) ;
+ MapItemHolder(const char* value) ;
+ ~MapItemHolder() ;
+
+ int getType() const ;
+ bool getBoolean() const throw (ConversionException) ;
+ char getByte() const throw (ConversionException) ;
+ array<char> getBytes() const throw (ConversionException) ;
+ double getDouble() const throw (ConversionException) ;
+ float getFloat() const throw (ConversionException) ;
+ int getInt() const throw (ConversionException) ;
+ long long getLong() const throw (ConversionException) ;
+ short getShort() const throw (ConversionException) ;
+ p<string> getString() const throw (ConversionException) ;
+} ;
+
+typedef map<string, MapItemHolder> PropertyMap ;
+
+/* namespace */
+ }
+ }
+}
+
+#endif /*Ppr_MapItemHolder_hpp_*/