From 76542f8b94b83e1291971866b1a11d5ac552db3b Mon Sep 17 00:00:00 2001 From: Bartosz Taudul Date: Sun, 13 Jul 2008 16:23:15 +0200 Subject: [PATCH] Replace vectorbuffer with std::queue. Replace non-standard vectorbuffer with std::queue. SDL now requires Open C++. --- src/main/symbian/SDL_main.cpp | 17 +-- src/main/symbian/vectorbuffer.cpp | 52 --------- src/main/symbian/vectorbuffer.h | 221 ------------------------------------ symbian/include/internal/epoc_sdl.h | 2 +- symbian/sdl.mmp | 3 +- 5 files changed, 12 insertions(+), 283 deletions(-) delete mode 100644 src/main/symbian/vectorbuffer.cpp delete mode 100644 src/main/symbian/vectorbuffer.h diff --git a/src/main/symbian/SDL_main.cpp b/src/main/symbian/SDL_main.cpp index a5e0d68..ab18472 100644 --- a/src/main/symbian/SDL_main.cpp +++ b/src/main/symbian/SDL_main.cpp @@ -1,10 +1,10 @@ +#include #include "epoc_sdl.h" #include "sdlepocapi.h" #include #include #include #include -#include "vectorbuffer.h" #include #include #include @@ -107,13 +107,13 @@ class CEventQueue : public CBase, public MEventQueue void ConstructL(); ~CEventQueue(); TInt Append(const TWsEvent& aEvent); - const TWsEvent& Shift(); + const TWsEvent Shift(); void Lock(); void Unlock(); TBool HasData(); private: - TVector iVector; + std::queue m_queue; RCriticalSection iCS; }; @@ -131,16 +131,16 @@ CEventQueue::~CEventQueue() TInt CEventQueue::Append(const TWsEvent& aEvent) { Lock(); - const TInt err = iVector.Append(aEvent); + m_queue.push(aEvent); Unlock(); - return err; + return 0; } TBool CEventQueue::HasData() { EnvUtils::RunSingleThread(); - return iVector.Size() > 0; + return !m_queue.empty(); } void CEventQueue::Lock() @@ -155,9 +155,10 @@ void CEventQueue::Unlock() iCS.Signal(); } -const TWsEvent& CEventQueue::Shift() +const TWsEvent CEventQueue::Shift() { - const TWsEvent& event = iVector.Shift(); + const TWsEvent event = m_queue.front(); + m_queue.pop(); return event; } diff --git a/src/main/symbian/vectorbuffer.cpp b/src/main/symbian/vectorbuffer.cpp deleted file mode 100644 index 1969f5e..0000000 --- a/src/main/symbian/vectorbuffer.cpp +++ /dev/null @@ -1,52 +0,0 @@ -/* - vectorbuffer.cpp - yet another circle buffer - - Markus Mertama - */ - -#include"vectorbuffer.h" - -void VectorPanic(TInt aErr, TInt aLine) -{ - TBuf<64> b; - b.Format(_L("vector buffer at % d "), aLine); - User::Panic(b, aErr); -} - -void TNodeBuffer::TNode::Terminator(TNodeBuffer::TNode* aNode) -{ - Mem::Copy(iSucc, &aNode, sizeof(TNode*)); -} - -TInt TNodeBuffer::TNode::Size() const -{ - return reinterpret_cast(iSucc) - Ptr(); -} - -const TUint8* TNodeBuffer::TNode::Ptr() const -{ - return reinterpret_cast(this) + sizeof(TNode); -} - -TNodeBuffer::TNode* TNodeBuffer::TNode::Empty(TUint8* aBuffer) -{ - TNode* node = reinterpret_cast(aBuffer); - node->iSucc = node + 1; - return node; -} - -TNodeBuffer::TNode* TNodeBuffer::TNode::New(TNode* aPred, const TDesC8& aData) -{ - TNode* node = aPred->Size() == 0 ? aPred : aPred->iSucc; - - - TUint8* start = reinterpret_cast(node) + sizeof(TNode); - node->iSucc = reinterpret_cast(start + aData.Size()); - node->iSucc->iSucc = NULL; //terminator - - __ASSERT_DEBUG(node->Size() == aData.Size(), VECPANIC(KErrCorrupt)); - - Mem::Copy(start, aData.Ptr(), aData.Size()); - return node; -} diff --git a/src/main/symbian/vectorbuffer.h b/src/main/symbian/vectorbuffer.h deleted file mode 100644 index 8a12055..0000000 --- a/src/main/symbian/vectorbuffer.h +++ /dev/null @@ -1,221 +0,0 @@ -/* - vectorbuffer.cpp - yet another circle buffer - - Markus Mertama - */ - -#ifndef __VECTORBUFFER_H__ -#define __VECTORBUFFER_H__ - -#include -#define VECPANIC(x) VectorPanic(x, __LINE__) -void VectorPanic(TInt, TInt); - - -//Internal - -NONSHARABLE_CLASS(TNodeBuffer) -{ - public: - protected: - NONSHARABLE_CLASS(TNode) - { - public: - static TNode* Empty(TUint8* iBuffer); - static TNode* New(TNode* aPrev, const TDesC8& aData); - const TUint8* Ptr() const; - TInt Size() const; - inline TNode* Succ(); - static void SetSucc(TNode*& aNode); - void Terminator(TNode* aNode); - private: - TNode* iSucc; - }; -}; - -inline TNodeBuffer::TNode* TNodeBuffer::TNode::Succ() -{ - return iSucc; -} - - -//Vector buffer for variable length data - -template -NONSHARABLE_CLASS(TVectorBuffer) : public TNodeBuffer -{ - public: - TVectorBuffer(); - TInt Append(const TDesC8& aData); - TPtrC8 Shift(); - TPtrC8 operator[](TInt aIndex) const; - TInt Size() const; - private: - TInt GetRoom(TInt aSize) const; - TInt Unreserved() const; - private: - TNode* iTop; - TNode* iBottom; - TInt iSize; - TUint8 iBuffer[C]; -}; - - template -TVectorBuffer::TVectorBuffer() : iSize(0) -{ - Mem::FillZ(iBuffer, C); - iTop = TNode::Empty(iBuffer); //these points to buffer - iBottom = TNode::Empty(iBuffer); -} - -template -TInt TVectorBuffer::Unreserved() const -{ - __ASSERT_DEBUG(iBottom < iBottom->Succ(), VECPANIC(KErrCorrupt)); - const TInt bytesbetween = - reinterpret_cast(iBottom->Succ()) - - reinterpret_cast(iTop); - const TInt topsize = sizeof(TNode); - if(bytesbetween > 0) //bytesbetween is room between bottom and top - { //therefore free room is subracted from free space - - const TInt room = C - bytesbetween - topsize; - return room; - } - if(bytesbetween == 0) - { - - if(Size() > 0) - return 0; - else - return C - topsize; - } - const TInt room = -bytesbetween - topsize; //free is space between pointers - return room; -} - -template -TInt TVectorBuffer::GetRoom(TInt aSize) const -{ - const TInt bytesnew = sizeof(TNode) + aSize; - const TInt room = Unreserved() - bytesnew; - return room; -} - - template -TInt TVectorBuffer::Append(const TDesC8& aData) -{ - const TInt len = aData.Length(); - if(GetRoom(len) < 0) - { - return KErrOverflow; - } - if(iBottom->Succ()->Ptr() - iBuffer > (C - (len + TInt(sizeof(TNode))))) - { - - TNode* p = TNode::Empty(iBuffer); - iBottom->Terminator(p); - iBottom = p; - return Append(aData); - } - - - iBottom = TNode::New(iBottom, aData); - - iSize += len; - return KErrNone; -} - - template -TPtrC8 TVectorBuffer::Shift() -{ - __ASSERT_ALWAYS(iTop->Succ() != NULL, VECPANIC(KErrUnderflow)); //can never pass-by bottom - TNode* node = iTop; - iTop = iTop->Succ(); - if(iTop > node) - { - iSize -= node->Size(); - return TPtrC8(node->Ptr(), node->Size()); - } - else - { - return Shift(); //this happens when buffer is terminated, and data lies in next - } -} - -template -TInt TVectorBuffer::Size() const -{ - return iSize; -} - -template -TPtrC8 TVectorBuffer::operator[](TInt aIndex) const -{ - TInt index = 0; - TNode* t = iTop->Size() > 0 ? iTop : iTop->Succ(); //eliminate terminator - while(index < aIndex) - { - TNode* nt = t->Succ(); - if(nt < t) - { - nt = nt->Succ(); - } - t = nt; - if(t->Size() > 0) - index++; - __ASSERT_ALWAYS(t->Succ() != NULL, VECPANIC(KErrUnderflow)); //can never pass-by bottom - } - return t->Ptr(); -} - -//Vector buffer for fixed length data - -template -NONSHARABLE_CLASS(TVector) : public TVectorBuffer -{ - public: - TVector(); - TInt Append(const T& aData); - const T& Shift(); - TInt Size() const; - const T& operator[](TInt aIndex) const; -}; - - template -TVector::TVector() : TVectorBuffer() -{ -} - - template -TInt TVector::Append(const T& aData) -{ - const TPckgC data(aData); - return TVectorBuffer::Append(data); -} - - template -const T& TVector::Shift() -{ - const TPtrC8 ptr = TVectorBuffer::Shift(); - return *(reinterpret_cast(ptr.Ptr())); -} - - -template -TInt TVector::Size() const -{ - return TVectorBuffer::Size() / sizeof(T); -} - -template -const T& TVector::operator[](TInt aIndex) const -{ - const TPtrC8 ptr = TVectorBuffer::operator[](aIndex); - return *(reinterpret_cast(ptr.Ptr())); -} - -#endif - - diff --git a/symbian/include/internal/epoc_sdl.h b/symbian/include/internal/epoc_sdl.h index 82bd3ef..e01aeee 100644 --- a/symbian/include/internal/epoc_sdl.h +++ b/symbian/include/internal/epoc_sdl.h @@ -42,7 +42,7 @@ NONSHARABLE_CLASS(MEventQueue) // virtual const TWsEvent& Top() = 0; virtual TBool HasData() = 0; // virtual TInt Shift() = 0; - virtual const TWsEvent& Shift() = 0; + virtual const TWsEvent Shift() = 0; virtual void Lock() = 0; virtual void Unlock() = 0; }; diff --git a/symbian/sdl.mmp b/symbian/sdl.mmp index 4a7268f..84431a7 100644 --- a/symbian/sdl.mmp +++ b/symbian/sdl.mmp @@ -26,7 +26,6 @@ SOURCE events/SDL_resize.c SOURCE file/SDL_rwops.c SOURCE main/symbian/SDL_env.cpp SOURCE main/symbian/SDL_main.cpp -SOURCE main/symbian/vectorbuffer.cpp SOURCE stdlib/SDL_getenv.c SOURCE stdlib/SDL_string.c SOURCE thread/generic/SDL_syscond.c @@ -60,6 +59,8 @@ SOURCE video/symbian/SDL_epocvideo.cpp SYSTEMINCLUDE \epoc32\include SYSTEMINCLUDE \epoc32\include\GLES SYSTEMINCLUDE \epoc32\include\stdapis +SYSTEMINCLUDE \epoc32\include\stdapis\stlport +SYSTEMINCLUDE \epoc32\include\stdapis\stlport\stl SYSTEMINCLUDE include SYSTEMINCLUDE ..\include -- 2.11.4.GIT