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 #include "StringSync.h"
27 //////////////////////////////////////////////////////////////////////////////
30 StringSync::~StringSync()
32 // do not Sync() here, since, if this object is part of another
33 // class, then external strings may have already been
34 // freed, depending on the order of objects defined in that class
37 wxString
* StringSync::Add(std::string
&source
)
39 m_wx
.push_front(WxIsCopyType(wxString(source
.c_str(), wxConvUTF8
), &source
));
40 return &m_wx
.begin()->first
;
43 std::string
* StringSync::Add(wxString
&source
)
45 m_std
.push_front(StdIsCopyType(std::string(source
.utf8_str()), &source
));
46 return &m_std
.begin()->first
;
49 void StringSync::SyncToStd()
51 WxIsCopyList::iterator b
= m_wx
.begin();
52 for( ; b
!= m_wx
.end(); ++b
) {
53 b
->second
->assign(b
->first
.utf8_str());
57 void StringSync::SyncToWx()
59 StdIsCopyList::iterator b
= m_std
.begin();
60 for( ; b
!= m_std
.end(); ++b
) {
61 *b
->second
= wxString(b
->first
.c_str(), wxConvUTF8
);
65 void StringSync::Sync()
67 // call order doesn't matter, since lists are independent
72 void StringSync::RefreshWx()
74 WxIsCopyList::iterator b
= m_wx
.begin();
75 for( ; b
!= m_wx
.end(); ++b
) {
76 b
->first
= wxString(b
->second
->c_str(), wxConvUTF8
);
80 void StringSync::RefreshStd()
82 StdIsCopyList::iterator b
= m_std
.begin();
83 for( ; b
!= m_std
.end(); ++b
) {
84 b
->first
.assign(b
->second
->utf8_str());
88 void StringSync::Refresh()
90 // call order doesn't matter, since lists are independent