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

« back to all changes in this revision

Viewing changes to src/plugins/contrib/wxSmith/properties/wxspropertystream.cpp

  • 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
* This file is part of wxSmith plugin for Code::Blocks Studio
 
3
* Copyright (C) 2006-2007  Bartlomiej Swiecki
 
4
*
 
5
* wxSmith is free software; you can redistribute it and/or modify
 
6
* it under the terms of the GNU General Public License as published by
 
7
* the Free Software Foundation; either version 3 of the License, or
 
8
* (at your option) any later version.
 
9
*
 
10
* wxSmith is distributed in the hope that it will be useful,
 
11
* but WITHOUT ANY WARRANTY; without even the implied warranty of
 
12
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
 
13
* GNU General Public License for more details.
 
14
*
 
15
* You should have received a copy of the GNU General Public License
 
16
* along with wxSmith. If not, see <http://www.gnu.org/licenses/>.
 
17
*
 
18
* $Revision: 4850 $
 
19
* $Id: wxspropertystream.cpp 4850 2008-01-29 21:45:49Z byo $
 
20
* $HeadURL: svn://svn.berlios.de/codeblocks/tags/8.02/src/plugins/contrib/wxSmith/properties/wxspropertystream.cpp $
 
21
*/
 
22
 
 
23
#include "wxspropertystream.h"
 
24
 
 
25
bool wxsPropertyStream::GetChar(const wxString &Name, wxChar& Value, wxChar Default)
 
26
{
 
27
    wxString Data;
 
28
    if ( !GetString(Name,Data,wxEmptyString) || Data.empty() )
 
29
    {
 
30
        Value = Default;
 
31
        return false;
 
32
    }
 
33
    Value = Data[0];
 
34
    return true;
 
35
}
 
36
 
 
37
bool wxsPropertyStream::PutChar(const wxString &Name, wxChar& Value, wxChar Default)
 
38
{
 
39
    wxString Data = wxString::Format(_T("%c"),Value);
 
40
    if ( !PutString(Name,Data,wxString::Format(_T("%c"),Default)) ) return false;
 
41
    Value = Data.empty() ? Default : Data[0];
 
42
    return true;
 
43
}
 
44
 
 
45
bool wxsPropertyStream::GetLong(const wxString &Name, long& Value, long Default)
 
46
{
 
47
    wxString Data;
 
48
    if ( !GetString(Name,Data,wxEmptyString) || Data.empty() )
 
49
    {
 
50
        Value = Default;
 
51
        return false;
 
52
    }
 
53
    Data.ToLong(&Value);
 
54
    return true;
 
55
}
 
56
 
 
57
bool wxsPropertyStream::PutLong(const wxString &Name, long& Value, long Default)
 
58
{
 
59
    wxString Data = wxString::Format(_T("%d"),Value);
 
60
    if ( !PutString(Name,Data,wxString::Format(_T("%d"),Default)) ) return false;
 
61
    Data.ToLong(&Value);
 
62
    return true;
 
63
}
 
64
 
 
65
bool wxsPropertyStream::GetDouble(const wxString &Name, double& Value, double Default)
 
66
{
 
67
    wxString Data;
 
68
    if ( !GetString(Name,Data,wxEmptyString) || Data.empty() )
 
69
    {
 
70
        Value = Default;
 
71
        return false;
 
72
    }
 
73
    Data.ToDouble(&Value);
 
74
    return true;
 
75
}
 
76
 
 
77
bool wxsPropertyStream::PutDouble(const wxString &Name, double& Value, double Default)
 
78
{
 
79
    wxString Data = wxString::Format(_T("%f"),Value);
 
80
    if ( !PutString(Name,Data,wxString::Format(_T("%f"),Default)) ) return false;
 
81
    Data.ToDouble(&Value);
 
82
    return true;
 
83
}
 
84
 
 
85
bool wxsPropertyStream::GetULong(const wxString &Name, unsigned long& Value, unsigned long Default)
 
86
{
 
87
    wxString Data;
 
88
    if ( !GetString(Name,Data,wxEmptyString) || Data.empty() )
 
89
    {
 
90
        Value = Default;
 
91
        return false;
 
92
    }
 
93
    Data.ToULong(&Value);
 
94
    return true;
 
95
}
 
96
 
 
97
bool wxsPropertyStream::PutULong(const wxString &Name, unsigned long& Value, unsigned long Default)
 
98
{
 
99
    wxString Data = wxString::Format(_T("%u"),Value);
 
100
    if ( !PutString(Name,Data,wxString::Format(_T("%u"),Default)) ) return false;
 
101
    Data.ToULong(&Value);
 
102
    return true;
 
103
}
 
104
 
 
105
bool wxsPropertyStream::GetBool(const wxString &Name, bool& Value, bool Default)
 
106
{
 
107
    wxString Data;
 
108
    if ( !GetString(Name,Data,wxEmptyString) || Data.empty() )
 
109
    {
 
110
        Value = Default;
 
111
        return false;
 
112
    }
 
113
    long ValueL;
 
114
    Data.ToLong(&ValueL);
 
115
    Value = ValueL!=0;
 
116
    return true;
 
117
}
 
118
 
 
119
bool wxsPropertyStream::PutBool(const wxString &Name, bool& Value, bool Default)
 
120
{
 
121
    wxString Data = Value ? _T("1") : _T("0");
 
122
    if ( !PutString(Name,Data,Default?_T("1"):_T("0")) ) return false;
 
123
    long ValueL;
 
124
    Data.ToLong(&ValueL);
 
125
    Value = ValueL!=0;
 
126
    return true;
 
127
}