From 9c0c899e7d5d797fa8cceafe4016ad6c249425d6 Mon Sep 17 00:00:00 2001 From: Stefano Ceccherini Date: Wed, 4 Jan 2006 09:49:47 +0000 Subject: [PATCH] Added a copy constructor to ServerPicture. ServerPicture's constructors are private now, and can be called only from ServerApp (friend). Changed BList to a stl::stack which is better suited as a stack... Changed ServerApp::CreatePicture() to accept a picture to clone, instead of passing back a token which was never used anyway. git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@15840 a95241bf-73f2-0310-859d-f6bbb57e9c96 --- src/servers/app/ServerApp.cpp | 19 +++++++++---------- src/servers/app/ServerApp.h | 2 +- src/servers/app/ServerPicture.cpp | 16 ++++++++++++++-- src/servers/app/ServerPicture.h | 23 +++++++++++++++-------- 4 files changed, 39 insertions(+), 21 deletions(-) diff --git a/src/servers/app/ServerApp.cpp b/src/servers/app/ServerApp.cpp index c3aac5d643..53ee452f10 100644 --- a/src/servers/app/ServerApp.cpp +++ b/src/servers/app/ServerApp.cpp @@ -747,12 +747,9 @@ ServerApp::_DispatchMessage(int32 code, BPrivate::LinkReceiver& link) ServerPicture *cloned = NULL; if (original != NULL) - cloned = CreatePicture(); + cloned = CreatePicture(original); if (cloned != NULL) { - // TODO: I'm not sure that this does a plain copy. - // Check, and, in case, put the stuff in Data() directly - cloned->AddData(original->Data(), original->DataLength()); fLink.StartMessage(B_OK); fLink.Attach(cloned->Token()); } else @@ -2567,14 +2564,16 @@ ServerApp::CountPictures() const ServerPicture * -ServerApp::CreatePicture(int32 *token) +ServerApp::CreatePicture(const ServerPicture *original) { - ServerPicture *picture = new (nothrow) ServerPicture(); - if (picture != NULL) { + ServerPicture *picture; + if (original != NULL) + picture = new (nothrow) ServerPicture(*original); + else + picture = new (nothrow) ServerPicture(); + + if (picture != NULL) fPictureList.AddItem(picture); - if (token != NULL) - *token = picture->Token(); - } return picture; } diff --git a/src/servers/app/ServerApp.h b/src/servers/app/ServerApp.h index 21dbc13711..39bf0e5433 100644 --- a/src/servers/app/ServerApp.h +++ b/src/servers/app/ServerApp.h @@ -72,7 +72,7 @@ class ServerApp : public MessageLooper { ServerBitmap *FindBitmap(int32 token) const; int32 CountPictures() const; - ServerPicture *CreatePicture(int32 *token = NULL); + ServerPicture *CreatePicture(const ServerPicture *original = NULL); ServerPicture *FindPicture(const int32 &token) const; bool DeletePicture(const int32 &token); diff --git a/src/servers/app/ServerPicture.cpp b/src/servers/app/ServerPicture.cpp index 5128e5437a..8863f7c5d0 100644 --- a/src/servers/app/ServerPicture.cpp +++ b/src/servers/app/ServerPicture.cpp @@ -461,6 +461,16 @@ ServerPicture::ServerPicture() } +ServerPicture::ServerPicture(const ServerPicture &picture) + : + fStack(picture.fStack) +{ + fToken = gTokenSpace.NewToken(kPictureToken, this); + + AddData(picture.Data(), picture.DataLength()); +} + + ServerPicture::~ServerPicture() { } @@ -470,7 +480,7 @@ void ServerPicture::BeginOp(int16 op) { int32 size = 0; - fStack.AddItem((void *)fData.Position()); + fStack.push(fData.Position()); fData.Write(&op, sizeof(op)); fData.Write(&size, sizeof(size)); } @@ -480,7 +490,9 @@ void ServerPicture::EndOp() { off_t curPos = fData.Position(); - off_t stackPos = (off_t)fStack.RemoveItem(fStack.CountItems() - 1); + off_t stackPos = fStack.top(); + fStack.pop(); + size_t size = curPos - stackPos - 6; fData.Seek(stackPos + 2, SEEK_SET); diff --git a/src/servers/app/ServerPicture.h b/src/servers/app/ServerPicture.h index 47f58c81bb..da407a7b94 100644 --- a/src/servers/app/ServerPicture.h +++ b/src/servers/app/ServerPicture.h @@ -6,14 +6,15 @@ #include #include #include -#include +#include + +using std::stack; + +class ServerApp; class ViewLayer; class ServerPicture { -public: - ServerPicture(); -virtual ~ServerPicture(); - +public: int32 Token() { return fToken; } void BeginOp(int16 op); @@ -40,13 +41,19 @@ virtual ~ServerPicture(); void Play(ViewLayer *view); - const void *Data() { return fData.Buffer(); } - int32 DataLength() { return fData.BufferLength(); } + const void *Data() const { return fData.Buffer(); } + int32 DataLength() const { return fData.BufferLength(); } private: +friend class ServerApp; + + ServerPicture(); + ServerPicture(const ServerPicture &); + ~ServerPicture(); + int32 fToken; BMallocIO fData; - BList fStack; + stack fStack; // DrawState *fState; };