CMake file

Update to C++ 11: std::shared_ptr, for each loops
Update to wxWidgets 3.0+
This commit is contained in:
Twan van Laarhoven
2020-04-08 00:18:14 +02:00
parent aa39a9bc71
commit 35a89676b4
53 changed files with 343 additions and 415 deletions
+39
View File
@@ -0,0 +1,39 @@
cmake_minimum_required(VERSION 3.13)
project(magicseteditor VERSION 2.2.0)
set(CMAKE_CXX_STANDARD 11)
set(CMAKE_CXX_STANDARD_REQUIRED True)
find_package(wxWidgets 3 REQUIRED COMPONENTS core base net html)
find_package(Boost REQUIRED COMPONENTS regex)
# find hunspell
#find_package(HUNSPELL)
find_path(HUNSPELL_INCLUDE_DIRS hunspell/hunspell.hxx)
find_library(HUNSPELL_LIBRARIES NAMES hunspell libhunspell)
include_directories("${PROJECT_BINARY_DIR}/src")
include_directories("${PROJECT_SOURCE_DIR}/src")
include(${wxWidgets_USE_FILE})
include_directories(${Boost_INCLUDE_DIRS})
include_directories(${HUNSPELL_INCLUDE_DIRS})
add_executable(magicseteditor WIN32)
target_link_libraries(${PROJECT_NAME} ${wxWidgets_LIBRARIES})
target_link_libraries(${PROJECT_NAME} ${Boost_LIBRARIES})
target_link_libraries(${PROJECT_NAME} ${HUNSPELL_LIBRARIES})
file(GLOB_RECURSE sources src/*.cpp)
target_sources(magicseteditor PRIVATE ${sources})
target_precompile_headers(magicseteditor PRIVATE src/util/prec.hpp)
# warnings
if(CMAKE_COMPILER_IS_GNUCC OR CMAKE_COMPILER_IS_GNUCXX)
# Update if necessary
#set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -Wno-comment")
endif()
# visual studio debugger
set_property(DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} PROPERTY VS_STARTUP_PROJECT magicseteditor)
+1 -1
View File
@@ -125,7 +125,7 @@ void CLISetInterface::handleCommand(const String& command) {
// :something
size_t space = min(command.find_first_of(_(' ')), command.size());
String before = command.substr(0,space);
String arg = space + 1 < command.size() ? command.substr(space+1) : wxEmptyString;
String arg = space + 1 < command.size() ? command.substr(space+1) : String();
if (before == _(":q") || before == _(":quit")) {
if (!quiet) {
cli << _("Goodbye\n");
+2 -1
View File
@@ -146,7 +146,8 @@ void KeywordReminderTextValue::highlight(const String& code, const vector<Script
}
++pos;
} else if (c == _('\\') && in_string && pos + 1 < code.size()) {
new_value += c + code.GetChar(pos + 1); // escape code
new_value += c;
new_value += code.GetChar(pos + 1); // escape code
pos += 2;
} else if (is_substr(code, pos, _("if ")) && !in_string) {
new_value += _("<code-kw>if</code-kw> ");
+4 -2
View File
@@ -19,6 +19,7 @@
#include <data/card.hpp>
#include <util/tagged_string.hpp>
#include <data/set.hpp> // for ValueActionPerformer
#include <wx/imaglist.h>
// ----------------------------------------------------------------------------- : ValueAction
@@ -210,8 +211,9 @@ void TextToggleReminderAction::perform(bool to_undo) {
String& val = value.value.mutate();
assert(pos + 4 < val.size());
size_t end = match_close_tag(val, pos);
Char& c = val[pos + 4];
swap(c, old);
wxUniChar c = old;
old = val[pos + 4];
val[pos + 4] = c;
if (end != String::npos && end + 5 < val.size()) {
val[end + 5] = c; // </kw-c>
}
+1 -1
View File
@@ -105,7 +105,7 @@ class TextToggleReminderAction : public ValueAction {
private:
size_t pos; ///< Position of "<kw-"
bool enable; ///< Should the reminder text be turned on or off?
Char old; ///< Old value of the <kw- tag
wxUniChar old; ///< Old value of the <kw- tag
};
// ----------------------------------------------------------------------------- : Replace all
+1 -1
View File
@@ -28,7 +28,7 @@ void AddCardsScript::perform(Set& set, vector<CardP>& out) {
Context& ctx = set.getContext();
ScriptValueP result = script.invoke(ctx);
// Add cards to out
ScriptValueP it = result->makeIterator(result);
ScriptValueP it = result->makeIterator();
while (ScriptValueP item = it->next()) {
CardP card = from_script<CardP>(item);
// is this a new card?
+1
View File
@@ -17,6 +17,7 @@
#include <script/scriptable.hpp>
#include <script/image.hpp>
#include <wx/image.h>
class wxImageList;
// ----------------------------------------------------------------------------- : ChoiceField
+2 -2
View File
@@ -79,8 +79,8 @@ FontP Font::make(int add_flags, AColor* other_color, double* other_size) const {
static const String BOLD_STRING = _(" Bold");
wxFont Font::toWxFont(double scale) const {
int size_i = to_int(scale * size);
int weight_i = flags & FONT_BOLD ? wxFONTWEIGHT_BOLD : wxFONTWEIGHT_NORMAL;
int style_i = flags & FONT_ITALIC ? wxFONTSTYLE_ITALIC : wxFONTSTYLE_NORMAL;
wxFontWeight weight_i = flags & FONT_BOLD ? wxFONTWEIGHT_BOLD : wxFONTWEIGHT_NORMAL;
wxFontStyle style_i = flags & FONT_ITALIC ? wxFONTSTYLE_ITALIC : wxFONTSTYLE_NORMAL;
// make font
wxFont font;
+1 -1
View File
@@ -220,7 +220,7 @@ String MtgEditorFileFormat::filter1(const String& str) {
after = str.substr(pos + 1);
}
// filter
FOR_EACH(c, after) {
FOR_EACH_CONST(c, after) {
if (isAlnum(c)) ret += c;
else ret += _('_');
}
-1
View File
@@ -275,7 +275,6 @@ class KeywordTrie {
KeywordTrie::KeywordTrie()
: on_any_star(nullptr)
, finished(nullptr)
{}
KeywordTrie::~KeywordTrie() {
+1 -1
View File
@@ -201,7 +201,7 @@ int string_format_args(const String& str) {
InputStreamP load_resource_text(const String& name);
InputStreamP load_resource_text(const String& name) {
#if defined(__WXMSW__) && !defined(__GNUC__)
HRSRC hResource = ::FindResource(wxGetInstance(), name, _("TEXT"));
HRSRC hResource = ::FindResource(wxGetInstance(), name.wc_str(), _("TEXT"));
if ( hResource == 0 ) throw InternalError(String::Format(_("Resource not found: %s"), name));
HGLOBAL hData = ::LoadResource(wxGetInstance(), hResource);
if ( hData == 0 ) throw InternalError(String::Format(_("Resource not text: %s"), name));
+1 -1
View File
@@ -50,7 +50,7 @@ void AboutWindow::draw(DC& dc) {
dc.SetTextBackground(Color(114,197,224));
dc.SetTextForeground(Color(0,0,0));
// draw version info
dc.SetFont(wxFont(9, wxSWISS, wxNORMAL, wxNORMAL, false, _("Arial")));
dc.SetFont(wxFont(9, wxFONTFAMILY_SWISS, wxFONTSTYLE_NORMAL, wxFONTWEIGHT_NORMAL, false, _("Arial")));
dc.DrawText(_("Version: ") + app_version.toString() + version_suffix, 34, 110);
dc.DrawText(_("Copyright \xA9 2001-2011"), 34, 130);
dc.DrawText(_(" Twan van Laarhoven,"), 34, 147);
+4 -4
View File
@@ -258,11 +258,11 @@ void AutoReplaceWindow::refreshItem() {
in_event = true;
AutoReplaceP ar = list->getSelected();
match ->Enable(ar && ar->custom);
replace ->Enable(ar);
replace ->Enable((bool)ar);
matchL ->Enable(ar && ar->custom);
replaceL ->Enable(ar);
enabled ->Enable(ar);
whole_word->Enable(ar);
replaceL ->Enable((bool)ar);
enabled ->Enable((bool)ar);
whole_word->Enable((bool)ar);
remove ->Enable(ar && ar->custom);
if (ar) {
match ->SetValue(ar->match);
+1 -1
View File
@@ -956,7 +956,7 @@ void GraphValueAxis::draw(RotatedDC& dc, int current, DrawLayer layer) const {
// highlight?
if (i == highlight) {
wxFont font(*wxNORMAL_FONT);
font.SetWeight(wxBOLD);
font.SetWeight(wxFONTWEIGHT_BOLD);
dc.SetFont(font);
dc.SetPen(fg);
}
+1 -1
View File
@@ -39,7 +39,7 @@ void PackageList::drawItem(DC& dc, int x, int y, size_t item) {
dc.DrawBitmap(d.image, x + int(align_delta_x(ALIGN_CENTER, item_size.x, d.image.GetWidth())), y + 3, true);
}
// draw short name
dc.SetFont(wxFont(12,wxSWISS,wxNORMAL,wxBOLD,false,_("Arial")));
dc.SetFont(wxFont(12,wxFONTFAMILY_SWISS,wxFONTSTYLE_NORMAL,wxFONTWEIGHT_BOLD,false,_("Arial")));
dc.GetTextExtent(capitalize(d.package->short_name), &w, &h);
pos = align_in_rect(ALIGN_CENTER, RealSize(w,h), rect);
dc.DrawText(capitalize(d.package->short_name), max(x+1,(int)pos.x), (int)pos.y + 110);
+3 -2
View File
@@ -42,14 +42,15 @@ void PackageUpdateList::TreeItem::add(const InstallablePackageP& package, const
String name = path.substr(0,pos);
String rest = pos == String::npos ? _("") : path.substr(pos+1);
// find/add child
FOR_EACH(ti, children) {
for (auto it = children.begin() ; it != children.end() ; ++it) {
auto const& ti = *it;
if (ti->label == name) {
// already have this child
if (pos == String::npos && ti->package) {
// two packages with the same path
TreeItemP ti2(new TreeItem);
ti2->label = name;
children.insert(ti_IT.first, ti2);
children.insert(it, ti2);
ti2->add(package, rest, level + 1);
} else {
ti->add(package, rest, level + 1);
+2 -2
View File
@@ -125,7 +125,7 @@ void StylePanel::onAction(const Action& action, bool undone) {
}
}
use_for_all->Enable(card && card->stylesheet);
use_custom_options->Enable(card);
use_custom_options->Enable((bool)card);
use_custom_options->SetValue(card ? card->has_styling : false);
}
@@ -139,7 +139,7 @@ void StylePanel::selectCard(const CardP& card) {
editor->showCard(card);
list->select(set->stylesheetFor(card).name(), false);
use_for_all->Enable(card && card->stylesheet);
use_custom_options->Enable(card);
use_custom_options->Enable((bool)card);
use_custom_options->SetValue(card ? card->has_styling : false);
}
+1 -1
View File
@@ -278,7 +278,7 @@ void SymbolControl::onUpdateUI(wxUpdateUIEvent& ev) {
ev.Check(editor->modeToolId() == ev.GetId());
if (ev.GetId() == ID_MODE_POINTS) {
// can only edit points when a shape is available
ev.Enable(selected_parts.getAShape());
ev.Enable((bool)selected_parts.getAShape());
}
if (ev.GetId() == ID_MODE_SYMMETRY) {
ev.Enable(!selected_parts.empty());
+1 -1
View File
@@ -146,7 +146,7 @@ wxPen SymbolPointEditor::handlePen(WhichPen p, LockMode lock) {
switch(p) {
case PEN_NORMAL: return wxPen(col);
case PEN_HOVER: return wxPen(col, 2);
case PEN_LINE: return wxPen(col, 1, wxDOT);
case PEN_LINE: return wxPen(col, 1, wxPENSTYLE_DOT);
default: throw InternalError(_("SymbolPointEditor::handlePen"));
}
}
+1 -1
View File
@@ -57,7 +57,7 @@ void SymbolSelectEditor::draw(DC& dc) {
if (click_mode == CLICK_RECT) {
// draw selection rectangle
dc.SetBrush(*wxTRANSPARENT_BRUSH);
dc.SetPen(wxPen(*wxCYAN,1,wxDOT));
dc.SetPen(wxPen(*wxCYAN,1,wxPENSTYLE_DOT));
//% TODO: use RotatedDC?
RealRect rect = control.rotation.trRectToBB(RealRect(selection_rect_a, RealSize(selection_rect_b - selection_rect_a)));
dc.DrawRectangle(rect);
+4 -4
View File
@@ -37,7 +37,7 @@ void SymbolSymmetryEditor::draw(DC& dc) {
Vector2D handle = control.rotation.tr(symmetry->center + symmetry->handle);
if (symmetry->kind == SYMMETRY_REFLECTION) {
// draw line to handle
dc.SetPen(wxPen(color,1,wxDOT));
dc.SetPen(wxPen(color,1,wxPENSTYLE_DOT));
dc.DrawLine(int(center.x), int(center.y), int(handle.x), int(handle.y));
// draw handle
dc.SetPen(*wxBLACK_PEN);
@@ -87,17 +87,17 @@ void SymbolSymmetryEditor::destroyUI(wxToolBar* tb, wxMenuBar* mb) {
void SymbolSymmetryEditor::onUpdateUI(wxUpdateUIEvent& ev) {
if (ev.GetId() >= ID_SYMMETRY && ev.GetId() < ID_SYMMETRY_MAX) {
ev.Enable(symmetry);
ev.Enable((bool)symmetry);
ev.Check(symmetry && symmetry->kind == ev.GetId() - ID_SYMMETRY);
} else if (ev.GetId() == ID_COPIES) {
ev.Enable(symmetry);
ev.Enable((bool)symmetry);
if (symmetry) {
copies->SetValue(symmetry->copies);
}
} else if (ev.GetId() == ID_ADD_SYMMETRY) {
ev.Enable(true);
} else if (ev.GetId() == ID_REMOVE_SYMMETRY) {
ev.Enable(symmetry);
ev.Enable((bool)symmetry);
} else {
ev.Enable(false); // we don't know about this item
}
+4 -3
View File
@@ -22,6 +22,7 @@
#include <util/error.hpp>
#include <wx/filename.h>
#include <wx/wfstream.h>
#include <wx/spinctrl.h>
// ----------------------------------------------------------------------------- : Constructor
@@ -209,7 +210,7 @@ void SymbolWindow::onFileNew(wxCommandEvent& ev) {
}
void SymbolWindow::onFileOpen(wxCommandEvent& ev) {
String name = wxFileSelector(_("Open symbol"),settings.default_symbol_dir,_(""),_(""),_("Symbol files|*.mse-symbol;*.bmp|MSE2 symbol files (*.mse-symbol)|*.mse-symbol|Images/MSE1 symbol files|*.bmp;*.png;*.jpg;*.gif"),wxOPEN|wxFILE_MUST_EXIST, this);
String name = wxFileSelector(_("Open symbol"),settings.default_symbol_dir,_(""),_(""),_("Symbol files|*.mse-symbol;*.bmp|MSE2 symbol files (*.mse-symbol)|*.mse-symbol|Images/MSE1 symbol files|*.bmp;*.png;*.jpg;*.gif"),wxFD_OPEN|wxFD_FILE_MUST_EXIST, this);
if (!name.empty()) {
settings.default_symbol_dir = wxPathOnly(name);
wxFileName n(name);
@@ -236,7 +237,7 @@ void SymbolWindow::onFileSave(wxCommandEvent& ev) {
}
void SymbolWindow::onFileSaveAs(wxCommandEvent& ev) {
String name = wxFileSelector(_("Save symbol"),settings.default_set_dir,_(""),_(""),_("Symbol files (*.mse-symbol)|*.mse-symbol"),wxSAVE, this);
String name = wxFileSelector(_("Save symbol"),settings.default_set_dir,_(""),_(""),_("Symbol files (*.mse-symbol)|*.mse-symbol"),wxFD_SAVE, this);
if (!name.empty()) {
settings.default_set_dir = wxPathOnly(name);
Writer writer(shared(new wxFileOutputStream(name)), file_version_symbol);
@@ -345,7 +346,7 @@ BEGIN_EVENT_TABLE(SymbolWindow, wxFrame)
EVT_TOOL_RANGE (ID_MODE_MIN, ID_MODE_MAX, SymbolWindow::onModeChange)
EVT_TOOL_RANGE (ID_CHILD_MIN, ID_CHILD_MAX, SymbolWindow::onExtraTool)
EVT_UPDATE_UI (wxID_ANY, SymbolWindow::onUpdateUI)
EVT_COMMAND_RANGE(ID_CHILD_MIN, ID_CHILD_MAX, wxEVT_COMMAND_SPINCTRL_UPDATED, SymbolWindow::onExtraTool)
EVT_COMMAND_RANGE(ID_CHILD_MIN, ID_CHILD_MAX, wxEVT_SPINCTRL, SymbolWindow::onExtraTool)
EVT_PART_SELECT (ID_PART_LIST, SymbolWindow::onSelectFromList)
EVT_PART_ACTIVATE (ID_PART_LIST, SymbolWindow::onActivateFromList)
+11 -7
View File
@@ -15,7 +15,11 @@
#if wxUSE_UXTHEME && defined(__WXMSW__)
#include <wx/msw/uxtheme.h>
#if defined(HAVE_VSSYM32)
#include <vssym32.h>
#else
#include <tmschema.h>
#endif
#include <shlobj.h>
#include <wx/mstream.h>
#endif
@@ -146,7 +150,7 @@ Image load_resource_image(const String& name) {
// Load resource
// based on wxLoadUserResource
// The image can be in an IMAGE resource, in any file format
HRSRC hResource = ::FindResource(wxGetInstance(), name, _("IMAGE"));
HRSRC hResource = ::FindResource(wxGetInstance(), name.wc_str(), _("IMAGE"));
if ( hResource == 0 ) throw InternalError(String::Format(_("Resource not found: %s"), name));
HGLOBAL hData = ::LoadResource(wxGetInstance(), hResource);
@@ -242,7 +246,7 @@ void draw3DBorder(DC& dc, int x1, int y1, int x2, int y2) {
}
void draw_control_box(Window* win, DC& dc, const wxRect& rect, bool focused, bool enabled) {
#if wxUSE_UXTHEME && defined(__WXMSW__)
#if wxUSE_UXTHEME && defined(__WXMSW__) && TODO_FIX_THEME_ENGINE
RECT r;
wxUxThemeEngine *themeEngine = wxUxThemeEngine::Get();
if (themeEngine && themeEngine->IsAppThemed()) {
@@ -270,7 +274,7 @@ void draw_control_box(Window* win, DC& dc, const wxRect& rect, bool focused, boo
dc.SetBrush(wxSystemSettings::GetColour(wxSYS_COLOUR_WINDOW));
dc.DrawRectangle(rect);
// draw the border
#if defined(__WXMSW__)
#if defined(__WXMSW__) && TODO_FIX_THEME_ENGINE
r.left = rect.x - 2;
r.top = rect.y - 2;
r.right = rect.x + rect.width + 2;
@@ -283,7 +287,7 @@ void draw_control_box(Window* win, DC& dc, const wxRect& rect, bool focused, boo
}
void draw_button(Window* win, DC& dc, const wxRect& rect, bool focused, bool down, bool enabled) {
#if wxVERSION >= 2700
#if wxVERSION_NUMBER >= 2700
wxRendererNative& rn = wxRendererNative::GetDefault();
rn.DrawPushButton(win, dc, rect, (focused ? wxCONTROL_FOCUSED : 0) | (down ? wxCONTROL_PRESSED : 0) | (enabled ? 0 : wxCONTROL_DISABLED));
#else
@@ -336,7 +340,7 @@ void draw_checkbox(Window* win, DC& dc, const wxRect& rect, bool checked, bool e
}
void draw_radiobox(Window* win, DC& dc, const wxRect& rect, bool checked, bool enabled) {
#if wxUSE_UXTHEME && defined(__WXMSW__)
#if wxUSE_UXTHEME && defined(__WXMSW__) && TODO_FIX_THEME_ENGINE
// TODO: Windows version?
#endif
// portable version
@@ -357,7 +361,7 @@ void draw_radiobox(Window* win, DC& dc, const wxRect& rect, bool checked, bool e
}
void draw_selection_rectangle(Window* win, DC& dc, const wxRect& rect, bool selected, bool focused, bool hot) {
#if wxUSE_UXTHEME && defined(__WXMSW__)
#if wxUSE_UXTHEME && defined(__WXMSW__) && TODO_FIX_THEME_ENGINE
#if !defined(NTDDI_LONGHORN) || NTDDI_VERSION < NTDDI_LONGHORN
#define LISS_NORMAL LIS_NORMAL
#define LISS_SELECTED LIS_SELECTED
@@ -390,7 +394,7 @@ void draw_selection_rectangle(Window* win, DC& dc, const wxRect& rect, bool sele
}
void enable_themed_selection_rectangle(Window* win) {
#if wxUSE_UXTHEME && defined(__WXMSW__)
#if wxUSE_UXTHEME && defined(__WXMSW__) && TODO_FIX_THEME_ENGINE
wxUxThemeEngine *themeEngine = wxUxThemeEngine::Get();
if (themeEngine && themeEngine->IsAppThemed()) {
themeEngine->SetWindowTheme((HWND)win->GetHWND(), L"Explorer", NULL);
+1 -1
View File
@@ -21,7 +21,7 @@ IMPLEMENT_VALUE_EDITOR(Image) {}
bool ImageValueEditor::onLeftDClick(const RealPoint&, wxMouseEvent&) {
String filename = wxFileSelector(_("Open image file"), settings.default_image_dir, _(""), _(""),
_("All images|*.bmp;*.jpg;*.png;*.gif|Windows bitmaps (*.bmp)|*.bmp|JPEG images (*.jpg;*.jpeg)|*.jpg;*.jpeg|PNG images (*.png)|*.png|GIF images (*.gif)|*.gif|TIFF images (*.tif;*.tiff)|*.tif;*.tiff"),
wxOPEN, wxGetTopLevelParent(&editor()));
wxFD_OPEN, wxGetTopLevelParent(&editor()));
if (!filename.empty()) {
settings.default_image_dir = wxPathOnly(filename);
wxImage image;
+1 -1
View File
@@ -24,7 +24,7 @@ void SymbolValueEditor::draw(RotatedDC& dc) {
SymbolValueViewer::draw(dc);
// draw helper text if there are no symbols
if (symbols.empty()) {
dc.SetFont(wxFont(10,wxSWISS,wxNORMAL,wxNORMAL));
dc.SetFont(wxFont(10,wxFONTFAMILY_SWISS,wxFONTSTYLE_NORMAL,wxFONTWEIGHT_NORMAL));
dc.SetTextForeground(*wxBLACK);
RealSize text_size = dc.GetTextExtent(_("double click to edit symbol"));
dc.DrawText(_("double click to edit symbol"), align_in_rect(ALIGN_MIDDLE_CENTER, text_size, style().getInternalRect()));
+1 -1
View File
@@ -733,7 +733,7 @@ bool TextValueEditor::containsPoint(const RealPoint& pos) const {
RealPoint pos2(pos.x * style().getStretch(), pos.y);
if (TextValueViewer::containsPoint(pos2)) return true;
if (word_lists.empty()) return false;
return findWordList(pos);
return (bool) findWordList(pos);
}
RealRect TextValueEditor::boundingBox() const {
if (word_lists.empty()) return ValueViewer::boundingBox();
+3 -3
View File
@@ -92,7 +92,7 @@ void WelcomeWindow::draw(DC& dc) {
dc.DrawBitmap(logo2, ws.GetWidth() - logo2.GetWidth(), ws.GetHeight() - logo2.GetHeight());
#endif
// draw version number
dc.SetFont(wxFont(8, wxSWISS, wxNORMAL, wxNORMAL, false, _("Arial")));
dc.SetFont(wxFont(8, wxFONTFAMILY_SWISS, wxFONTSTYLE_NORMAL, wxFONTWEIGHT_NORMAL, false, _("Arial")));
dc.SetTextForeground(Color(0,126,176));
int tw,th;
String version_string = _("version ") + app_version.toString() + version_suffix;
@@ -159,8 +159,8 @@ HoverButtonExt::HoverButtonExt(Window* parent, int id, const wxImage& icon, cons
: HoverButton(parent, id, _("btn"))
, icon(icon)
, label(label), sub_label(sub_label)
, font_large(14, wxSWISS, wxNORMAL, wxNORMAL, false, _("Arial"))
, font_small(8, wxSWISS, wxNORMAL, wxNORMAL, false, _("Arial"))
, font_large(14, wxFONTFAMILY_SWISS, wxFONTSTYLE_NORMAL, wxFONTWEIGHT_NORMAL, false, _("Arial"))
, font_small(8, wxFONTFAMILY_SWISS, wxFONTSTYLE_NORMAL, wxFONTWEIGHT_NORMAL, false, _("Arial"))
{}
void HoverButtonExt::draw(DC& dc) {
+3 -3
View File
@@ -274,7 +274,7 @@ void SymbolViewer::drawSymbolShape(const SymbolShape& shape, DC* border, DC* int
border->SetPen(*wxTRANSPARENT_PEN);
border->SetBrush(Color(0, (directB ? 128 : 0), 0));
int func = border->GetLogicalFunction();
wxRasterOperationMode func = border->GetLogicalFunction();
border->SetLogicalFunction(wxCOPY);
border->DrawPolygon((int)points.size(), &points[0]);
border->SetLogicalFunction(func);
@@ -317,7 +317,7 @@ void SymbolViewer::highlightPart(DC& dc, const SymbolShape& shape, HighlightStyl
dc.DrawPolygon((int)points.size(), &points[0]);
} else if (style == HIGHLIGHT_BORDER_DOT) {
dc.SetBrush(*wxTRANSPARENT_BRUSH);
dc.SetPen (wxPen(Color(255,0,0), 1, wxDOT));
dc.SetPen (wxPen(Color(255,0,0), 1, wxPENSTYLE_DOT));
dc.DrawPolygon((int)points.size(), &points[0]);
} else {
dc.SetLogicalFunction(wxOR);
@@ -351,7 +351,7 @@ void SymbolViewer::highlightPart(DC& dc, const SymbolSymmetry& sym, HighlightSty
for (int i = 0; i < copies ; ++i) {
Radians a = angle + (i + 0.5) * 2 * M_PI / copies;
Vector2D dir(cos(a), sin(a));
Vector2D dir2 = rotation.tr(sym.center + 2 * dir);
Vector2D dir2 = rotation.tr(sym.center + 2.0 * dir);
dc.DrawLine(int(center.x), int(center.y), int(dir2.x), int(dir2.y));
}
// draw center
+1 -1
View File
@@ -117,7 +117,7 @@ Bitmap ImageValueViewer::imagePlaceholder(const Rotation& rot, UInt w, UInt h, c
if (editing) {
// only when in editor mode
for (UInt size = 12 ; size > 2 ; --size) {
dc.SetFont(wxFont(size, wxSWISS, wxNORMAL, wxNORMAL));
dc.SetFont(wxFont(size, wxFONTFAMILY_SWISS, wxFONTSTYLE_NORMAL, wxFONTWEIGHT_NORMAL));
RealSize rs = dc.GetTextExtent(_("double click to load image"));
if (rs.width <= w - 10 && rs.height < h - 10) {
// text fits
+2 -2
View File
@@ -44,8 +44,8 @@ bool ValueViewer::setFieldBorderPen(RotatedDC& dc) {
DrawWhat what = viewer.drawWhat(this);
if (!(what & DRAW_BORDERS)) return false;
dc.SetPen( (what & DRAW_ACTIVE)
? wxPen(Color(0,128,255), 1, wxSOLID)
: wxPen(Color(128,128,128), 1, wxDOT)
? wxPen(Color(0,128,255), 1, wxPENSTYLE_SOLID)
: wxPen(Color(128,128,128), 1, wxPENSTYLE_DOT)
);
return true;
}
+1 -1
View File
@@ -359,7 +359,7 @@ void Context::closeScope(size_t scope) {
// ----------------------------------------------------------------------------- : Simple instructions : unary
void instrUnary (UnaryInstructionType i, ScriptValueP& a) {
void instrUnary(UnaryInstructionType i, ScriptValueP& a) {
switch (i) {
case I_ITERATOR_C:
a = a->makeIterator(a);
+3 -3
View File
@@ -41,7 +41,7 @@ ScriptValueP unified(const ScriptValueP& a, const ScriptValueP& b);
* So it has the dependency characteristics of both.
*/
class DependencyUnion : public ScriptValue {
public:
public:
DependencyUnion(const ScriptValueP& a, const ScriptValueP& b)
: a(a), b(b)
{}
@@ -53,7 +53,7 @@ class DependencyUnion : public ScriptValue {
return unified( a->dependencies(ctx,dep), b->dependencies(ctx,dep));
}
virtual ScriptValueP makeIterator(ScriptValueP thisP) const {
return unified(a->makeIterator(thisP), b->makeIterator(thisP));
return unified(a->makeIterator(a), b->makeIterator(b));
}
virtual ScriptValueP dependencyMember(const String& name, const Dependency& dep) const {
return unified(a->dependencyMember(name,dep), b->dependencyMember(name,dep));
@@ -61,7 +61,7 @@ class DependencyUnion : public ScriptValue {
virtual ScriptValueP dependencyName(const ScriptValue& container, const Dependency& dep) const {
return unified(a->dependencyName(container,dep), b->dependencyName(container,dep));
}
private:
private:
ScriptValueP a, b;
};
+23 -10
View File
@@ -316,11 +316,18 @@ SCRIPT_FUNCTION(to_title) {
SCRIPT_RETURN(capitalize(input.Lower()));
}
String reverse_string(String const& input) {
// Note: std::reverse doesn't work because of unicode encoding stuff
String reversed;
for (auto it = input.rbegin(); it != input.rend(); ++it) {
reversed += *it;
}
return reversed;
}
// reverse a string
SCRIPT_FUNCTION(reverse) {
SCRIPT_PARAM_C(String, input);
reverse(input.begin(), input.end());
SCRIPT_RETURN(input);
SCRIPT_RETURN(reverse_string(input));
}
// remove leading and trailing whitespace from a string
@@ -370,12 +377,19 @@ SCRIPT_FUNCTION(regex_escape) {
}
// sort/filter characters
void sort_string(String& input) {
vector<wxUniChar> chars;
copy(input.begin(), input.end(), back_inserter(chars));
sort(chars.begin(), chars.end());
input.clear();
for (auto c : chars) input += c;
}
SCRIPT_FUNCTION(sort_text) {
SCRIPT_PARAM_C(String, input);
SCRIPT_OPTIONAL_PARAM_C(String, order) {
SCRIPT_RETURN(spec_sort(order, input));
} else {
sort(input.begin(), input.end());
sort_string(input);
SCRIPT_RETURN(input);
}
}
@@ -432,7 +446,6 @@ SCRIPT_FUNCTION(remove_tags) {
// ----------------------------------------------------------------------------- : Collection stuff
/// position of some element in a vector
/** 0 based index, -1 if not found */
int position_in_vector(const ScriptValueP& of, const ScriptValueP& in, const ScriptValueP& order_by, const ScriptValueP& filter) {
@@ -450,7 +463,7 @@ int position_in_vector(const ScriptValueP& of, const ScriptValueP& in, const Scr
}
} else {
// unordered position
ScriptValueP it = in->makeIterator(in);
ScriptValueP it = in->makeIterator();
int i = 0;
while (ScriptValueP v = it->next()) {
if (equal(of, v)) return i;
@@ -473,7 +486,7 @@ ScriptValueP sort_script(Context& ctx, const ScriptValueP& list, ScriptValue& or
if (list_t == SCRIPT_STRING) {
// sort a string
String s = list->toString();
sort(s.begin(), s.end());
sort_string(s);
if (remove_duplicates) {
s.erase( unique(s.begin(), s.end()), s.end() );
}
@@ -483,7 +496,7 @@ ScriptValueP sort_script(Context& ctx, const ScriptValueP& list, ScriptValue& or
ScriptObject<Set*>* set = dynamic_cast<ScriptObject<Set*>*>(list.get());
// sort a collection
vector<pair<String,ScriptValueP> > values;
ScriptValueP it = list->makeIterator(list);
ScriptValueP it = list->makeIterator();
while (ScriptValueP v = it->next()) {
ctx.setVariable(set ? _("card") : _("input"), v);
values.push_back(make_pair(order_by.eval(ctx)->toString(), v));
@@ -558,7 +571,7 @@ SCRIPT_FUNCTION(filter_list) {
SCRIPT_PARAM_C(ScriptValueP, filter);
// filter a collection
ScriptCustomCollectionP ret(new ScriptCustomCollection());
ScriptValueP it = input->makeIterator(input);
ScriptValueP it = input->makeIterator();
while (ScriptValueP v = it->next()) {
ctx.setVariable(SCRIPT_VAR_input, v);
if (*filter->eval(ctx)) {
@@ -581,7 +594,7 @@ SCRIPT_FUNCTION(random_shuffle) {
SCRIPT_PARAM_C(ScriptValueP, input);
// convert to CustomCollection
ScriptCustomCollectionP ret(new ScriptCustomCollection());
ScriptValueP it = input->makeIterator(input);
ScriptValueP it = input->makeIterator();
while (ScriptValueP v = it->next()) {
ret->value.push_back(v);
}
@@ -620,7 +633,7 @@ SCRIPT_FUNCTION(random_select_many) {
throw ScriptError(String::Format(_("Can not select %d items from a collection conaining only %d items"), count, input->itemCount()));
}
// transfer all to ret and shuffle
ScriptValueP it = input->makeIterator(input);
ScriptValueP it = input->makeIterator();
while (ScriptValueP v = it->next()) {
ret->value.push_back(v);
}
+1 -1
View File
@@ -25,7 +25,7 @@ SCRIPT_FUNCTION(new_card) {
CardP new_card = intrusive(new Card(*game));
// set field values
SCRIPT_PARAM(ScriptValueP, input);
ScriptValueP it = input->makeIterator(input);
ScriptValueP it = input->makeIterator();
ScriptValueP key;
while (ScriptValueP v = it->next(&key)) {
assert(key);
+1 -1
View File
@@ -384,7 +384,7 @@ SCRIPT_FUNCTION(count_chosen) {
SCRIPT_RETURN(0);
} else {
int count = 1;
FOR_EACH(c, input) if (c == _(',')) ++count;
FOR_EACH_CONST(c, input) if (c == _(',')) ++count;
SCRIPT_RETURN(count);
}
}
+1 -1
View File
@@ -33,7 +33,7 @@ class ScriptableImage {
/// Is there a scripted image set?
inline bool isScripted() const { return script; }
/// Is there an image generator available?
inline bool isReady() const { return value; }
inline bool isReady() const { return (bool)value; }
/// Is there an image set?
inline bool isSet() const { return script || value; }
+13 -19
View File
@@ -75,8 +75,8 @@ bool equal(const ScriptValueP& a, const ScriptValueP& b) {
} else if (at == SCRIPT_COLLECTION && bt == SCRIPT_COLLECTION) {
// compare each element
if (a->itemCount() != b->itemCount()) return false;
ScriptValueP a_it = a->makeIterator(a);
ScriptValueP b_it = b->makeIterator(b);
ScriptValueP a_it = a->makeIterator();
ScriptValueP b_it = b->makeIterator();
while (true) {
ScriptValueP a_v = a_it->next();
ScriptValueP b_v = b_it->next();
@@ -115,7 +115,7 @@ ScriptValueP ScriptDelayedError::getMember(const String&) const
ScriptValueP ScriptDelayedError::dependencyMember(const String&, const Dependency&) const { return intrusive(new ScriptDelayedError(error)); }
ScriptValueP ScriptDelayedError::do_eval(Context&, bool) const { return intrusive(new ScriptDelayedError(error)); }
ScriptValueP ScriptDelayedError::dependencies(Context&, const Dependency&) const { return intrusive(new ScriptDelayedError(error)); }
ScriptValueP ScriptDelayedError::makeIterator(const ScriptValueP& thisP) const { return thisP; }
ScriptValueP ScriptDelayedError::makeIterator(const ScriptValueP& thisP) const { return thisP ? thisP : intrusive(new ScriptDelayedError(error)); }
// ----------------------------------------------------------------------------- : Iterators
@@ -279,7 +279,8 @@ class ScriptString : public ScriptValue {
}
virtual operator wxDateTime() const {
wxDateTime date;
if (!date.ParseDateTime(value.c_str())) {
String::const_iterator end;
if (!date.ParseDateTime(value,&end) || end != value.end()) {
throw ScriptErrorConversion(value, typeName(), _TYPE_("date"));
}
return date;
@@ -386,13 +387,7 @@ ScriptValueP script_nil(new ScriptNil);
String ScriptCollectionBase::toCode() const {
String ret = _("[");
bool first = true;
#ifdef USE_INTRUSIVE_PTR
// we can just turn this into a ScriptValueP
// TODO: remove thisP alltogether
ScriptValueP it = makeIterator(ScriptValueP(const_cast<ScriptValue*>(static_cast<const ScriptValue*>(this))));
#else
#error "makeIterator needs a ScriptValueP :("
#endif
ScriptValueP it = makeIterator();
while (ScriptValueP v = it->next()) {
if (!first) ret += _(",");
first = false;
@@ -407,9 +402,9 @@ String ScriptCollectionBase::toCode() const {
// Iterator over a custom collection
class ScriptCustomCollectionIterator : public ScriptIterator {
public:
ScriptCustomCollectionIterator(ScriptCustomCollectionP col)
: col(col), pos(0), it(col->key_value.begin()) {}
public:
ScriptCustomCollectionIterator(ScriptCustomCollection const* col, ScriptValueP const& col_owned)
: col(col), col_owned(col_owned), pos(0), it(col->key_value.begin()) {}
virtual ScriptValueP next(ScriptValueP* key_out) {
if (pos < col->value.size()) {
if (key_out) *key_out = to_script((int)pos);
@@ -421,8 +416,9 @@ class ScriptCustomCollectionIterator : public ScriptIterator {
return ScriptValueP();
}
}
private:
ScriptCustomCollectionP col;
private:
ScriptCustomCollection const* col;
ScriptValueP col_owned; // own the collection so it doesn't get deleted
size_t pos;
map<String,ScriptValueP>::const_iterator it;
};
@@ -443,9 +439,7 @@ ScriptValueP ScriptCustomCollection::getIndex(int index) const {
}
}
ScriptValueP ScriptCustomCollection::makeIterator(const ScriptValueP& thisP) const {
return intrusive(new ScriptCustomCollectionIterator(
static_pointer_cast<ScriptCustomCollection>(thisP)
));
return intrusive(new ScriptCustomCollectionIterator(this, thisP));
}
// ----------------------------------------------------------------------------- : Concat collection
+4 -2
View File
@@ -110,8 +110,10 @@ class ScriptValue : public IntrusivePtrBaseWithDelete {
virtual ScriptValueP simplifyClosure(ScriptClosure&) const;
/// Return an iterator for the current collection, an iterator is a value that has next()
/** thisP can be used to prevent destruction of the collection */
virtual ScriptValueP makeIterator(const ScriptValueP& thisP) const;
/** thisP is a shared_ptr for this collection, needed for the iterator to take ownership of it.
* It can be null if the iterator always lives shorter than the collection.
*/
virtual ScriptValueP makeIterator(const ScriptValueP& thisP = ScriptValueP()) const;
/// Return the next item for this iterator, or ScriptValueP() if there is no such item
/** If key_out != 0, then it will recieve the key of the item */
virtual ScriptValueP next(ScriptValueP* key_out = nullptr);
+4
View File
@@ -185,6 +185,10 @@ void handle_error(const Error& e) {
queue_message(e.is_fatal() ? MESSAGE_FATAL_ERROR : MESSAGE_ERROR, e.what());
}
void handle_error_now(const Error& e) {
queue_message(MESSAGE_FATAL_ERROR, e.what());
}
bool have_queued_message() {
wxMutexLocker lock(crit_error_handling);
return !message_queue.empty();
+3 -1
View File
@@ -156,6 +156,8 @@ enum MessageType
void queue_message(MessageType type, String const& msg);
/// Handle an error by queuing a message
void handle_error(const Error& e);
/// Handle an error by showing a message box
void handle_error_now(const Error& e);
/// Are there any queued messages?
bool have_queued_message();
@@ -170,7 +172,7 @@ String get_stack_trace();
/// Catch all types of errors, and pass then to handle_error
#define CATCH_ALL_ERRORS(handle_now) \
catch (const Error& e) { \
handle_error(e); \
if (handle_now) handle_error_now(e); else handle_error(e); \
} catch (const std::exception& e) { \
/* we don't throw std::exception ourselfs, so this is probably something serious */ \
String message(e.what(), IF_UNICODE(wxConvLocal, wxSTRING_MAXLEN) ); \
+18 -72
View File
@@ -18,77 +18,19 @@
// ----------------------------------------------------------------------------- : Typeof magic
#ifdef __GNUC__
// GCC has a buildin typeof function, so it doesn't need (as much) hacks
#define DECLARE_TYPEOF(T)
#define DECLARE_TYPEOF_NO_REV(T)
#define DECLARE_TYPEOF_CONST(T)
#define DECLARE_TYPEOF_COLLECTION(T)
// GCC has a buildin typeof function, so it doesn't need (as much) hacks
#define DECLARE_TYPEOF(T)
#define DECLARE_TYPEOF_NO_REV(T)
#define DECLARE_TYPEOF_CONST(T)
#define DECLARE_TYPEOF_COLLECTION(T)
#define TYPEOF(Value) __typeof(Value)
#define TYPEOF_IT(Value) __typeof((Value).begin())
#define TYPEOF_CIT(Value) __typeof((Value).begin())
#define TYPEOF_RIT(Value) __typeof((Value).rbegin())
#define TYPEOF_CRIT(Value) __typeof((Value).rbegin())
#define TYPEOF_REF(Value) __typeof(*(Value).begin())&
#define TYPEOF_CREF(Value) __typeof(*(Value).begin())&
#else
/// Helper for typeof tricks
template<const type_info &ref_type_info> struct TypeOf {};
/// The type of a value
#define TYPEOF(Value) TypeOf<typeid(Value)>::type
/// The type of an iterator
#define TYPEOF_IT(Value) TypeOf<typeid(Value)>::iterator
/// The type of a const iterator
#define TYPEOF_CIT(Value) TypeOf<typeid(Value)>::const_iterator
/// The type of a reverse iterator
#define TYPEOF_RIT(Value) TypeOf<typeid(Value)>::reverse_iterator
/// The type of a const reverse iterator
#define TYPEOF_CRIT(Value) TypeOf<typeid(Value)>::const_reverse_iterator
/// The type of a reference
#define TYPEOF_REF(Value) TypeOf<typeid(Value)>::reference
/// The type of a const reference
#define TYPEOF_CREF(Value) TypeOf<typeid(Value)>::const_reference
/// Declare typeof magic for a specific type
#define DECLARE_TYPEOF(T) \
template<> struct TypeOf<typeid(T)> { \
typedef T type; \
typedef T::iterator iterator; \
typedef T::const_iterator const_iterator; \
typedef T::reverse_iterator reverse_iterator; \
typedef T::const_reverse_iterator const_reverse_iterator; \
typedef T::reference reference; \
typedef T::const_reference const_reference; \
}
/// Declare typeof magic for a specific type that doesn't support reverse iterators
#define DECLARE_TYPEOF_NO_REV(T) \
template<> struct TypeOf<typeid(T)> { \
typedef T type; \
typedef T::iterator iterator; \
typedef T::const_iterator const_iterator; \
typedef T::reference reference; \
typedef T::const_reference const_reference; \
}
/// Declare typeof magic for a specific type, using const iterators
#define DECLARE_TYPEOF_CONST(T) \
template<> struct TypeOf<typeid(T)> { \
typedef T type; \
typedef T::const_iterator iterator; \
typedef T::const_iterator const_iterator; \
typedef T::const_reverse_iterator reverse_iterator; \
typedef T::const_reverse_iterator const_reverse_iterator; \
typedef T::const_reference reference; \
typedef T::const_reference const_reference; \
}
/// Declare typeof magic for a specific std::vector type
#define DECLARE_TYPEOF_COLLECTION(T) DECLARE_TYPEOF(vector< T >); \
DECLARE_TYPEOF_CONST(set< T >)
#endif
#define TYPEOF(Value) decltype(Value)
#define TYPEOF_IT(Value) decltype((Value).begin())
#define TYPEOF_CIT(Value) decltype((Value).begin())
#define TYPEOF_RIT(Value) decltype((Value).rbegin())
#define TYPEOF_CRIT(Value) decltype((Value).rbegin())
#define TYPEOF_REF(Value) decltype(*(Value).begin())&
#define TYPEOF_CREF(Value) decltype(*(Value).begin())&
/// Use for template classes
/** i.e.
@@ -151,15 +93,19 @@
/// Iterate over a collection whos type must be declared with DECLARE_TYPEOF
/** Usage: FOR_EACH(e,collect) { body-of-loop }
*/
//#define FOR_EACH(Elem,Collection) \
// FOR_EACH_T(TYPEOF_IT(Collection), TYPEOF_REF(Collection), Elem, Collection, begin, end)
#define FOR_EACH(Elem,Collection) \
FOR_EACH_T(TYPEOF_IT(Collection), TYPEOF_REF(Collection), Elem, Collection, begin, end)
for (auto& Elem : Collection)
/// Iterate over a collection whos type must be declared with DECLARE_TYPEOF
/** Uses a const iterator
* Usage: FOR_EACH_CONST(e,collect) { body-of-loop }
*/
//#define FOR_EACH_CONST(Elem,Collection) \
// FOR_EACH_T(TYPEOF_CIT(Collection), TYPEOF_CREF(Collection), Elem, Collection, begin, end)
#define FOR_EACH_CONST(Elem,Collection) \
FOR_EACH_T(TYPEOF_CIT(Collection), TYPEOF_CREF(Collection), Elem, Collection, begin, end)
for (auto const& Elem : Collection)
/// Iterate over a collection whos type must be declared with DECLARE_TYPEOF
/** Iterates using a reverse_iterator
+1 -14
View File
@@ -154,17 +154,8 @@ void Package::clearKeepFlag() {
// ----------------------------------------------------------------------------- : Package : inside
#if 0
/// Class that is a wxZipInputStream over a wxFileInput stream
/** Note that wxFileInputStream is also a base class, because it must be constructed first
* This class requires a patch in wxWidgets (2.5.4)
* change zipstrm.cpp line 1745:;
* if ((!m_ffile || AtHeader()));
* to:
* if ((AtHeader()));
* It seems that in 2.6.3 this is no longer necessary (TODO: test)
*
* NOTE: Not used with wx 2.6.3, since it doesn't support seeking
*/
class ZipFileInputStream : private wxFileInputStream, public wxZipInputStream {
public:
@@ -175,7 +166,6 @@ class ZipFileInputStream : private wxFileInputStream, public wxZipInputStream {
OpenEntry(*entry);
}
};
#endif
class BufferedFileInputStream_aux {
protected:
@@ -219,10 +209,7 @@ InputStreamP Package::openIn(const String& file) {
stream = shared(new BufferedFileInputStream(filename+_("/")+file));
} else if (wxFileExists(filename) && it != files.end() && it->second.zipEntry) {
// a file in a zip archive
// somebody in wx thought seeking was no longer needed, it now only works with the 'compatability constructor'
stream = shared(new wxZipInputStream(filename, it->second.zipEntry->GetInternalName()));
//stream = static_pointer_cast<wxZipInputStream>(
// shared(new ZipFileInputStream(filename, it->second.zipEntry)));
stream = static_pointer_cast<wxZipInputStream>(shared(new ZipFileInputStream(filename, it->second.zipEntry)));
} else {
// shouldn't happen, packaged changed by someone else since opening it
throw FileNotFoundError(file, filename);
+1 -1
View File
@@ -147,7 +147,7 @@ class Package : public IntrusivePtrVirtualBase {
protected:
// TODO: I dislike putting this here very much. There ought to be a better way.
virtual VCSP getVCS() { return intrusive(new VCS()); }
virtual VCSP getVCS() { return make_shared<VCS>(); }
/// true if this is a zip file, false if a directory
bool isZipfile() const { return !wxDirExists(filename); }
+3 -1
View File
@@ -402,7 +402,9 @@ template <> void Reader::handle(tribool& tb) {
// ----------------------------------------------------------------------------- : Handling less basic util types
template <> void Reader::handle(wxDateTime& date) {
if (!date.ParseDateTime(getValue().c_str())) {
auto str = getValue();
String::const_iterator end;
if (!date.ParseDateTime(str,&end) || end != str.end()) {
throw ParseError(_("Expected a date and time"));
}
}
+1 -1
View File
@@ -209,7 +209,7 @@ template <typename T> void update_index(T&, size_t index) {}
template <typename T>
void Reader::handle(const Char* name, vector<T>& vector) {
String vectorKey = singular_form(name);
while (enterBlock(vectorKey)) {
while (enterBlock(vectorKey.c_str())) {
vector.resize(vector.size() + 1);
handle_greedy(vector.back());
update_index(vector.back(), vector.size() - 1); // update index for IndexMap
+2 -1
View File
@@ -103,8 +103,9 @@ class Writer {
template <typename T>
void Writer::handle(const Char* name, const vector<T>& vec) {
String vectorKey = singular_form(name);
const Char* vectorKeyC = IF_UNICODE(vectorKey.wc_str(), vectorKey.c_str());
for (typename vector<T>::const_iterator it = vec.begin() ; it != vec.end() ; ++it) {
handle(vectorKey, *it);
handle(vectorKeyC, *it);
}
}
+2 -4
View File
@@ -19,6 +19,7 @@
# pragma warning (disable: 4355) // 'this' : used in base member initializer list
# pragma warning (disable: 4800) // 'int' : forcing value to bool 'true' or 'false' (performance warning)
# pragma warning (disable: 4675) // resolved overload was found by argument-dependent lookup (occurs in some boost header)
# define _CRT_NO_VA_START_VALIDATION // fix "va_start argument must not have reference type and must not be parenthesized"
#endif
// ----------------------------------------------------------------------------- : Includes
@@ -31,7 +32,7 @@
#include <wx/datetime.h>
#include <wx/regex.h> // TODO : remove, see regex.hpp
#if defined(__WXMSW__) && defined(__GNUC__)
#if defined(__WXMSW__)
// MSW uses the RGB define, fix it before it's undefined
#include <wx/msw/private.h>
#endif
@@ -87,9 +88,6 @@ typedef wxOutputStream OutputStream;
typedef unsigned char Byte;
typedef unsigned int UInt;
/// Null pointer
#define nullptr 0
/// A string standing for a filename, has different behaviour when reading/writing
class FileName : public wxString {
public:
+4 -7
View File
@@ -16,7 +16,7 @@
void Regex::assign(const String& code) {
// compile string
try {
regex.assign(code.begin(),code.end());
regex.assign(toStdString(code));
} catch (const boost::regex_error& e) {
/// TODO: be more precise
throw ScriptError(String::Format(_("Error while compiling regular expression: '%s'\nAt position: %d\n%s"),
@@ -25,12 +25,9 @@ void Regex::assign(const String& code) {
}
void Regex::replace_all(String* input, const String& format) {
//std::basic_string<Char> fmt; format_string(format,fmt);
std::basic_string<Char> fmt(format.begin(),format.end());
String output;
regex_replace(insert_iterator<String>(output, output.end()),
input->begin(), input->end(), regex, fmt, boost::format_sed);
*input = output;
wxStdString std_string = toStdString(*input);
regex_replace(std_string, regex, toStdString(format), boost::format_sed);
*input = std_string;
}
#else // USE_BOOST_REGEX
+19 -1
View File
@@ -32,6 +32,24 @@
// ----------------------------------------------------------------------------- : Boost implementation
#if USE_BOOST_REGEX
// needed for boost::regex
inline std::size_t hash_value(wxUniChar const& x) {
boost::hash<int> hasher;
return hasher(static_cast<int>(x));
}
/*
// fix: boost regex doesn't like that wxUniChar can't be constructed from an int
namespace boost {
namespace BOOST_REGEX_DETAIL_NS {
inline bool can_start(wxUniChar c, const unsigned char* map, unsigned char mask) {
return can_start(c.GetValue(), map, mask);
}
inline bool can_start(wxUniCharRef c, const unsigned char* map, unsigned char mask) {
return can_start(c.GetValue(), map, mask);
}
}
}*/
/// Our own regular expression wrapper
/** Suppors both boost::regex and wxRegEx.
* Has an interface like boost::regex, but compatible with wxStrings.
@@ -59,7 +77,7 @@
void assign(const String& code);
inline bool matches(const String& str) const {
return regex_search(str.begin(), str.end(), regex);
return regex_search(toStdString(str), regex);
}
inline bool matches(Results& results, const String& str, size_t start = 0) const {
return matches(results, str.begin() + start, str.end());
+22 -114
View File
@@ -14,33 +14,16 @@
// ----------------------------------------------------------------------------- : Includes
#include <util/atomic.hpp>
#ifdef HAVE_FAST_ATOMIC
/// Using intrusive_ptr where possible? (as opposed to smart_ptr)
#define USE_INTRUSIVE_PTR
#endif
#include <memory>
// Use slightly less fancy template stuff, so msvc7.1 doesn't crash with an internal compiler error
#define BOOST_SP_NO_SP_CONVERTIBLE
using std::shared_ptr;
using std::unique_ptr;
using std::static_pointer_cast;
using std::dynamic_pointer_cast;
using std::make_shared;
#include <boost/shared_ptr.hpp>
#include <boost/scoped_ptr.hpp>
#ifdef USE_INTRUSIVE_PTR
#include <boost/intrusive_ptr.hpp>
#endif
// Can't do using namespace boost;
// because boost::shared_ptr conflicts with std::tr1::shared_ptr
// and some boost headers do include boost/shared_ptr themselves
#if _HAS_TR1
using std::tr1::shared_ptr;
#else
using boost::shared_ptr;
#endif
using boost::intrusive_ptr;
using boost::scoped_ptr;
using boost::static_pointer_cast;
using boost::dynamic_pointer_cast;
// TODO: remove scoped_ptr
template <typename T> using scoped_ptr = unique_ptr<T>;
// ----------------------------------------------------------------------------- : Declaring
@@ -56,80 +39,30 @@ using boost::dynamic_pointer_cast;
* return shared(new T(stuff)));
*/
template <typename T>
//[[deprecated("use make_shared")]]
inline shared_ptr<T> shared(T* ptr) {
return shared_ptr<T>(ptr);
}
template <typename T>
//[[deprecated("use make_shared")]]
inline shared_ptr<T> intrusive(T* ptr) {
return shared_ptr<T>(ptr);
}
// ----------------------------------------------------------------------------- : Intrusive pointers
#ifdef USE_INTRUSIVE_PTR
#define DECLARE_POINTER_TYPE DECLARE_SHARED_POINTER_TYPE
#define intrusive_ptr shared_ptr
/// Declares the type TypeP as a intrusive_ptr<Type>
#define DECLARE_POINTER_TYPE(Type) \
class Type; \
typedef intrusive_ptr<Type> Type##P;
template <typename T> class IntrusivePtrBase {};
/// Wrap a newly allocated pointer in an intrusive_ptr
/** Usage:
* return intrusive(new T(stuff)));
*/
template <typename T>
inline intrusive_ptr<T> intrusive(T* ptr) {
return intrusive_ptr<T>(ptr);
}
// ----------------------------------------------------------------------------- : Intrusive pointer base
template <typename T> class IntrusivePtrBase;
template <typename T> void intrusive_ptr_add_ref(IntrusivePtrBase<T>*);
template <typename T> void intrusive_ptr_release(IntrusivePtrBase<T>*);
/// Base class for objects wishing to use intrusive_ptrs.
/** There is no implicit virtual destructor, objects are destructed as type T
* Usage:
* @code
* DECLARE_POINTER_TYPE(MyClass);
* class MyClass : public IntrusivePtrBase<MyClass> { ... }
* @endcode
*/
template <typename T> class IntrusivePtrBase {
public:
inline IntrusivePtrBase() : ref_count(0) {}
// don't copy construct the reference count!
inline IntrusivePtrBase(const IntrusivePtrBase&) : ref_count(0) {}
// don't assign the reference count!
inline void operator = (const IntrusivePtrBase&) { }
protected:
/// Delete this object, can be overloaded
inline void destroy() {
delete static_cast<T*>(this);
}
private:
AtomicInt ref_count;
friend void intrusive_ptr_add_ref <> (IntrusivePtrBase*);
friend void intrusive_ptr_release <> (IntrusivePtrBase*);
};
template <typename T> void intrusive_ptr_add_ref(IntrusivePtrBase<T>* p) {
++(p->ref_count);
}
template <typename T> void intrusive_ptr_release(IntrusivePtrBase<T>* p) {
if (--p->ref_count == 0) {
static_cast<T*>(p)->destroy();
}
}
// ----------------------------------------------------------------------------- : Intrusive pointer base : virtual
/// IntrusivePtrBase with a virtual destructor
class IntrusivePtrVirtualBase : public IntrusivePtrBase<IntrusivePtrVirtualBase> {
/// IntrusivePtrBase with a virtual destructor
class IntrusivePtrVirtualBase : public IntrusivePtrBase<IntrusivePtrVirtualBase> {
public:
virtual ~IntrusivePtrVirtualBase() {}
};
};
// ----------------------------------------------------------------------------- : Intrusive pointer base : with delete
/// Base class for objects wishing to use intrusive_ptrs, using a manual delete function
class IntrusivePtrBaseWithDelete : public IntrusivePtrBase<IntrusivePtrBaseWithDelete> {
class IntrusivePtrBaseWithDelete : public IntrusivePtrBase<IntrusivePtrBaseWithDelete> {
public:
virtual ~IntrusivePtrBaseWithDelete() {}
protected:
@@ -137,32 +70,7 @@ inline shared_ptr<T> shared(T* ptr) {
virtual void destroy() {
delete this;
}
template <typename T> friend void intrusive_ptr_release(IntrusivePtrBase<T>*);
};
#else
#define DECLARE_POINTER_TYPE DECLARE_SHARED_POINTER_TYPE
#define intrusive_ptr shared_ptr
template <typename T> class IntrusivePtrBase {};
/// IntrusivePtrBase with a virtual destructor
class IntrusivePtrVirtualBase : public IntrusivePtrBase<IntrusivePtrVirtualBase> {
public:
virtual ~IntrusivePtrVirtualBase() {}
};
class IntrusivePtrBaseWithDelete : public IntrusivePtrBase<IntrusivePtrBaseWithDelete> {
public:
virtual ~IntrusivePtrBaseWithDelete() {}
protected:
/// Delete this object
virtual void destroy() {
delete this;
}
};
#endif
};
/// Pointer to 'anything'
typedef intrusive_ptr<IntrusivePtrVirtualBase> VoidP;
+10 -2
View File
@@ -28,6 +28,14 @@ typedef wxString String;
DECLARE_TYPEOF_NO_REV(String); // iterating over characters in a string
inline wxStdString const& toStdString(String const& s) {
#if wxUSE_UNICODE_WCHAR
return s.ToStdWstring();
#else
return s.ToStdString();
#endif
}
// ----------------------------------------------------------------------------- : Unicode
/// u if UNICODE is defined, a otherwise
@@ -42,7 +50,7 @@ DECLARE_TYPEOF_NO_REV(String); // iterating over characters in a string
#define _(S) IF_UNICODE(BOOST_PP_CAT(L,S), S)
/// The character type used
typedef IF_UNICODE(wchar_t, char) Char;
typedef wxChar Char;
/// Decode a UTF8 string
/** In non-unicode builds the input is considered to be an incorrectly encoded utf8 string.
@@ -55,7 +63,7 @@ String decodeUTF8BOM(const String& s);
/** In non-unicode builds it is UTF8 encoded \xFEFF.
* In unicode builds it is a normal \xFEFF.
*/
const Char BYTE_ORDER_MARK[] = IF_UNICODE(L"\xFEFF", "\xEF\xBB\xBF");
const Char BYTE_ORDER_MARK[] = L"\xFEFF";
/// Writes a string to an output stream, encoded as UTF8
void writeUTF8(wxTextOutputStream& stream, const String& str);