]> git.saurik.com Git - wxWidgets.git/blame - src/common/xti.cpp
compilation fix for !PCH
[wxWidgets.git] / src / common / xti.cpp
CommitLineData
a095505c
SC
1/////////////////////////////////////////////////////////////////////////////
2// Name: src/common/xti.cpp
3// Purpose: runtime metadata information (extended class info
4// Author: Stefan Csomor
5// Modified by:
6// Created: 27/07/03
7// RCS-ID: $Id$
8// Copyright: (c) 1997 Julian Smart
9// (c) 2003 Stefan Csomor
10// Licence: wxWindows licence
11/////////////////////////////////////////////////////////////////////////////
12
13#ifdef __GNUG__
14#pragma implementation "xti.h"
15#endif
16
17// For compilers that support precompilation, includes "wx.h".
18#include "wx/wxprec.h"
19
20#ifdef __BORLANDC__
21#pragma hdrstop
22#endif
23
24#ifndef WX_PRECOMP
25 #include "wx/hash.h"
26 #include "wx/object.h"
27#endif
28
29#include "wx/xml/xml.h"
30#include "wx/tokenzr.h"
31
32#include <string.h>
33
30bfc425 34#if wxUSE_EXTENDED_RTTI
a095505c
SC
35
36// ----------------------------------------------------------------------------
37// Enum Support
38// ----------------------------------------------------------------------------
39
40wxEnumData::wxEnumData( wxEnumMemberData* data )
41{
42 m_members = data ;
43 for ( m_count = 0; m_members[m_count].m_name ; m_count++)
44 {} ;
45}
46
47bool wxEnumData::HasEnumMemberValue(const wxChar *name, int *value)
48{
49 int i;
50 for (i = 0; m_members[i].m_name ; i++ )
51 {
52 if (!strcmp(name, m_members[i].m_name))
53 {
54 if ( value )
55 *value = m_members[i].m_value;
56 return true ;
57 }
58 }
59 return false ;
60}
61
62int wxEnumData::GetEnumMemberValue(const wxChar *name)
63{
64 int i;
65 for (i = 0; m_members[i].m_name ; i++ )
66 {
67 if (!strcmp(name, m_members[i].m_name))
68 {
69 return m_members[i].m_value;
70 }
71 }
72 return 0 ;
73}
74
75const wxChar *wxEnumData::GetEnumMemberName(int value)
76{
77 int i;
78 for (i = 0; m_members[i].m_name ; i++)
79 if (value == m_members[i].m_value)
80 return m_members[i].m_name;
81
82 return wxT("") ;
83}
84
85int wxEnumData::GetEnumMemberValueByIndex( int idx )
86{
87 // we should cache the count in order to avoid out-of-bounds errors
88 return m_members[idx].m_value ;
89}
90
91const char * wxEnumData::GetEnumMemberNameByIndex( int idx )
92{
93 // we should cache the count in order to avoid out-of-bounds errors
94 return m_members[idx].m_name ;
95}
96
97// ----------------------------------------------------------------------------
98// Type Information
99// ----------------------------------------------------------------------------
100
101const wxTypeInfo* wxGetTypeInfo( void * )
102{
103 static wxBuiltInTypeInfo s_typeInfo( wxT_VOID ) ;
104 return &s_typeInfo ;
105}
106
107const wxTypeInfo* wxGetTypeInfo( bool * )
108{
109 static wxBuiltInTypeInfo s_typeInfo( wxT_BOOL ) ;
110 return &s_typeInfo ;
111}
112
113const wxTypeInfo* wxGetTypeInfo( char * )
114{
115 static wxBuiltInTypeInfo s_typeInfo( wxT_CHAR ) ;
116 return &s_typeInfo ;
117}
118
119const wxTypeInfo* wxGetTypeInfo( unsigned char * )
120{
121 static wxBuiltInTypeInfo s_typeInfo( wxT_UCHAR ) ;
122 return &s_typeInfo ;
123}
124
125const wxTypeInfo* wxGetTypeInfo( int * )
126{
127 static wxBuiltInTypeInfo s_typeInfo( wxT_CHAR ) ;
128 return &s_typeInfo ;
129}
130
131const wxTypeInfo* wxGetTypeInfo( unsigned int * )
132{
133 static wxBuiltInTypeInfo s_typeInfo( wxT_UCHAR ) ;
134 return &s_typeInfo ;
135}
136
137const wxTypeInfo* wxGetTypeInfo( long * )
138{
139 static wxBuiltInTypeInfo s_typeInfo( wxT_CHAR ) ;
140 return &s_typeInfo ;
141}
142
143const wxTypeInfo* wxGetTypeInfo( unsigned long * )
144{
145 static wxBuiltInTypeInfo s_typeInfo( wxT_UCHAR ) ;
146 return &s_typeInfo ;
147}
148
149const wxTypeInfo* wxGetTypeInfo( float * )
150{
151 static wxBuiltInTypeInfo s_typeInfo( wxT_FLOAT ) ;
152 return &s_typeInfo ;
153}
154
155const wxTypeInfo* wxGetTypeInfo( double * )
156{
157 static wxBuiltInTypeInfo s_typeInfo( wxT_DOUBLE ) ;
158 return &s_typeInfo ;
159}
160
161const wxTypeInfo* wxGetTypeInfo( wxString * )
162{
163 static wxBuiltInTypeInfo s_typeInfo( wxT_STRING ) ;
164 return &s_typeInfo ;
165}
166
167// this is a compiler induced specialization which is never used anywhere
168// const char * should never be active
169
170const wxTypeInfo* wxGetTypeInfo( char const ** )
171{
172 assert(0) ;
173 static wxBuiltInTypeInfo s_typeInfo( wxT_VOID ) ;
174 return &s_typeInfo ;
175}
176
177void wxStringReadValue(const wxString & , const char* & )
178{
179 assert(0) ;
180}
181
182void wxStringWriteValue(wxString & , char const * const & )
183{
184 assert(0) ;
185}
186
187
188// ----------------------------------------------------------------------------
189// value streaming
190// ----------------------------------------------------------------------------
191
192// convenience function (avoids including xml headers in users code)
193
194void wxXmlAddContentToNode( wxXmlNode* node , const wxString& data )
195{
196 node->AddChild(new wxXmlNode(wxXML_TEXT_NODE, "value", data ) );
197}
198
199wxString wxXmlGetContentFromNode( wxXmlNode *node )
200{
201 return node->GetChildren()->GetContent() ;
202}
203
204// streamer specializations
205
206// TODO for all built-in types
207
208// long
209
210void wxStringReadValue(const wxString &s , long &data )
211{
212 wxSscanf(s, _T("%ld"), &data ) ;
213}
214
215void wxStringWriteValue(wxString &s , const long &data )
216{
217 s = wxString::Format("%ld", data ) ;
218}
219
220// long
221
222void wxStringReadValue(const wxString &s , int &data )
223{
224 wxSscanf(s, _T("%d"), &data ) ;
225}
226
227void wxStringWriteValue(wxString &s , const int &data )
228{
229 s = wxString::Format("%d", data ) ;
230}
231
232// wxString
233
234void wxStringReadValue(const wxString &s , wxString &data )
235{
236 data = s ;
237}
238
239void wxStringWriteValue(wxString &s , const wxString &data )
240{
241 s = data ;
242}
243
244/*
245 Custom Data Streaming / Type Infos
246 we will have to add this for all wx non object types, but it is also an example
247 for custom data structures
248*/
249
250// wxPoint
251
252void wxStringReadValue(const wxString &s , wxPoint &data )
253{
254 wxSscanf(s, _T("%d,%d"), &data.x , &data.y ) ;
255}
256
257void wxStringWriteValue(wxString &s , const wxPoint &data )
258{
259 s = wxString::Format("%d,%d", data.x , data.y ) ;
260}
261
262WX_CUSTOM_TYPE_INFO(wxPoint)
263
264// removing header dependancy on string tokenizer
265
266void wxSetStringToArray( const wxString &s , wxArrayString &array )
267{
268 wxStringTokenizer tokenizer(s, wxT("| \t\n"), wxTOKEN_STRTOK);
269 wxString flag;
270 array.Clear() ;
271 while (tokenizer.HasMoreTokens())
272 {
273 array.Add(tokenizer.GetNextToken()) ;
274 }
275}
276
277// ----------------------------------------------------------------------------
278// wxClassInfo
279// ----------------------------------------------------------------------------
280
281
282void wxClassInfo::Register(const char *WXUNUSED(name), wxClassInfo *WXUNUSED(info))
283{
284 /*
285 if (!ExtendedTypeMap)
286 ExtendedTypeMap = new ClassMap;
287 (*ExtendedTypeMap)[string(Name)] = Info;
288 */
289}
290
291void wxClassInfo::Unregister(const char *WXUNUSED(name))
292{
293 /*
294 assert(ExtendedTypeMap);
295 ExtendedTypeMap->erase(Name);
296 */
297}
298
299const wxPropertyAccessor *wxClassInfo::FindAccessor(const char *PropertyName)
300{
301 const wxPropertyInfo* info = FindPropInfo( PropertyName ) ;
302
303 if ( info )
304 return info->GetAccessor() ;
305
306 return NULL ;
307}
308
309const wxPropertyInfo *wxClassInfo::FindPropInfo (const char *PropertyName) const
310{
311 const wxPropertyInfo* info = GetFirstProperty() ;
312
313 while( info )
314 {
315 if ( strcmp( info->GetName() , PropertyName ) == 0 )
316 return info ;
317 info = info->GetNext() ;
318 }
319
320 const wxClassInfo** parents = GetParents() ;
321 for ( int i = 0 ; parents[i] ; ++ i )
322 {
323 if ( ( info = parents[i]->FindPropInfo( PropertyName ) ) != NULL )
324 return info ;
325 }
326
327 return 0;
328}
329
330void wxClassInfo::SetProperty(wxObject *object, const char *propertyName, const wxxVariant &value)
331{
332 const wxPropertyAccessor *accessor;
333
334 accessor = FindAccessor(propertyName);
335 wxASSERT(accessor->HasSetter());
336 accessor->SetProperty( object , value ) ;
337}
338
339wxxVariant wxClassInfo::GetProperty(wxObject *object, const char *propertyName)
340{
341 const wxPropertyAccessor *accessor;
342
343 accessor = FindAccessor(propertyName);
344 wxASSERT(accessor->HasGetter());
345 return accessor->GetProperty(object);
346}
347
348/*
349VARIANT TO OBJECT
350*/
351
352wxObject* wxxVariant::GetAsObject() const
353{
354 const wxClassTypeInfo *ti = dynamic_cast<const wxClassTypeInfo*>( m_data->GetTypeInfo() ) ;
355 if ( ti )
356 return ti->GetClassInfo()->VariantToInstance(*this) ;
357 else
358 return NULL ;
359}
360
361
362#endif