1
/////////////////////////////////////////////////////////////////////////////
3
// Purpose: An string option & value pair class
4
// Author: John Labenski
6
// Copyright: John Labenski, 2002
7
// License: wxWidgets v2
8
/////////////////////////////////////////////////////////////////////////////
10
#ifndef __WXOPTIONVALUE_H__
11
#define __WXOPTIONVALUE_H__
13
#if defined(__GNUG__) && !defined(NO_GCC_PRAGMA)
14
#pragma interface "optvalue.h"
17
#include "wx/things/thingdef.h"
18
class WXDLLIMPEXP_THINGS wxOptionValue;
20
#include "wx/dynarray.h"
21
WX_DECLARE_OBJARRAY_WITH_DECL(wxOptionValue, wxArrayOptionValue, class WXDLLIMPEXP_THINGS);
23
//----------------------------------------------------------------------------
24
// Global wxString utilities
25
//----------------------------------------------------------------------------
27
//extern wxArrayString wxStringToWords( const wxString &string );
29
//----------------------------------------------------------------------------
30
// wxOptionValue - a ref counted wxString key, wxString value container
31
//----------------------------------------------------------------------------
33
class WXDLLIMPEXP_THINGS wxOptionValue : public wxObject
36
wxOptionValue(bool create = true) : wxObject() { if (create) Create(); }
37
wxOptionValue( const wxOptionValue &optValue ) : wxObject() { Create(optValue); }
38
wxOptionValue( const wxString &str ) : wxObject() { Create(str); }
40
// (Re)Create as an empty container
42
// Ref the other wxOptionValue
43
bool Create( const wxOptionValue &optValue );
44
// Create from a string with this structure
47
bool Create( const wxString &string );
49
// Make a true copy of the source wxOptionValue (not refed)
50
bool Copy( const wxOptionValue &source );
52
// Is there any ref data
57
//-------------------------------------------------------------------------
59
// Get/Set the "type", which can mean whatever you want
60
wxString GetType() const;
61
void SetType( const wxString &type );
63
//-------------------------------------------------------------------------
65
// does this have a wxOptionValueArray filled with children
66
size_t GetChildrenCount() const;
67
wxArrayOptionValue *GetChildren() const;
69
bool AddChild( const wxOptionValue& child );
70
void DeleteChildren();
72
//-------------------------------------------------------------------------
74
// Get the number of different option name/value combinations
75
size_t GetOptionCount() const;
76
// Access the arrays themselves
77
wxArrayString GetOptionNames() const;
78
wxArrayString GetOptionValues() const;
79
// Get a specific option name or value
80
wxString GetOptionName( size_t n ) const;
81
wxString GetOptionValue( size_t n ) const;
83
// returns the index of the option >= 0 or -1 (wxNOT_FOUND) if not found
84
int HasOption(const wxString &name) const;
85
// Search through the option names for this part returning the first match
86
int FindOption(const wxString &part_of_option_name) const;
87
// delete this option, returns sucess
88
bool DeleteOption(const wxString &name);
89
bool DeleteOption( size_t n );
91
// Option functions (arbitrary name/value mapping)
92
void SetOption(const wxString& name, const wxString& value, bool force=true );
93
void SetOption(const wxString& name, int value, bool force=true ) { SetOption(name, wxString::Format(wxT("%d"), value), force); }
94
void SetOption(const wxString& name, double value, bool force=true ) { SetOption(name, wxString::Format(wxT("%lf"), value), force); }
96
// printf style for numeric values SetOption("Name", true, "%d %f", 2, 2.5)
97
void SetOption(const wxString& name, bool update, const wxChar* format, ...);
99
void SetOption(const wxString& name, int v1, int v2, int v3, bool force=true ) { SetOption(name, wxString::Format(wxT("%d %d %d"), v1, v2, v3), force); }
100
void SetOption(const wxString& name, double v1, double v2, double v3, bool force=true ) { SetOption(name, wxString::Format(wxT("%lf %lf %lf"), v1, v2, v3), force); }
101
void SetOption(const wxString& name, int *v, int count, bool force=true ) { if(v) { wxString s; for (int i=0; i<count; i++) s += wxString::Format(wxT("%d "), v[i]); SetOption(name, s, force); }}
102
void SetOption(const wxString& name, float *v, int count, bool force=true ) { if(v) { wxString s; for (int i=0; i<count; i++) s += wxString::Format(wxT("%f "), v[i]); SetOption(name, s, force); }}
103
void SetOption(const wxString& name, const wxPoint &value, bool force=true ) { SetOption(name, wxString::Format(wxT("%d %d"), value.x, value.y), force); }
104
void SetOption(const wxString& name, const wxSize &value, bool force=true ) { SetOption(name, wxString::Format(wxT("%d %d"), value.x, value.y), force); }
105
void SetOption(const wxString& name, const wxRect &value, bool force=true ) { SetOption(name, wxString::Format(wxT("%d %d %d %d"), value.x, value.y, value.width, value.height), force); }
107
wxString GetOption(const wxString& name) const; // returns wxEmptyString if not found
108
int GetOptionInt(const wxString& name) const; // returns 0 if not found
110
// These return true on sucess otherwise the value is not modified
111
bool GetOption(const wxString& name, wxString &value ) const;
112
bool GetOption(const wxString& name, int *value ) const;
113
bool GetOption(const wxString& name, float *value ) const;
114
bool GetOption(const wxString& name, double *value ) const;
116
// sscanf style for numeric values GetOption("Name", "%d %f", &n_int, &n_float)
117
int GetOption(const wxString& name, const wxChar* format, ...) const;
119
// Get int values filling a wxArrayInt, if count == -1 get all, else count.
120
// delims are the possible separators between values.
121
int GetOption(const wxString& name, wxArrayInt &values, int count = -1,
122
const wxString& delims = wxT(" ,\t\r\n")) const;
124
// Get values and fill arrays up to count items
125
bool GetOption(const wxString& name, unsigned char *value, int count,
126
const wxString& delims = wxT(" ,\t\r\n")) const;
127
bool GetOption(const wxString& name, int *value, int count,
128
const wxString& delims = wxT(" ,\t\r\n")) const;
129
bool GetOption(const wxString& name, long *value, int count,
130
const wxString& delims = wxT(" ,\t\r\n")) const;
131
bool GetOption(const wxString& name, float *value, int count,
132
const wxString& delims = wxT(" ,\t\r\n")) const;
133
bool GetOption(const wxString& name, double *value, int count,
134
const wxString& delims = wxT(" ,\t\r\n")) const;
136
// Convience function to easily get common values
137
bool GetOption(const wxString& name, int *v1, int *v2,
138
const wxString& delims = wxT(" ,\t\r\n")) const;
140
bool GetOption(const wxString& name, int *v1, int *v2, int *v3,
141
const wxString& delims = wxT(" ,\t\r\n")) const;
142
bool GetOption(const wxString& name, float *v1, float *v2, float *v3,
143
const wxString& delims = wxT(" ,\t\r\n")) const;
145
bool GetOption(const wxString& name, wxPoint &value,
146
const wxString& delims = wxT(" ,\t\r\n")) const
147
{ return GetOption(name, &value.x, &value.y, delims); }
148
bool GetOption(const wxString& name, wxSize &value,
149
const wxString& delims = wxT(" ,\t\r\n")) const
150
{ return GetOption(name, &value.x, &value.y, delims); }
151
bool GetOption(const wxString& name, wxRect &value,
152
const wxString& delims = wxT(" ,\t\r\n")) const;
154
//-------------------------------------------------------------------------
157
wxOptionValue& operator = (const wxOptionValue& optValue)
159
if ( (*this) != optValue ) wxObject::Ref(optValue);
162
bool operator == (const wxOptionValue& optValue) const
163
{ return m_refData == optValue.m_refData; }
164
bool operator != (const wxOptionValue& optValue) const
165
{ return m_refData != optValue.m_refData; }
169
virtual wxObjectRefData *CreateRefData() const;
170
virtual wxObjectRefData *CloneRefData(const wxObjectRefData *data) const;
172
DECLARE_DYNAMIC_CLASS(wxOptionValue);
175
#endif // __WXOPTIONVALUE_H__