Bumped copyright dates to 2012
[barry.git] / desktop / src / StringSync.h
blob47c4a2c857c4e2c1e5e275d380f82ffdedbcae1a
1 ///
2 /// \file StringSync.h
3 /// Class to easily manage the wxString / std::string boundary
4 ///
6 /*
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__
25 #include <wx/wx.h>
26 #include <list>
29 // StringSync
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.
35 ///
36 class StringSync
38 public:
39 typedef std::pair<wxString, std::string*> WxIsCopyType;
40 typedef std::pair<std::string, wxString*> StdIsCopyType;
41 typedef std::list<WxIsCopyType> WxIsCopyList;
42 typedef std::list<StdIsCopyType> StdIsCopyList;
44 private:
45 WxIsCopyList m_wx;
46 StdIsCopyList m_std;
48 public:
49 /// On destruction, calls Sync()
50 ~StringSync();
52 /// Creates an internal wxString, copies the contents of source
53 /// into it, and returns its reference.
54 wxString* Add(std::string &source);
56 /// Does the opposite
57 std::string* Add(wxString &source);
59 /// Copies all internal wxString contents into the corresponding
60 /// external std::strings.
61 void SyncToStd();
63 /// Copies all internal std::string contents into the corresponding
64 /// external wxStrings.
65 void SyncToWx();
67 /// Calls SyncToStd() and then SyncToWx()
68 void Sync();
71 #endif