3 /// Class to easily manage the wxString / std::string boundary
7 Copyright (C) 2011-2012, Net Direct Inc. (http://www.netdirect.ca/)
9 This program is free software; you can redistribute it and/or modify
10 it under the terms of the GNU General Public License as published by
11 the Free Software Foundation; either version 2 of the License, or
12 (at your option) any later version.
14 This program is distributed in the hope that it will be useful,
15 but WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
18 See the GNU General Public License in the COPYING file at the
19 root directory of this project for more details.
22 #ifndef __BARRYDESKTOP_STRING_SYNC_H__
23 #define __BARRYDESKTOP_STRING_SYNC_H__
31 /// Provides a wxString or std::string while maintaining a link to
32 /// a corresponding external string of the opposite kind. When
33 /// Sync() is called, the external linked string is updated with the
34 /// current contents of the returned string.
36 /// This class contains two lists of strings: one that maps external
37 /// std::strings to internal wxStrings, and another that maps external
38 /// wxStrings to internal std::strings. These lists never mix.
39 /// Add or Refresh transfers data from external to internal, and Sync
40 /// transfers data from internal to external.
42 /// Normally, you would use Add and Refresh when setting up a dialog,
43 /// and once setup, never use them again. Use Sync when extracting
44 /// data from the dialog, back into the original variables again.
46 /// Note that you must call Sync explicitly, as it is not called
47 /// in the destructor, since it is impossible to know when the
48 /// external strings are freed, and they may have been freed already
49 /// by the time ~StringSync() is called.
54 typedef std::pair
<wxString
, std::string
*> WxIsCopyType
;
55 typedef std::pair
<std::string
, wxString
*> StdIsCopyType
;
56 typedef std::list
<WxIsCopyType
> WxIsCopyList
;
57 typedef std::list
<StdIsCopyType
> StdIsCopyList
;
64 /// On destruction, calls Sync()
67 /// Creates an internal wxString, copies the contents of source
68 /// into it, and returns its reference.
69 wxString
* Add(std::string
&source
);
72 std::string
* Add(wxString
&source
);
74 /// Copies all internal wxString contents into the corresponding
75 /// external std::strings.
78 /// Copies all internal std::string contents into the corresponding
79 /// external wxStrings.
82 /// Calls both SyncToStd() and SyncToWx()
85 /// Copies the contents of all the external std::strings into
86 /// their internal wxStrings, basically doing an Add() for each one
87 /// without re-creating the wxStrings.
90 /// Copies the contents of all the external wxStrings into their
91 /// internal std::strings, basically doing an Add() for each one
92 /// without re-creating the std::strings.
95 /// Calls both RefreshStd() and RefreshWx()