]> git.saurik.com Git - wxWidgets.git/blob - src/common/ipcbase.cpp
support for unicode font names
[wxWidgets.git] / src / common / ipcbase.cpp
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: ipcbase.cpp
3 // Purpose: IPC base classes
4 // Author: Julian Smart
5 // Modified by:
6 // Created: 04/01/98
7 // RCS-ID: $Id$
8 // Copyright: (c) Julian Smart
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
11
12 // For compilers that support precompilation, includes "wx.h".
13 #include "wx/wxprec.h"
14
15 #ifdef __BORLANDC__
16 #pragma hdrstop
17 #endif
18
19 #ifndef WX_PRECOMP
20 #include "wx/defs.h"
21 #endif
22
23 #include "wx/ipcbase.h"
24
25 IMPLEMENT_CLASS(wxServerBase, wxObject)
26 IMPLEMENT_CLASS(wxClientBase, wxObject)
27 IMPLEMENT_CLASS(wxConnectionBase, wxObject)
28
29 wxConnectionBase::wxConnectionBase(wxChar *buffer, int bytes)
30 : m_connected(true),
31 m_buffer(buffer),
32 m_buffersize(bytes),
33 m_deletebufferwhendone(false)
34 {
35 if ( buffer == (wxChar *)NULL )
36 { // behave like next constructor
37 m_buffersize = 0;
38 m_deletebufferwhendone = true;
39 }
40 }
41
42 wxConnectionBase::wxConnectionBase()
43 : m_connected(true),
44 m_buffer(NULL),
45 m_buffersize(0),
46 m_deletebufferwhendone(true)
47 {
48 }
49
50 wxConnectionBase::wxConnectionBase(const wxConnectionBase& copy)
51 : wxObject(),
52 m_connected(copy.m_connected),
53 m_buffer(copy.m_buffer),
54 m_buffersize(copy.m_buffersize),
55 m_deletebufferwhendone(false)
56
57 {
58 // copy constructor would require ref-counted pointer to buffer
59 wxFAIL_MSG( _T("Copy constructor of wxConnectionBase not implemented") );
60 }
61
62
63 wxConnectionBase::~wxConnectionBase(void)
64 {
65 if ( m_deletebufferwhendone && m_buffer )
66 delete m_buffer;
67 }
68
69 wxChar *wxConnectionBase::GetBufferAtLeast( size_t bytes )
70 {
71 if ( m_buffersize >= bytes )
72 return m_buffer;
73 else
74 { // need to resize buffer
75 if ( m_deletebufferwhendone )
76 { // we're in charge of buffer, increase it
77 if ( m_buffer )
78 delete m_buffer;
79 // the argument specifies **byte size**, but m_buffer is of type
80 // wxChar. Under unicode: sizeof(wxChar) > 1, so the buffer size is
81 // bytes / sizeof(wxChar) rounded upwards.
82 m_buffer = new wxChar[(bytes + sizeof(wxChar) - 1) / sizeof(wxChar)];
83 m_buffersize = bytes;
84 return m_buffer;
85 } // user-supplied buffer, fail
86 else
87 return NULL;
88 }
89 }
90