~ubuntu-branches/ubuntu/hardy/codeblocks/hardy-backports

« back to all changes in this revision

Viewing changes to src/plugins/contrib/wxSmithContribItems/wxthings/wxthings/include/wx/things/optvalue.h

  • Committer: Bazaar Package Importer
  • Author(s): Michael Casadevall
  • Date: 2008-07-17 04:39:23 UTC
  • Revision ID: james.westby@ubuntu.com-20080717043923-gmsy5cwkdjswghkm
Tags: upstream-8.02
ImportĀ upstreamĀ versionĀ 8.02

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/////////////////////////////////////////////////////////////////////////////
 
2
// Name:        optvalue.h
 
3
// Purpose:     An string option & value pair class
 
4
// Author:      John Labenski
 
5
// Created:     07/01/02
 
6
// Copyright:   John Labenski, 2002
 
7
// License:     wxWidgets v2
 
8
/////////////////////////////////////////////////////////////////////////////
 
9
 
 
10
#ifndef __WXOPTIONVALUE_H__
 
11
#define __WXOPTIONVALUE_H__
 
12
 
 
13
#if defined(__GNUG__) && !defined(NO_GCC_PRAGMA)
 
14
    #pragma interface "optvalue.h"
 
15
#endif
 
16
 
 
17
#include "wx/things/thingdef.h"
 
18
class WXDLLIMPEXP_THINGS wxOptionValue;
 
19
 
 
20
#include "wx/dynarray.h"
 
21
WX_DECLARE_OBJARRAY_WITH_DECL(wxOptionValue, wxArrayOptionValue, class WXDLLIMPEXP_THINGS);
 
22
 
 
23
//----------------------------------------------------------------------------
 
24
// Global wxString utilities
 
25
//----------------------------------------------------------------------------
 
26
 
 
27
//extern wxArrayString wxStringToWords( const wxString &string );
 
28
 
 
29
//----------------------------------------------------------------------------
 
30
// wxOptionValue - a ref counted wxString key, wxString value container
 
31
//----------------------------------------------------------------------------
 
32
 
 
33
class WXDLLIMPEXP_THINGS wxOptionValue : public wxObject
 
34
{
 
35
public:
 
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); }
 
39
 
 
40
    // (Re)Create as an empty container
 
41
    bool Create();
 
42
    // Ref the other wxOptionValue
 
43
    bool Create( const wxOptionValue &optValue );
 
44
    // Create from a string with this structure
 
45
    //   [type]  # optional
 
46
    //   key = value
 
47
    bool Create( const wxString &string );
 
48
 
 
49
    // Make a true copy of the source wxOptionValue (not refed)
 
50
    bool Copy( const wxOptionValue &source );
 
51
 
 
52
    // Is there any ref data
 
53
    bool Ok() const;
 
54
    // Unref the data
 
55
    void Destroy();
 
56
 
 
57
    //-------------------------------------------------------------------------
 
58
 
 
59
    // Get/Set the "type", which can mean whatever you want
 
60
    wxString GetType() const;
 
61
    void SetType( const wxString &type );
 
62
 
 
63
    //-------------------------------------------------------------------------
 
64
 
 
65
    // does this have a wxOptionValueArray filled with children
 
66
    size_t GetChildrenCount() const;
 
67
    wxArrayOptionValue *GetChildren() const;
 
68
 
 
69
    bool AddChild( const wxOptionValue& child );
 
70
    void DeleteChildren();
 
71
 
 
72
    //-------------------------------------------------------------------------
 
73
 
 
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;
 
82
 
 
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 );
 
90
 
 
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); }
 
95
 
 
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, ...);
 
98
 
 
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); }
 
106
 
 
107
    wxString GetOption(const wxString& name) const; // returns wxEmptyString if not found
 
108
    int GetOptionInt(const wxString& name) const;   // returns 0 if not found
 
109
 
 
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;
 
115
 
 
116
    // sscanf style for numeric values GetOption("Name", "%d %f", &n_int, &n_float)
 
117
    int GetOption(const wxString& name, const wxChar* format, ...) const;
 
118
 
 
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;
 
123
 
 
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;
 
135
 
 
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;
 
139
 
 
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;
 
144
 
 
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;
 
153
 
 
154
    //-------------------------------------------------------------------------
 
155
    // Operators
 
156
 
 
157
    wxOptionValue& operator = (const wxOptionValue& optValue)
 
158
    {
 
159
        if ( (*this) != optValue ) wxObject::Ref(optValue);
 
160
        return *this;
 
161
    }
 
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; }
 
166
 
 
167
private :
 
168
    // ref counting code
 
169
    virtual wxObjectRefData *CreateRefData() const;
 
170
    virtual wxObjectRefData *CloneRefData(const wxObjectRefData *data) const;
 
171
 
 
172
    DECLARE_DYNAMIC_CLASS(wxOptionValue);
 
173
};
 
174
 
 
175
#endif // __WXOPTIONVALUE_H__