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
This commit is contained in:
Stefano Ceccherini
2006-01-04 09:49:47 +00:00
parent ebc8a403e5
commit 9c0c899e7d
4 changed files with 39 additions and 21 deletions
+9 -10
View File
@@ -747,12 +747,9 @@ ServerApp::_DispatchMessage(int32 code, BPrivate::LinkReceiver& link)
ServerPicture *cloned = NULL; ServerPicture *cloned = NULL;
if (original != NULL) if (original != NULL)
cloned = CreatePicture(); cloned = CreatePicture(original);
if (cloned != NULL) { 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.StartMessage(B_OK);
fLink.Attach<int32>(cloned->Token()); fLink.Attach<int32>(cloned->Token());
} else } else
@@ -2567,14 +2564,16 @@ ServerApp::CountPictures() const
ServerPicture * ServerPicture *
ServerApp::CreatePicture(int32 *token) ServerApp::CreatePicture(const ServerPicture *original)
{ {
ServerPicture *picture = new (nothrow) ServerPicture(); ServerPicture *picture;
if (picture != NULL) { if (original != NULL)
picture = new (nothrow) ServerPicture(*original);
else
picture = new (nothrow) ServerPicture();
if (picture != NULL)
fPictureList.AddItem(picture); fPictureList.AddItem(picture);
if (token != NULL)
*token = picture->Token();
}
return picture; return picture;
} }
+1 -1
View File
@@ -72,7 +72,7 @@ class ServerApp : public MessageLooper {
ServerBitmap *FindBitmap(int32 token) const; ServerBitmap *FindBitmap(int32 token) const;
int32 CountPictures() const; int32 CountPictures() const;
ServerPicture *CreatePicture(int32 *token = NULL); ServerPicture *CreatePicture(const ServerPicture *original = NULL);
ServerPicture *FindPicture(const int32 &token) const; ServerPicture *FindPicture(const int32 &token) const;
bool DeletePicture(const int32 &token); bool DeletePicture(const int32 &token);
+14 -2
View File
@@ -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() ServerPicture::~ServerPicture()
{ {
} }
@@ -470,7 +480,7 @@ void
ServerPicture::BeginOp(int16 op) ServerPicture::BeginOp(int16 op)
{ {
int32 size = 0; int32 size = 0;
fStack.AddItem((void *)fData.Position()); fStack.push(fData.Position());
fData.Write(&op, sizeof(op)); fData.Write(&op, sizeof(op));
fData.Write(&size, sizeof(size)); fData.Write(&size, sizeof(size));
} }
@@ -480,7 +490,9 @@ void
ServerPicture::EndOp() ServerPicture::EndOp()
{ {
off_t curPos = fData.Position(); 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; size_t size = curPos - stackPos - 6;
fData.Seek(stackPos + 2, SEEK_SET); fData.Seek(stackPos + 2, SEEK_SET);
+15 -8
View File
@@ -6,14 +6,15 @@
#include <Region.h> #include <Region.h>
#include <DataIO.h> #include <DataIO.h>
#include <InterfaceDefs.h> #include <InterfaceDefs.h>
#include <List.h>
#include <stack>
using std::stack;
class ServerApp;
class ViewLayer; class ViewLayer;
class ServerPicture { class ServerPicture {
public: public:
ServerPicture();
virtual ~ServerPicture();
int32 Token() { return fToken; } int32 Token() { return fToken; }
void BeginOp(int16 op); void BeginOp(int16 op);
@@ -40,13 +41,19 @@ virtual ~ServerPicture();
void Play(ViewLayer *view); void Play(ViewLayer *view);
const void *Data() { return fData.Buffer(); } const void *Data() const { return fData.Buffer(); }
int32 DataLength() { return fData.BufferLength(); } int32 DataLength() const { return fData.BufferLength(); }
private: private:
friend class ServerApp;
ServerPicture();
ServerPicture(const ServerPicture &);
~ServerPicture();
int32 fToken; int32 fToken;
BMallocIO fData; BMallocIO fData;
BList fStack; stack<off_t> fStack;
// DrawState *fState; // DrawState *fState;
}; };