/[pcsx2_0.9.7]/branch/r3113_0.9.7_beta/3rdparty/wxWidgets/src/msw/ole/uuid.cpp
ViewVC logotype

Annotation of /branch/r3113_0.9.7_beta/3rdparty/wxWidgets/src/msw/ole/uuid.cpp

Parent Directory Parent Directory | Revision Log Revision Log


Revision 32 - (hide annotations) (download)
Tue Sep 7 03:29:01 2010 UTC (9 years, 11 months ago) by william
File size: 4684 byte(s)
branching from upstream revision (http://pcsx2.googlecode.com/svn/trunk
): r3113 to
https://svn.netsolutions.dnsalias.com/websvn/ps2/pcsx2/pcsx2_0.9.7/branch/r3113_0.9.7_beta
1 william 31 ///////////////////////////////////////////////////////////////////////////////
2     // Name: src/msw/ole/uuid.cpp
3     // Purpose: implements Uuid class, see uuid.h for details
4     // Author: Vadim Zeitlin
5     // Modified by:
6     // Created: 12.09.96
7     // RCS-ID: $Id: uuid.cpp 55125 2008-08-18 20:04:58Z VZ $
8     // Copyright: (c) 1998 Vadim Zeitlin <zeitlin@dptmaths.ens-cachan.fr>
9     // Licence: wxWindows licence
10     ///////////////////////////////////////////////////////////////////////////////
11    
12     // ============================================================================
13     // Declarations
14     // ============================================================================
15    
16     // For compilers that support precompilation, includes "wx.h".
17     #include "wx/wxprec.h"
18    
19     #if defined(__BORLANDC__)
20     #pragma hdrstop
21     #endif
22    
23     #if wxUSE_OLE && ( wxUSE_DRAG_AND_DROP || (defined(__WXDEBUG__) && wxUSE_DATAOBJ) )
24    
25     #ifndef WX_PRECOMP
26     #include "wx/msw/wrapwin.h"
27     #endif
28    
29     #include <rpc.h> // UUID related functions
30    
31     #include "wx/msw/ole/uuid.h"
32    
33    
34    
35     // ============================================================================
36     // Implementation
37     // ============================================================================
38    
39     // length of UUID in C format
40     #define UUID_CSTRLEN 100 // real length is 66
41    
42     // copy ctor
43     Uuid::Uuid(const Uuid& uuid)
44     {
45     // bitwise copy Ok for UUIDs
46     m_uuid = uuid.m_uuid;
47    
48     // force the string to be allocated by RPC
49     // (we free it later with RpcStringFree)
50     #ifdef _UNICODE
51     UuidToString(&m_uuid, (unsigned short **)&m_pszUuid);
52     #else
53     UuidToString(&m_uuid, &m_pszUuid);
54     #endif
55    
56     // allocate new buffer
57     m_pszCForm = new wxChar[UUID_CSTRLEN];
58     // and fill it
59     memcpy(m_pszCForm, uuid.m_pszCForm, UUID_CSTRLEN*sizeof(wxChar));
60     }
61    
62     // assignment operator
63     Uuid& Uuid::operator=(const Uuid& uuid)
64     {
65     m_uuid = uuid.m_uuid;
66    
67     // force the string to be allocated by RPC
68     // (we free it later with RpcStringFree)
69     #ifdef _UNICODE
70     UuidToString(&m_uuid, (unsigned short **)&m_pszUuid);
71     #else
72     UuidToString(&m_uuid, &m_pszUuid);
73     #endif
74    
75     // allocate new buffer if not done yet
76     if ( !m_pszCForm )
77     m_pszCForm = new wxChar[UUID_CSTRLEN];
78    
79     // and fill it
80     memcpy(m_pszCForm, uuid.m_pszCForm, UUID_CSTRLEN*sizeof(wxChar));
81    
82     return *this;
83     }
84    
85     bool Uuid::operator==(const Uuid& uuid) const
86     {
87     // IsEqualGUID() returns BOOL and not bool so use an explicit comparison to
88     // avoid MSVC warnings about int->bool conversion
89     return IsEqualGUID(m_uuid, uuid.m_uuid) == TRUE;
90     }
91    
92     bool Uuid::operator!=(const Uuid& uuid) const
93     {
94     return !(*this == uuid);
95     }
96    
97     // dtor
98     Uuid::~Uuid()
99     {
100     // this string must be allocated by RPC!
101     // (otherwise you get a debug breakpoint deep inside RPC DLL)
102     if ( m_pszUuid )
103     #ifdef _UNICODE
104     RpcStringFree((unsigned short **)&m_pszUuid);
105     #else
106     RpcStringFree(&m_pszUuid);
107     #endif
108    
109     // perhaps we should just use a static buffer and not bother
110     // with new and delete?
111     if ( m_pszCForm )
112     delete [] m_pszCForm;
113     }
114    
115     // update string representation of new UUID
116     void Uuid::Set(const UUID &uuid)
117     {
118     m_uuid = uuid;
119    
120     // get string representation
121     #ifdef _UNICODE
122     UuidToString(&m_uuid, (unsigned short **)&m_pszUuid);
123     #else
124     UuidToString(&m_uuid, &m_pszUuid);
125     #endif
126    
127     // cache UUID in C format
128     UuidToCForm();
129     }
130    
131     // create a new UUID
132     void Uuid::Create()
133     {
134     UUID uuid;
135    
136     // can't fail
137     UuidCreate(&uuid);
138    
139     Set(uuid);
140     }
141    
142     // set the value
143     bool Uuid::Set(const wxChar *pc)
144     {
145     // get UUID from string
146     #ifdef _UNICODE
147     if ( UuidFromString((unsigned short *)pc, &m_uuid) != RPC_S_OK)
148     #else
149     if ( UuidFromString((wxUChar *)pc, &m_uuid) != RPC_S_OK)
150     #endif
151     // failed: probably invalid string
152     return false;
153    
154     // transform it back to string to normalize it
155     #ifdef _UNICODE
156     UuidToString(&m_uuid, (unsigned short **)&m_pszUuid);
157     #else
158     UuidToString(&m_uuid, &m_pszUuid);
159     #endif
160    
161     // update m_pszCForm
162     UuidToCForm();
163    
164     return true;
165     }
166    
167     // stores m_uuid in m_pszCForm in a format required by
168     // DEFINE_GUID macro: i.e. something like
169     // 0x7D8A2281L,0x4C61,0x11D0,0xBA,0xBD,0x00,0x00,0xC0,0x18,0xBA,0x27
170     // m_pszUuid is of the form (no, it's not quite the same UUID :-)
171     // 6aadc650-67b0-11d0-bac8-0000c018ba27
172     void Uuid::UuidToCForm()
173     {
174     if ( m_pszCForm == NULL )
175     m_pszCForm = new wxChar[UUID_CSTRLEN];
176    
177     wsprintf(m_pszCForm, wxT("0x%8.8X,0x%4.4X,0x%4.4X,0x%2.2X,0x2.2%X,0x2.2%X,0x2.2%X,0x2.2%X,0x2.2%X,0x2.2%X,0x2.2%X"),
178     m_uuid.Data1, m_uuid.Data2, m_uuid.Data3,
179     m_uuid.Data4[0], m_uuid.Data4[1], m_uuid.Data4[2], m_uuid.Data4[3],
180     m_uuid.Data4[4], m_uuid.Data4[5], m_uuid.Data4[6], m_uuid.Data4[7]);
181     }
182    
183     #endif
184     // wxUSE_DRAG_AND_DROP

  ViewVC Help
Powered by ViewVC 1.1.22