Commit 7df019db authored by twanvl's avatar twanvl

default smart pointer type switched to intrusive_ptr

parent 42e66d0d
......@@ -9,6 +9,7 @@
#include <data/action/set.hpp>
#include <data/set.hpp>
#include <data/card.hpp>
#include <data/stylesheet.hpp>
#include <util/error.hpp>
// ----------------------------------------------------------------------------- : Add card
......@@ -89,6 +90,9 @@ void DisplayChangeAction::perform(bool to_undo) {
}
ChangeCardStyleAction::ChangeCardStyleAction(const CardP& card, const StyleSheetP& stylesheet)
: card(card), stylesheet(stylesheet)
{}
String ChangeCardStyleAction::getName(bool to_undo) const {
return _("Change style");
}
......@@ -97,6 +101,9 @@ void ChangeCardStyleAction::perform(bool to_undo) {
}
ChangeSetStyleAction::ChangeSetStyleAction(Set& set, const CardP& card)
: set(set), card(card)
{}
String ChangeSetStyleAction::getName(bool to_undo) const {
return _("Change style (all cards)");
}
......
......@@ -87,8 +87,7 @@ class DisplayChangeAction : public Action {
/// Changing the style of a a card
class ChangeCardStyleAction : public DisplayChangeAction {
public:
ChangeCardStyleAction(const CardP& card, const StyleSheetP& stylesheet)
: card(card), stylesheet(stylesheet) {}
ChangeCardStyleAction(const CardP& card, const StyleSheetP& stylesheet);
virtual String getName(bool to_undo) const;
virtual void perform(bool to_undo);
......@@ -101,8 +100,7 @@ class ChangeCardStyleAction : public DisplayChangeAction {
/// Changing the style of a set to that of a card
class ChangeSetStyleAction : public DisplayChangeAction {
public:
ChangeSetStyleAction(Set& set, const CardP& card)
: set(set), card(card) {}
ChangeSetStyleAction(Set& set, const CardP& card);
virtual String getName(bool to_undo) const;
virtual void perform(bool to_undo);
......
......@@ -289,7 +289,7 @@ double ssqrt(double x) {
}
// Remove a single control point
class SinglePointRemoveAction : public Action {
class SinglePointRemoveAction : public Action, public IntrusivePtrBase<SinglePointRemoveAction> {
public:
SinglePointRemoveAction(const SymbolPartP& part, UInt position);
......@@ -393,7 +393,7 @@ ControlPointRemoveAction::ControlPointRemoveAction(const SymbolPartP& part, cons
FOR_EACH(point, part->points) {
if (toDelete.find(point) != toDelete.end()) {
// remove this point
removals.push_back(new_shared2<SinglePointRemoveAction>(part, index));
removals.push_back(new_intrusive2<SinglePointRemoveAction>(part, index));
}
++index;
}
......@@ -417,7 +417,7 @@ void ControlPointRemoveAction::perform(bool to_undo) {
Action* controlPointRemoveAction(const SymbolPartP& part, const set<ControlPointP>& toDelete) {
if (part->points.size() - toDelete.size() < 2) {
// TODO : remove part?
//new_shared<ControlPointRemoveAllAction>(part);
//new_intrusive<ControlPointRemoveAllAction>(part);
return 0; // no action
} else {
return new ControlPointRemoveAction(part, toDelete);
......
......@@ -36,7 +36,7 @@ inline void swap_value(TextValue& a, TextValue ::ValueType& b
template <typename T, bool ALLOW_MERGE>
class SimpleValueAction : public ValueAction {
public:
inline SimpleValueAction(const shared_ptr<T>& value, const typename T::ValueType& new_value)
inline SimpleValueAction(const intrusive_ptr<T>& value, const typename T::ValueType& new_value)
: ValueAction(value), new_value(new_value)
{}
......
......@@ -8,6 +8,7 @@
#include <data/card.hpp>
#include <data/game.hpp>
#include <data/stylesheet.hpp>
#include <data/field.hpp>
#include <util/error.hpp>
#include <util/reflect.hpp>
......
......@@ -24,7 +24,7 @@ DECLARE_POINTER_TYPE(StyleSheet);
// ----------------------------------------------------------------------------- : Card
/// A card from a card Set
class Card {
class Card : public IntrusivePtrVirtualBase {
public:
/// Default constructor, uses game_for_new_cards to make the game
Card();
......
......@@ -61,18 +61,18 @@ IMPLEMENT_REFLECTION(Field) {
}
template <>
shared_ptr<Field> read_new<Field>(Reader& reader) {
intrusive_ptr<Field> read_new<Field>(Reader& reader) {
// there must be a type specified
String type;
reader.handle(_("type"), type);
if (type == _("text")) return new_shared<TextField>();
else if (type == _("choice")) return new_shared<ChoiceField>();
else if (type == _("multiple choice")) return new_shared<MultipleChoiceField>();
else if (type == _("boolean")) return new_shared<BooleanField>();
else if (type == _("image")) return new_shared<ImageField>();
else if (type == _("symbol")) return new_shared<SymbolField>();
else if (type == _("color")) return new_shared<ColorField>();
else if (type == _("info")) return new_shared<InfoField>();
if (type == _("text")) return new_intrusive<TextField>();
else if (type == _("choice")) return new_intrusive<ChoiceField>();
else if (type == _("multiple choice")) return new_intrusive<MultipleChoiceField>();
else if (type == _("boolean")) return new_intrusive<BooleanField>();
else if (type == _("image")) return new_intrusive<ImageField>();
else if (type == _("symbol")) return new_intrusive<SymbolField>();
else if (type == _("color")) return new_intrusive<ColorField>();
else if (type == _("info")) return new_intrusive<InfoField>();
else {
throw ParseError(_("Unsupported field type: '") + type + _("'"));
}
......
......@@ -32,7 +32,7 @@ DECLARE_POINTER_TYPE(ValueEditor);
// ----------------------------------------------------------------------------- : Field
/// Information on how to store a value
class Field {
class Field : public IntrusivePtrVirtualBase {
public:
Field();
virtual ~Field();
......@@ -71,7 +71,7 @@ class Field {
};
template <>
shared_ptr<Field> read_new<Field>(Reader& reader);
intrusive_ptr<Field> read_new<Field>(Reader& reader);
inline void update_index(FieldP& f, size_t index) {
f->index = index;
}
......@@ -79,7 +79,7 @@ inline void update_index(FieldP& f, size_t index) {
// ----------------------------------------------------------------------------- : Style
/// Style information needed to display a Value in a Field.
class Style {
class Style : public IntrusivePtrVirtualBase {
public:
Style(const FieldP&);
virtual ~Style();
......@@ -134,7 +134,7 @@ template <> StyleP read_new<Style>(Reader&);
// ----------------------------------------------------------------------------- : StyleListener
/// An object that can respond when a style changes;
class StyleListener {
class StyleListener : public IntrusivePtrVirtualBase {
public:
StyleListener(const StyleP& style);
virtual ~StyleListener();
......@@ -148,7 +148,7 @@ class StyleListener {
// ----------------------------------------------------------------------------- : Value
/// A specific value 'in' a Field.
class Value {
class Value : public IntrusivePtrVirtualBase {
public:
inline Value(const FieldP& field) : fieldP(field) {}
virtual ~Value();
......@@ -189,14 +189,14 @@ template <> ValueP read_new<Value>(Reader&);
#define IMPLEMENT_FIELD_TYPE(Type) \
StyleP Type ## Field::newStyle(const FieldP& thisP) const { \
assert(thisP.get() == this); \
return new_shared1<Type ## Style>(static_pointer_cast<Type ## Field>(thisP)); \
return new_intrusive1<Type ## Style>(static_pointer_cast<Type ## Field>(thisP));\
} \
ValueP Type ## Field::newValue(const FieldP& thisP) const { \
assert(thisP.get() == this); \
return new_shared1<Type ## Value>(static_pointer_cast<Type ## Field>(thisP)); \
return new_intrusive1<Type ## Value>(static_pointer_cast<Type ## Field>(thisP));\
} \
StyleP Type ## Style::clone() const { \
return new_shared1<Type ## Style>(*this); \
return new_intrusive1<Type ## Style>(*this); \
}
#define DECLARE_STYLE_TYPE(Type) \
......
......@@ -11,8 +11,8 @@
// ----------------------------------------------------------------------------- : BooleanField
BooleanField::BooleanField() {
choices->choices.push_back(new_shared1<Choice>(_("yes")));
choices->choices.push_back(new_shared1<Choice>(_("no")));
choices->choices.push_back(new_intrusive1<Choice>(_("yes")));
choices->choices.push_back(new_intrusive1<Choice>(_("no")));
choices->initIds();
}
......
......@@ -30,7 +30,7 @@ class ChoiceField : public Field {
DECLARE_FIELD_TYPE(Choice);
class Choice;
typedef shared_ptr<Choice> ChoiceP;
typedef intrusive_ptr<Choice> ChoiceP;
ChoiceP choices; ///< A choice group of possible choices
OptionalScript script; ///< Script to apply to all values
......@@ -47,7 +47,7 @@ class ChoiceField : public Field {
};
/// An item that can be chosen for this field
class ChoiceField::Choice {
class ChoiceField::Choice : public IntrusivePtrBase<ChoiceField::Choice> {
public:
Choice();
Choice(const String& name);
......
......@@ -27,7 +27,7 @@ class ColorField : public Field {
DECLARE_FIELD_TYPE(Color);
class Choice;
typedef shared_ptr<Choice> ChoiceP;
typedef intrusive_ptr<Choice> ChoiceP;
OptionalScript script; ///< Script to apply to all values
OptionalScript default_script; ///< Script that generates the default value
......@@ -42,7 +42,7 @@ class ColorField : public Field {
};
/// A color that can be chosen for this field
class ColorField::Choice {
class ColorField::Choice : public IntrusivePtrBase<ColorField::Choice> {
public:
String name; ///< Name of the color
Color color; ///< The actual color
......
......@@ -32,8 +32,9 @@ IMPLEMENT_REFLECTION(SymbolStyle) {
SymbolVariation::SymbolVariation()
: border_radius(0.05)
{}
SymbolVariation::~SymbolVariation() {}
IMPLEMENT_REFLECTION(SymbolVariation) {
IMPLEMENT_REFLECTION_NO_SCRIPT(SymbolVariation) {
REFLECT(name);
REFLECT(border_radius);
REFLECT_NAMELESS(filter);
......
......@@ -47,9 +47,10 @@ class SymbolStyle : public Style {
};
/// Styling for a symbol variation, defines color, border, etc.
class SymbolVariation {
class SymbolVariation : public IntrusivePtrBase<SymbolVariation> {
public:
SymbolVariation();
~SymbolVariation();
String name; ///< Name of this variation
SymbolFilterP filter; ///< Filter to color the symbol
double border_radius; ///< Border radius for the symbol
......
......@@ -48,7 +48,7 @@ class TextField : public Field {
// ----------------------------------------------------------------------------- : TextStyle
/// Background behind text
class TextBackground {
class TextBackground : public IntrusivePtrBase<TextBackground> {
public:
ScriptableImage image; ///< background image, stretched to text size
RealSize displacement;
......
......@@ -79,7 +79,7 @@ wxFont Font::toWxFont(double scale) const {
}
}
IMPLEMENT_REFLECTION(Font) {
IMPLEMENT_REFLECTION_NO_SCRIPT(Font) {
REFLECT(name);
REFLECT(size);
REFLECT(weight);
......
......@@ -19,7 +19,7 @@ DECLARE_POINTER_TYPE(Font);
/// A font for rendering text
/** Contains additional information about scaling, color and shadow */
class Font {
class Font : public IntrusivePtrBase<Font> {
public:
Scriptable<String> name; ///< Name of the font
Scriptable<String> italic_name; ///< Font name for italic text (optional)
......
......@@ -383,7 +383,7 @@ class ApprCardDatabase : public ApprDatabase {
/** Each card has two records, a data record at the top of the file
* and a head record at the bottom
*/
class ApprCardRecord {
class ApprCardRecord : public IntrusivePtrBase<ApprCardRecord> {
public:
String name, sets;
String type, cc, pt, text, flavor;
......@@ -536,7 +536,7 @@ void ApprCardDatabase::doRead(wxInputStream& in) {
progress_target->onProgress(0.4f * float(i) / cards.size(),
String(_("reading card ")) << i << _(" of ") << (int)cards.size());
}
card = new_shared<ApprCardRecord>();
card = new_intrusive<ApprCardRecord>();
card->readHead(data);
head_pos = in.TellI();
in.SeekI(card->data_pos);
......@@ -751,7 +751,7 @@ bool ApprenticeExportWindow::exportSet() {
cardlist.removeSet(set->apprentice_code);
// add cards from set
FOR_EACH(card, set->cards) {
ApprCardRecordP rec = new_shared2<ApprCardRecord>(*card, set->apprentice_code);
ApprCardRecordP rec = new_intrusive2<ApprCardRecord>(*card, set->apprentice_code);
cardlist.cards.push_back(rec);
}
cardlist.write();
......
......@@ -20,7 +20,7 @@ DECLARE_POINTER_TYPE(FileFormat);
// ----------------------------------------------------------------------------- : FileFormat
/// A filter for a specific file format
class FileFormat {
class FileFormat : public IntrusivePtrVirtualBase {
public:
virtual ~FileFormat() {}
/// File extension used by this file format
......
......@@ -24,10 +24,8 @@ Bitmap export_bitmap(const SetP& set, const CardP& card) {
DataViewer viewer;
viewer.setSet(set);
viewer.setCard(card);
// style to use
StyleSheetP style = set->stylesheetFor(card);
// size of cards
if (settings.stylesheetSettingsFor(*style).card_normal_export()) {
if (settings.stylesheetSettingsFor(set->stylesheetFor(card)).card_normal_export()) {
// TODO
// viewer.rotation.angle = 0;
// viewer.rotation.zoom = 1.0;
......
......@@ -179,7 +179,7 @@ SymbolPartP read_symbol_part(const ImageData& data) {
}
// add to part and place a mark
part->points.push_back(new_shared2<ControlPoint>(
part->points.push_back(new_intrusive2<ControlPoint>(
double(x) / data.width,
double(y) / data.height
));
......
......@@ -29,7 +29,7 @@ class MSE1FileFormat : public FileFormat {
};
FileFormatP mse1_file_format() {
return new_shared<MSE1FileFormat>();
return new_intrusive<MSE1FileFormat>();
}
// ----------------------------------------------------------------------------- : Importing
......
......@@ -33,5 +33,5 @@ class MSE2FileFormat : public FileFormat {
};
FileFormatP mse2_file_format() {
return new_shared<MSE2FileFormat>();
return new_intrusive<MSE2FileFormat>();
}
......@@ -43,7 +43,7 @@ class MtgEditorFileFormat : public FileFormat {
};
FileFormatP mtg_editor_file_format() {
return new_shared<MtgEditorFileFormat>();
return new_intrusive<MtgEditorFileFormat>();
}
// ----------------------------------------------------------------------------- : Importing
......@@ -68,7 +68,7 @@ SetP MtgEditorFileFormat::importSet(const String& filename) {
// read file
while (!f.Eof()) {
// read a line
if (!current_card) current_card = new_shared1<Card>(*set->game);
if (!current_card) current_card = new_intrusive1<Card>(*set->game);
String line = file.ReadLine();
if (line == _("#SET###########")) { // set.title
target = &set->value<TextValue>(_("title")).value;
......@@ -103,7 +103,7 @@ SetP MtgEditorFileFormat::importSet(const String& filename) {
set->cards.push_back(current_card);
}
first = false;
current_card = new_shared1<Card>(*set->game);
current_card = new_intrusive1<Card>(*set->game);
target = &current_card->value<TextValue>(_("name")).value;
} else if (line == _("#DATE##########")) { // date
// remember date for generation of illustration filename
......
......@@ -39,20 +39,20 @@ String Game::typeName() const { return _("game"); }
IMPLEMENT_REFLECTION(Game) {
REFLECT_BASE(Packaged);
REFLECT(init_script);
REFLECT(set_fields);
REFLECT_NO_SCRIPT(init_script);
REFLECT_NO_SCRIPT(set_fields);
REFLECT_IF_READING {
default_set_style.init(set_fields);
}
REFLECT(default_set_style);
REFLECT(card_fields);
REFLECT(statistics_dimensions);
REFLECT(statistics_categories);
REFLECT(pack_types);
REFLECT_NO_SCRIPT(default_set_style);
REFLECT_NO_SCRIPT(card_fields);
REFLECT_NO_SCRIPT(statistics_dimensions);
REFLECT_NO_SCRIPT(statistics_categories);
REFLECT_NO_SCRIPT(pack_types);
REFLECT(has_keywords);
REFLECT(keyword_modes);
REFLECT(keyword_parameter_types);
REFLECT(keywords);
REFLECT_NO_SCRIPT(keywords);
// REFLECT(word_lists);
}
......@@ -63,7 +63,7 @@ void Game::validate(Version v) {
vector<StatsDimensionP> dims;
FOR_EACH(f, card_fields) {
if (f->show_statistics) {
dims.push_back(new_shared1<StatsDimension>(*f));
dims.push_back(new_intrusive1<StatsDimension>(*f));
}
}
statistics_dimensions.insert(statistics_dimensions.begin(), dims.begin(), dims.end()); // push front
......@@ -72,7 +72,7 @@ void Game::validate(Version v) {
{
vector<StatsCategoryP> cats;
FOR_EACH(dim, statistics_dimensions) {
cats.push_back(new_shared1<StatsCategory>(dim));
cats.push_back(new_intrusive1<StatsCategory>(dim));
}
statistics_categories.insert(statistics_categories.begin(), cats.begin(), cats.end()); // push front
}
......
......@@ -21,7 +21,7 @@ class KeywordTrie;
// ----------------------------------------------------------------------------- : Keyword parameters
class ParamReferenceType {
class ParamReferenceType : public IntrusivePtrBase<ParamReferenceType> {
public:
String name; ///< Name of the parameter reference type
String description; ///< Description (for status bar)
......@@ -31,7 +31,7 @@ class ParamReferenceType {
};
/// Parameter type of keywords
class KeywordParam {
class KeywordParam : public IntrusivePtrBase<KeywordParam> {
public:
KeywordParam();
String name; ///< Name of the parameter type
......@@ -49,7 +49,7 @@ class KeywordParam {
// ----------------------------------------------------------------------------- : Keyword mode
/// Information on when and how to use a keyword
class KeywordMode {
class KeywordMode : public IntrusivePtrBase<KeywordMode> {
public:
KeywordMode() : is_default(false) {}
......@@ -63,7 +63,7 @@ class KeywordMode {
// ----------------------------------------------------------------------------- : Keyword expansion
/// A keyword for a set or a game
class Keyword {
class Keyword : public IntrusivePtrVirtualBase {
public:
Keyword() : fixed(false), valid(false) {}
......
......@@ -23,7 +23,7 @@ LocaleP Locale::byName(const String& name) {
return packages.open<Locale>(name + _(".mse-locale"));
}
IMPLEMENT_REFLECTION(Locale) {
IMPLEMENT_REFLECTION_NO_SCRIPT(Locale) {
REFLECT_BASE(Packaged);
REFLECT_N("menu", translations[LOCALE_CAT_MENU]);
REFLECT_N("help", translations[LOCALE_CAT_HELP]);
......@@ -40,7 +40,7 @@ IMPLEMENT_REFLECTION(Locale) {
REFLECT_N("symbol font", symbol_font_translations);
}
IMPLEMENT_REFLECTION_NAMELESS(SubLocale) {
IMPLEMENT_REFLECTION_NO_GET_MEMBER(SubLocale) {
REFLECT_NAMELESS(translations);
}
......
......@@ -20,7 +20,7 @@ DECLARE_POINTER_TYPE(SubLocale);
// ----------------------------------------------------------------------------- : Locale class
/// Translations of the texts of a game/stylesheet/symbolfont
class SubLocale {
class SubLocale : public IntrusivePtrBase<SubLocale> {
public:
map<String,String> translations;
......
......@@ -20,7 +20,7 @@ class Set;
// ----------------------------------------------------------------------------- : PackType
/// A card pack description for playtesting
class PackType {
class PackType : public IntrusivePtrBase<PackType> {
public:
PackType();
......@@ -38,7 +38,7 @@ class PackType {
// ----------------------------------------------------------------------------- : CardType
/// A card type description for playtesting
class CardType {
class CardType : public IntrusivePtrBase<CardType> {
public:
String name; ///< Name of this type of cards
Scriptable<int> amount; ///< Number of cards of this type
......
......@@ -79,7 +79,11 @@ Context& Set::getContextForThumbnails(const StyleSheetP& stylesheet) {
return thumbnail_script_context->getContext(stylesheet);
}
StyleSheetP Set::stylesheetFor(const CardP& card) {
const StyleSheet& Set::stylesheetFor(const CardP& card) {
if (card && card->stylesheet) return *card->stylesheet;
else return *stylesheet;
}
StyleSheetP Set::stylesheetForP(const CardP& card) {
if (card && card->stylesheet) return card->stylesheet;
else return stylesheet;
}
......@@ -122,7 +126,7 @@ void Set::validate(Version file_app_version) {
}
*/ }
// we want at least one card
if (cards.empty()) cards.push_back(new_shared1<Card>(*game));
if (cards.empty()) cards.push_back(new_intrusive1<Card>(*game));
// update scripts
script_manager->updateAll();
}
......@@ -187,7 +191,7 @@ int Set::positionOfCard(const CardP& card, const ScriptValueP& order_by) {
values.push_back(*order_by->eval(getContext(c)));
}
// 2. initialize order cache
order.reset(new OrderCache<CardP>(cards, values));
order = new_intrusive2<OrderCache<CardP> >(cards, values);
}
return order->find(card);
}
......@@ -199,7 +203,7 @@ void Set::clearOrderCache() {
// Extra set data, for a specific stylesheet
/* The data is not read immediatly, because we do not know the stylesheet */
class Set::Styling {
class Set::Styling : public IntrusivePtrBase<Set::Styling> {
public:
IndexMap<FieldP, ValueP> data;
String unread_data;
......@@ -209,7 +213,7 @@ class Set::Styling {
IndexMap<FieldP, ValueP>& Set::stylingDataFor(const StyleSheet& stylesheet) {
StylingP& styling = styling_data[stylesheet.name()];
if (!styling) {
styling = new_shared<Styling>();
styling = new_intrusive<Styling>();
styling->data.init(stylesheet.styling_fields);
} else if (!styling->unread_data.empty() || (styling->data.empty()) && !stylesheet.styling_fields.empty()) {
// we delayed the reading of the data, read it now
......
......@@ -25,13 +25,13 @@ DECLARE_POINTER_TYPE(Styling);
DECLARE_POINTER_TYPE(Field);
DECLARE_POINTER_TYPE(Value);
DECLARE_POINTER_TYPE(Keyword);
DECLARE_INTRUSIVE_POINTER_TYPE(ScriptValue);
DECLARE_POINTER_TYPE(ScriptValue);
class SetScriptManager;
class SetScriptContext;
class Context;
class Dependency;
template <typename> class OrderCache;
typedef shared_ptr<OrderCache<CardP> > OrderCacheP;
typedef intrusive_ptr<OrderCache<CardP> > OrderCacheP;
// ----------------------------------------------------------------------------- : Set
......@@ -80,7 +80,8 @@ class Set : public Packaged {
/// Stylesheet to use for a particular card
/** card may be null */
StyleSheetP stylesheetFor(const CardP& card);
const StyleSheet& stylesheetFor (const CardP& card);
StyleSheetP stylesheetForP(const CardP& card);
/// Styling information for a particular stylesheet
IndexMap<FieldP, ValueP>& stylingDataFor(const StyleSheet&);
......
......@@ -125,7 +125,7 @@ void Settings::addRecentFile(const String& filename) {
GameSettings& Settings::gameSettingsFor(const Game& game) {
GameSettingsP& gs = game_settings[game.name()];
if (!gs) gs.reset(new GameSettings);
if (!gs) gs = new_intrusive<GameSettings>();
return *gs;
}
ColumnSettings& Settings::columnSettingsFor(const Game& game, const Field& field) {
......@@ -143,7 +143,7 @@ ColumnSettings& Settings::columnSettingsFor(const Game& game, const Field& field
}
StyleSheetSettings& Settings::stylesheetSettingsFor(const StyleSheet& stylesheet) {
StyleSheetSettingsP& ss = stylesheet_settings[stylesheet.name()];
if (!ss) ss.reset(new StyleSheetSettings);
if (!ss) ss = new_intrusive<StyleSheetSettings>();
ss->useDefault(default_stylesheet_settings); // update default settings
return *ss;
}
......
......@@ -49,7 +49,7 @@ class ColumnSettings {
};
/// Settings for a Game
class GameSettings {
class GameSettings : public IntrusivePtrBase<GameSettings> {
public:
GameSettings();
......@@ -65,7 +65,7 @@ class GameSettings {
};
/// Settings for a StyleSheet
class StyleSheetSettings {
class StyleSheetSettings : public IntrusivePtrBase<StyleSheetSettings> {
public:
StyleSheetSettings();
......
......@@ -38,7 +38,7 @@ StatsDimension::StatsDimension(const Field& field)
s.addInstruction(I_RET);
}
IMPLEMENT_REFLECTION(StatsDimension) {
IMPLEMENT_REFLECTION_NO_GET_MEMBER(StatsDimension) {
if (!automatic) {
REFLECT(name);
REFLECT(description);
......@@ -72,7 +72,7 @@ IMPLEMENT_REFLECTION_ENUM(GraphType) {
VALUE_N("scatter", GRAPH_TYPE_SCATTER);
}
IMPLEMENT_REFLECTION(StatsCategory) {
IMPLEMENT_REFLECTION_NO_GET_MEMBER(StatsCategory) {
if (!automatic) {
REFLECT(name);
REFLECT(description);
......
......@@ -21,7 +21,7 @@ DECLARE_POINTER_TYPE(StatsCategory);
/// A dimension that can be plotted as an axis in a graph
/** Dimensions can be generated automatically based on card fields */
class StatsDimension {
class StatsDimension : public IntrusivePtrBase<StatsDimension> {
public:
StatsDimension();
StatsDimension(const Field&);
......@@ -49,7 +49,7 @@ enum GraphType
/// A category for statistics
/** Can be generated automatically based on a dimension */
class StatsCategory {
class StatsCategory : public IntrusivePtrBase<StatsCategory> {
public:
StatsCategory();
StatsCategory(const StatsDimensionP&);
......
......@@ -131,10 +131,10 @@ SymbolPart::SymbolPart()
{}
SymbolPartP SymbolPart::clone() const {
SymbolPartP part = new_shared1<SymbolPart>(*this);
SymbolPartP part = new_intrusive1<SymbolPart>(*this);
// also clone the control points
FOR_EACH(p, part->points) {
p = new_shared1<ControlPoint>(*p);
p = new_intrusive1<ControlPoint>(*p);
}
return part;
}
......@@ -166,18 +166,18 @@ IMPLEMENT_REFLECTION(Symbol) {
// A default symbol part, a square, moved by d
SymbolPartP default_symbol_part(double d) {
SymbolPartP part = new_shared<SymbolPart>();
part->points.push_back(new_shared2<ControlPoint>(d + .2, d + .2));
part->points.push_back(new_shared2<ControlPoint>(d + .2, d + .8));
part->points.push_back(new_shared2<ControlPoint>(d + .8, d + .8));
part->points.push_back(new_shared2<ControlPoint>(d + .8, d + .2));
SymbolPartP part = new_intrusive<SymbolPart>();
part->points.push_back(new_intrusive2<ControlPoint>(d + .2, d + .2));
part->points.push_back(new_intrusive2<ControlPoint>(d + .2, d + .8));
part->points.push_back(new_intrusive2<ControlPoint>(d + .8, d + .8));
part->points.push_back(new_intrusive2<ControlPoint>(d + .8, d + .2));
part->name = _("Square");
return part;
}
// A default symbol, a square
SymbolP default_symbol() {
SymbolP symbol = new_shared<Symbol>();
SymbolP symbol = new_intrusive<Symbol>();
symbol->parts.push_back(default_symbol_part(0));
return symbol;
}
......
......@@ -44,7 +44,7 @@ enum WhichHandle
};
/// A control point (corner) of a SymbolPart (polygon/bezier-gon)
class ControlPoint {
class ControlPoint : public IntrusivePtrBase<ControlPoint> {
public:
Vector2D pos; ///< position of the control point itself
Vector2D delta_before; ///< delta to bezier control point, for curve before point
......@@ -121,7 +121,7 @@ inline size_t mod(int a, size_t size) {
}
/// A single part (polygon/bezier-gon) in a Symbol
class SymbolPart {
class SymbolPart : public IntrusivePtrBase<SymbolPart> {
public:
/// The points of this polygon
vector<ControlPointP> points;
......@@ -158,7 +158,7 @@ class SymbolPart {
// ----------------------------------------------------------------------------- : Symbol
/// An editable symbol, consists of any number of SymbolParts
class Symbol {
class Symbol : public IntrusivePtrBase<Symbol> {
public:
/// The parts of this symbol
vector<SymbolPartP> parts;
......
......@@ -70,7 +70,7 @@ IMPLEMENT_REFLECTION(SymbolFont) {
// ----------------------------------------------------------------------------- : SymbolInFont
/// A symbol in a symbol font
class SymbolInFont {
class SymbolInFont : public IntrusivePtrBase<SymbolInFont> {
public:
SymbolInFont();
......
......@@ -111,7 +111,7 @@ enum MenuItemType
};
/// Description of a menu to insert symbols from a symbol font into the text
class InsertSymbolMenu {
class InsertSymbolMenu : public IntrusivePtrBase<InsertSymbolMenu> {
public:
InsertSymbolMenu();
......
......@@ -138,6 +138,11 @@ bool BuiltInImage::operator == (const GeneratedImage& that) const {
// ----------------------------------------------------------------------------- : SymbolToImage
SymbolToImage::SymbolToImage(const String& filename, Age age, const SymbolVariationP& variation)
: filename(filename), age(age), variation(variation)
{}
SymbolToImage::~SymbolToImage() {}
Image SymbolToImage::generate(const Options& opt) const {
// TODO : use opt.width and opt.height?
if (!opt.symbol_package) throw ScriptError(_("Can only load images in a context where an image is expected"));
......
......@@ -14,7 +14,7 @@
#include <gfx/gfx.hpp>
#include <script/value.hpp>
DECLARE_INTRUSIVE_POINTER_TYPE(GeneratedImage);
DECLARE_POINTER_TYPE(GeneratedImage);
DECLARE_POINTER_TYPE(SymbolVariation);
class Package;
......@@ -161,12 +161,12 @@ class BuiltInImage : public GeneratedImage {
/// Use a symbol as an image
class SymbolToImage : public GeneratedImage {
public:
inline SymbolToImage(const String& filename, Age age, const SymbolVariationP& variation)
: filename(filename), age(age), variation(variation)
{}
SymbolToImage(const String& filename, Age age, const SymbolVariationP& variation);
~SymbolToImage();
virtual Image generate(const Options& opt) const;
virtual bool operator == (const GeneratedImage& that) const;
private:
SymbolToImage(const SymbolToImage&); // copy ctor
String filename;
Age age; ///< Age the symbol was last updated
SymbolVariationP variation;
......
......@@ -127,7 +127,7 @@ void set_alpha(Image& img, const Image& img_alpha);
/// An alpha mask is an alpha channel that can be copied to another image
/** It is created by treating black in the source image as transparent and white (red) as opaque
*/
class AlphaMask {
class AlphaMask : public IntrusivePtrBase<AlphaMask> {
public:
AlphaMask(const Image& mask);
~AlphaMask();
......
......@@ -37,7 +37,7 @@ ValueViewerP DataEditor::makeViewer(const StyleP& style) {
bool DataEditor::drawBorders() const {
return !nativeLook() &&
settings.stylesheetSettingsFor(*set->stylesheetFor(card)).card_borders();
settings.stylesheetSettingsFor(set->stylesheetFor(card)).card_borders();
}
bool DataEditor::drawEditing() const {
return true;
......
......@@ -11,6 +11,7 @@
#include <util/prec.hpp>
#include <gui/control/item_list.hpp>
#include <data/card.hpp>
#include <data/set.hpp>
DECLARE_POINTER_TYPE(ChoiceField);
......@@ -27,10 +28,11 @@ DECLARE_EVENT_TYPE(EVENT_CARD_SELECT, <not used>)
/// The event of selecting a card
struct CardSelectEvent : public wxCommandEvent {
CardP card; ///< The selected card
inline CardSelectEvent(const CardP& card)
: wxCommandEvent(EVENT_CARD_SELECT), card(card)
{}
CardP card; ///< The selected card
};
// ----------------------------------------------------------------------------- : CardListBase
......
......@@ -17,7 +17,7 @@ DECLARE_POINTER_TYPE(CardListFilter);
// ----------------------------------------------------------------------------- : CardListFilter
/// A filter function to determine which items are shown in a card list
class CardListFilter {
class CardListFilter : public IntrusivePtrVirtualBase {
public:
virtual ~CardListFilter() {}
/// Should a card be shown in the list?
......
......@@ -367,19 +367,19 @@ GraphControl::GraphControl(Window* parent, int id)
: wxControl(parent, id)
{
//*
shared_ptr<GraphContainer> combined(new GraphContainer());
combined->add(new_shared1<GraphValueAxis>(0));
combined->add(new_shared1<BarGraph>(0));
graph = new_shared6<GraphWithMargins>(combined, 23,8,7,20, true);
intrusive_ptr<GraphContainer> combined(new GraphContainer());
combined->add(new_intrusive1<GraphValueAxis>(0));
combined->add(new_intrusive1<BarGraph>(0));
graph = new_intrusive6<GraphWithMargins>(combined, 23,8,7,20, true);
/*/
shared_ptr<GraphContainer> combined(new GraphContainer());
combined->add(new_shared1<PieGraph>(0));
graph = new_shared6<GraphWithMargins>(combined, 20,20,20,20, false);
intrusive_ptr<GraphContainer> combined(new GraphContainer());
combined->add(new_intrusive1<PieGraph>(0));
graph = new_intrusive6<GraphWithMargins>(combined, 20,20,20,20, false);
//*/
}
void GraphControl::setData(const GraphDataPre& data) {
setData(new_shared1<GraphData>(data));
setData(new_intrusive1<GraphData>(data));
}
void GraphControl::setData(const GraphDataP& data) {
if (graph) {
......
......@@ -28,7 +28,7 @@ DECLARE_EVENT_TYPE(EVENT_GRAPH_SELECT, <not used>)
/// A group in a table or graph
/** A group is rendered as a single bar or pie slice */
class GraphGroup {
class GraphGroup : public IntrusivePtrBase<GraphGroup> {
public:
GraphGroup(const String& name, UInt size, const Color& color = *wxBLACK)
: name(name), color(color), size(size)
......@@ -48,7 +48,7 @@ enum AutoColor
/// An axis in a graph, consists of a list of groups
/** The sum of groups.sum = sum of all elements in the data */
class GraphAxis {
class GraphAxis : public IntrusivePtrBase<GraphAxis> {
public:
GraphAxis(const String& name, AutoColor auto_color = AUTO_COLOR_EVEN, bool numeric = false, const map<String,Color>* colors = nullptr)
: name(name)
......@@ -69,7 +69,7 @@ class GraphAxis {
};
/// A single data point of a graph
class GraphElement {
class GraphElement : public IntrusivePtrBase<GraphElement> {
public:
GraphElement() {}
GraphElement(const String& v1);
......@@ -86,7 +86,7 @@ class GraphDataPre {
};
/// Data to be displayed in a graph
class GraphData {
class GraphData : public IntrusivePtrBase<GraphData> {
public:
GraphData(const GraphDataPre&);
......@@ -108,9 +108,8 @@ enum DrawLayer
/// A type of graph
/** It is rendered into a sub-rectangle of the screen */
class Graph {
class Graph : public IntrusivePtrVirtualBase {
public:
virtual ~Graph() {}
/// Draw this graph, filling the internalRect() of the dc.
virtual void draw(RotatedDC& dc, const vector<int>& current, DrawLayer layer) const = 0;
/// Find the item at the given position, the rectangle gives the screen size
......
......@@ -98,7 +98,7 @@ int ImageCardList::OnGetItemImage(long pos) const {
return it->second;
} else {
// request a thumbnail
thumbnail_thread.request(new_shared2<CardThumbnailRequest>(const_cast<ImageCardList*>(this), val.filename));
thumbnail_thread.request(new_intrusive2<CardThumbnailRequest>(const_cast<ImageCardList*>(this), val.filename));
}
}
return -1;
......
......@@ -12,7 +12,7 @@
#include <util/prec.hpp>
#include <wx/listctrl.h>
typedef shared_ptr<void> VoidP;
typedef intrusive_ptr<IntrusivePtrVirtualBase> VoidP;
// ----------------------------------------------------------------------------- : ItemList
......
......@@ -38,8 +38,8 @@ class PackageList : public GalleryList {
/** @pre hasSelection()
* Throws if the selection is not of type T */
template <typename T>
shared_ptr<T> getSelection() const {
shared_ptr<T> ret = dynamic_pointer_cast<T>(packages.at(selection).package);
intrusive_ptr<T> getSelection() const {
intrusive_ptr<T> ret = dynamic_pointer_cast<T>(packages.at(selection).package);
if (!ret) throw InternalError(_("PackageList: Selected package has the wrong type"));
ret->loadFully();
return ret;
......
......@@ -8,6 +8,7 @@
#include <gui/control/select_card_list.hpp>
#include <gui/util.hpp>
#include <data/card.hpp>
DECLARE_TYPEOF_COLLECTION(CardP);
......@@ -24,6 +25,7 @@ SelectCardList::SelectCardList(Window* parent, int id, long additional_style)
il->Add(load_resource_image(_("selected")));
AssignImageList(il, wxIMAGE_LIST_SMALL);
}
SelectCardList::~SelectCardList() {}
void SelectCardList::selectAll() {
FOR_EACH_CONST(c, set->cards) {
......
......@@ -19,6 +19,7 @@
class SelectCardList : public CardListBase {
public:
SelectCardList(Window* parent, int id, long additional_style = 0);
~SelectCardList();
/// Select all cards
void selectAll();
/// Deselect all cards
......
......@@ -21,6 +21,7 @@ TextCtrl::TextCtrl(Window* parent, int id, bool multi_line, long style)
, value(nullptr)
, multi_line(multi_line)
{}
TextCtrl::~TextCtrl() {}
Rotation TextCtrl::getRotation() const {
return Rotation(0, RealRect(RealPoint(0,0),GetClientSize()));
......@@ -57,7 +58,7 @@ void TextCtrl::updateSize() {
}
void TextCtrl::setValue(String* value, bool untagged) {
setValue(new_shared4<FakeTextValue>(getFieldP(), value, true, untagged));
setValue(new_intrusive4<FakeTextValue>(getFieldP(), value, true, untagged));
}
void TextCtrl::setValue(const FakeTextValueP& value) {
value->retrieve();
......
......@@ -30,6 +30,7 @@ DECLARE_POINTER_TYPE(FakeTextValue);
class TextCtrl : public DataEditor {
public:
TextCtrl(Window* parent, int id, bool multi_line, long style = 0);
~TextCtrl();
/// Set the value that is being edited
/** value can be a nullptr*/
......
......@@ -92,7 +92,7 @@ void NewSetWindow::OnOK(wxCommandEvent&) {
void NewSetWindow::done() {
StyleSheetP stylesheet = stylesheet_list->getSelection<StyleSheet>();
set = new_shared1<Set>(stylesheet);
set = new_intrusive1<Set>(stylesheet);
set->validate();
EndModal(wxID_OK);
}
......
......@@ -10,6 +10,7 @@
#include <gui/card_select_window.hpp>
#include <gui/util.hpp>
#include <data/set.hpp>
#include <data/card.hpp>
#include <data/stylesheet.hpp>
#include <render/card/viewer.hpp>
#include <wx/print.h>
......@@ -44,7 +45,7 @@ class TextBufferDC : public wxMemoryDC {
private:
// A call to DrawText
struct TextDraw {
struct TextDraw : public IntrusivePtrBase<TextDraw> {
wxFont font;
Color color;
int x, y;
......@@ -57,7 +58,7 @@ class TextBufferDC : public wxMemoryDC {
{}
};
public:
typedef shared_ptr<TextDraw> TextDrawP;
typedef intrusive_ptr<TextDraw> TextDrawP;
private:
vector<TextDrawP> text;
Bitmap buffer;
......@@ -73,12 +74,12 @@ TextBufferDC::TextBufferDC(int width, int height)
void TextBufferDC::DoDrawText(const String& str, int x, int y) {
double usx,usy;
GetUserScale(&usx, &usy);
text.push_back( new_shared7<TextDraw>(GetFont(), GetTextForeground(), usx, usy, x, y, str) );
text.push_back( new_intrusive7<TextDraw>(GetFont(), GetTextForeground(), usx, usy, x, y, str) );
}
void TextBufferDC::DoDrawRotatedText(const String& str, int x, int y, double angle) {
double usx,usy;
GetUserScale(&usx, &usy);
text.push_back( new_shared8<TextDraw>(GetFont(), GetTextForeground(), usx, usy, x, y, str, angle) );
text.push_back( new_intrusive8<TextDraw>(GetFont(), GetTextForeground(), usx, usy, x, y, str, angle) );
}
DECLARE_TYPEOF_COLLECTION(TextBufferDC::TextDrawP);
......@@ -171,7 +172,7 @@ void CardsPrintout::OnPreparePrinting() {
int pw_mm, ph_mm;
GetPageSizeMM(&pw_mm, &ph_mm);
if (!layout) {
layout = new_shared2<PageLayout>(*set->stylesheet, RealSize(pw_mm, ph_mm));
layout = new_intrusive2<PageLayout>(*set->stylesheet, RealSize(pw_mm, ph_mm));
}
}
......@@ -201,7 +202,7 @@ void CardsPrintout::drawCard(DC& dc, const CardP& card, int card_nr) {
RealPoint pos( layout->margin_left + (layout->card_size.width + layout->card_spacing.width) * col
, layout->margin_top + (layout->card_size.height + layout->card_spacing.height) * row);
// determine rotation
StyleSheet& stylesheet = *set->stylesheetFor(card);
const StyleSheet& stylesheet = set->stylesheetFor(card);
int rotation = 0;
if ((stylesheet.card_width > stylesheet.card_height) != layout->card_landscape) {
rotation = 90 - rotation;
......
......@@ -27,7 +27,7 @@ void print_set(Window* parent, const SetP& set);
// ----------------------------------------------------------------------------- : Layout
/// Layout of a page of cards
class PageLayout {
class PageLayout : public IntrusivePtrBase<PageLayout> {
public:
PageLayout();
PageLayout(const StyleSheet& stylesheet, const RealSize& page_size);
......
......@@ -150,7 +150,7 @@ void CardsPanel::onUpdateUI(wxUpdateUIEvent& ev) {
case ID_CARD_PREV: ev.Enable(card_list->canSelectPrevious()); break;
case ID_CARD_NEXT: ev.Enable(card_list->canSelectNext()); break;
case ID_CARD_ROTATE_0: case ID_CARD_ROTATE_90: case ID_CARD_ROTATE_180: case ID_CARD_ROTATE_270: {
StyleSheetSettings& ss = settings.stylesheetSettingsFor(*set->stylesheetFor(card_list->getCard()));
StyleSheetSettings& ss = settings.stylesheetSettingsFor(set->stylesheetFor(card_list->getCard()));
int a = ev.GetId() == ID_CARD_ROTATE_0 ? 0
: ev.GetId() == ID_CARD_ROTATE_90 ? 90
: ev.GetId() == ID_CARD_ROTATE_180 ? 180
......@@ -203,7 +203,7 @@ void CardsPanel::onCommand(int id) {
break;
case ID_CARD_ROTATE:
case ID_CARD_ROTATE_0: case ID_CARD_ROTATE_90: case ID_CARD_ROTATE_180: case ID_CARD_ROTATE_270: {
StyleSheetSettings& ss = settings.stylesheetSettingsFor(*set->stylesheetFor(card_list->getCard()));
StyleSheetSettings& ss = settings.stylesheetSettingsFor(set->stylesheetFor(card_list->getCard()));
ss.card_angle.assign(
id == ID_CARD_ROTATE ? (ss.card_angle() + 90) % 360
: id == ID_CARD_ROTATE_0 ? 0
......
......@@ -305,10 +305,10 @@ void KeywordsPanel::onKeywordSelect(KeywordSelectEvent& ev) {
if (ev.keyword) {
Keyword& kw = *ev.keyword;
sp->Show(fixed, kw.fixed);
keyword ->setValue(new_shared5<KeywordTextValue> (keyword->getFieldP(), &kw, &kw.keyword, !kw.fixed, true));
match ->setValue(new_shared4<KeywordTextValue> (match->getFieldP(), &kw, &kw.match, !kw.fixed));
rules ->setValue(new_shared4<KeywordTextValue> (rules->getFieldP(), &kw, &kw.rules, !kw.fixed));
shared_ptr<KeywordReminderTextValue> reminder_value(new KeywordReminderTextValue(reminder->getFieldP(), &kw, !kw.fixed));
keyword ->setValue(new_intrusive5<KeywordTextValue> (keyword->getFieldP(), &kw, &kw.keyword, !kw.fixed, true));
match ->setValue(new_intrusive4<KeywordTextValue> (match->getFieldP(), &kw, &kw.match, !kw.fixed));
rules ->setValue(new_intrusive4<KeywordTextValue> (rules->getFieldP(), &kw, &kw.rules, !kw.fixed));
intrusive_ptr<KeywordReminderTextValue> reminder_value(new KeywordReminderTextValue(reminder->getFieldP(), &kw, !kw.fixed));
reminder->setValue(reminder_value);
errors->SetLabel(reminder_value->errors);
add_param->Enable(!kw.fixed && !set->game->keyword_parameter_types.empty());
......
......@@ -7,9 +7,14 @@
// ----------------------------------------------------------------------------- : Includes
#include <gui/set/panel.hpp>
#include <data/card.hpp>
// ----------------------------------------------------------------------------- : SetWindowPanel
SetWindowPanel::SetWindowPanel(Window* parent, int id, bool autoTabbing)
: wxPanel(parent, id, wxDefaultPosition, wxDefaultSize, autoTabbing ? wxTAB_TRAVERSAL : 0)
{}
CardP SetWindowPanel::selectedCard() const {
return CardP();
}
......@@ -66,7 +66,7 @@ class SetWindowPanel : public wxPanel, public SetView {
virtual bool doReplaceAll(wxFindReplaceData&) { return false; } ///< Replace all matches
// --------------------------------------------------- : Selection
virtual CardP selectedCard() const { return CardP(); } ///< Return the currently selected card, or CardP()
virtual CardP selectedCard() const; ///< Return the currently selected card, or CardP()
virtual void selectCard(const CardP& card) {} ///< Switch the view to another card
virtual void selectFirstCard() {} ///< Switch the view to the first card
};
......
......@@ -148,7 +148,7 @@ void StatsPanel::onCategorySelect() {
StatsCategory& cat = categories->getSelection();
GraphDataPre d;
FOR_EACH(dim, cat.dimensions) {
d.axes.push_back(new_shared4<GraphAxis>(
d.axes.push_back(new_intrusive4<GraphAxis>(
dim->name,
dim->colors.empty() ? AUTO_COLOR_EVEN : AUTO_COLOR_NO,
dim->numeric,
......@@ -183,7 +183,7 @@ void StatsPanel::onGraphSelect(wxCommandEvent&) {
void StatsPanel::filterCards() {
if (!categories->hasSelection()) return;
shared_ptr<StatsFilter> filter(new StatsFilter(*set));
intrusive_ptr<StatsFilter> filter(new StatsFilter(*set));
StatsCategory& cat = categories->getSelection();
vector<pair<StatsDimensionP, String> > values;
int i = 0;
......
......@@ -46,19 +46,19 @@ void StylePanel::onChangeSet() {
list->select(set->stylesheet->name(), false);
editor->setSet(set);
preview->setSet(set);
card.reset();
card = CardP();
use_for_all->Enable(false);
}
void StylePanel::onAction(const Action& action, bool undone) {
TYPE_CASE_(action, ChangeSetStyleAction) {
list->select(set->stylesheetFor(card)->name(), false);
editor->showStylesheet(set->stylesheetFor(card));
list->select(set->stylesheetFor(card).name(), false);
editor->showStylesheet(set->stylesheetForP(card));
}
TYPE_CASE(action, ChangeCardStyleAction) {
if (action.card == card) {
list->select(set->stylesheetFor(card)->name(), false);
editor->showStylesheet(set->stylesheetFor(card));
list->select(set->stylesheetFor(card).name(), false);
editor->showStylesheet(set->stylesheetForP(card));
}
}
use_for_all->Enable(card && card->stylesheet);
......@@ -69,8 +69,8 @@ void StylePanel::onAction(const Action& action, bool undone) {
void StylePanel::selectCard(const CardP& card) {
this->card = card;
preview->setCard(card);
editor->showStylesheet(set->stylesheetFor(card));
list->select(set->stylesheetFor(card)->name(), false);
editor->showStylesheet(set->stylesheetForP(card));
list->select(set->stylesheetFor(card).name(), false);
use_for_all->Enable(card && card->stylesheet);
}
......
......@@ -233,7 +233,7 @@ bool SetWindow::isOnlyWithSet() {
void SetWindow::onChangeSet() {
// make sure there is always at least one card
// some things need this
if (set->cards.empty()) set->cards.push_back(new_shared1<Card>(*set->game));
if (set->cards.empty()) set->cards.push_back(new_intrusive1<Card>(*set->game));
// all panels view the same set
FOR_EACH(p, panels) {
p->setSet(set);
......
......@@ -178,7 +178,7 @@ void SymbolBasicShapeEditor::makeShape(const Vector2D& a, const Vector2D& b, boo
// TODO : Move out of this class
void SymbolBasicShapeEditor::makeCenteredShape(const Vector2D& c, Vector2D r, bool constrained) {
shape = new_shared<SymbolPart>();
shape = new_intrusive<SymbolPart>();
// What shape to make?
switch (mode) {
case ID_SHAPE_CIRCLE: {
......@@ -191,10 +191,10 @@ void SymbolBasicShapeEditor::makeCenteredShape(const Vector2D& c, Vector2D r, bo
// a circle has 4 control points, the first is: (x+r, y) db(0, kr) da(0, -kr)
// kr is a magic constant
const double kr = 0.5522847498f; // = 4/3 * (sqrt(2) - 1)
shape->points.push_back(new_shared7<ControlPoint>(c.x + r.x, c.y, 0, kr * r.y, 0, -kr * r.y, LOCK_SIZE));
shape->points.push_back(new_shared7<ControlPoint>(c.x, c.y - r.y, kr * r.x, 0, -kr * r.x, 0, LOCK_SIZE));
shape->points.push_back(new_shared7<ControlPoint>(c.x - r.x, c.y, 0, -kr * r.y, 0, kr * r.y, LOCK_SIZE));
shape->points.push_back(new_shared7<ControlPoint>(c.x, c.y + r.y, -kr * r.x, 0, kr * r.x, 0, LOCK_SIZE));
shape->points.push_back(new_intrusive7<ControlPoint>(c.x + r.x, c.y, 0, kr * r.y, 0, -kr * r.y, LOCK_SIZE));
shape->points.push_back(new_intrusive7<ControlPoint>(c.x, c.y - r.y, kr * r.x, 0, -kr * r.x, 0, LOCK_SIZE));
shape->points.push_back(new_intrusive7<ControlPoint>(c.x - r.x, c.y, 0, -kr * r.y, 0, kr * r.y, LOCK_SIZE));
shape->points.push_back(new_intrusive7<ControlPoint>(c.x, c.y + r.y, -kr * r.x, 0, kr * r.x, 0, LOCK_SIZE));
break;
} case ID_SHAPE_RECTANGLE: {
// A rectangle / square
......@@ -204,10 +204,10 @@ void SymbolBasicShapeEditor::makeCenteredShape(const Vector2D& c, Vector2D r, bo
shape->name = capitalize(_TYPE_("rectangle"));
}
// a rectangle just has four corners
shape->points.push_back(new_shared2<ControlPoint>(c.x - r.x, c.y - r.y));
shape->points.push_back(new_shared2<ControlPoint>(c.x + r.x, c.y - r.y));
shape->points.push_back(new_shared2<ControlPoint>(c.x + r.x, c.y + r.y));
shape->points.push_back(new_shared2<ControlPoint>(c.x - r.x, c.y + r.y));
shape->points.push_back(new_intrusive2<ControlPoint>(c.x - r.x, c.y - r.y));
shape->points.push_back(new_intrusive2<ControlPoint>(c.x + r.x, c.y - r.y));
shape->points.push_back(new_intrusive2<ControlPoint>(c.x + r.x, c.y + r.y));
shape->points.push_back(new_intrusive2<ControlPoint>(c.x - r.x, c.y + r.y));
break;
} default: {
// A polygon or star
......@@ -250,7 +250,7 @@ void SymbolBasicShapeEditor::makeCenteredShape(const Vector2D& c, Vector2D r, bo
// we can generate points
for(int i = 0 ; i < n ; ++i) {
double theta = alpha * i;
shape->points.push_back(new_shared2<ControlPoint>(
shape->points.push_back(new_intrusive2<ControlPoint>(
c.x + ra * r.x * sin(theta),
y - ra * r.y * cos(theta)
));
......@@ -272,13 +272,13 @@ void SymbolBasicShapeEditor::makeCenteredShape(const Vector2D& c, Vector2D r, bo
for(int i = 0 ; i < n ; ++i) {
double theta = alpha * i;
// from a
shape->points.push_back(new_shared2<ControlPoint>(
shape->points.push_back(new_intrusive2<ControlPoint>(
c.x + ra * r.x * sin(theta),
y - ra * r.y * cos(theta)
));
// from b
theta = alpha * (i + 0.5);
shape->points.push_back(new_shared2<ControlPoint>(
shape->points.push_back(new_intrusive2<ControlPoint>(
c.x + rb * r.x * sin(theta),
y - rb * r.y * cos(theta)
));
......
......@@ -37,22 +37,22 @@ void SymbolControl::switchEditor(const SymbolEditorBaseP& e) {
void SymbolControl::onChangeSymbol() {
selected_parts.clear();
switchEditor(new_shared2<SymbolSelectEditor>(this, false));
switchEditor(new_intrusive2<SymbolSelectEditor>(this, false));
Refresh(false);
}
void SymbolControl::onModeChange(wxCommandEvent& ev) {
switch (ev.GetId()) {
case ID_MODE_SELECT:
switchEditor(new_shared2<SymbolSelectEditor>(this, false));
switchEditor(new_intrusive2<SymbolSelectEditor>(this, false));
break;
case ID_MODE_ROTATE:
switchEditor(new_shared2<SymbolSelectEditor>(this, true));
switchEditor(new_intrusive2<SymbolSelectEditor>(this, true));
break;
case ID_MODE_POINTS:
if (selected_parts.size() == 1) {
single_selection = *selected_parts.begin();
switchEditor(new_shared2<SymbolPointEditor>(this, single_selection));
switchEditor(new_intrusive2<SymbolPointEditor>(this, single_selection));
}
break;
case ID_MODE_SHAPES:
......@@ -60,7 +60,7 @@ void SymbolControl::onModeChange(wxCommandEvent& ev) {
selected_parts.clear();
signalSelectionChange();
}
switchEditor(new_shared1<SymbolBasicShapeEditor>(this));
switchEditor(new_intrusive1<SymbolBasicShapeEditor>(this));
break;
}
}
......@@ -102,7 +102,7 @@ void SymbolControl::onUpdateSelection() {
if (single_selection != *selected_parts.begin()) {
// begin editing another part
single_selection = *selected_parts.begin();
editor = new_shared2<SymbolPointEditor>(this, single_selection);
editor = new_intrusive2<SymbolPointEditor>(this, single_selection);
Refresh(false);
}
break;
......@@ -122,14 +122,14 @@ void SymbolControl::onUpdateSelection() {
void SymbolControl::selectPart(const SymbolPartP& part) {
selected_parts.clear();
selected_parts.insert(part);
switchEditor(new_shared2<SymbolSelectEditor>(this, false));
switchEditor(new_intrusive2<SymbolSelectEditor>(this, false));
signalSelectionChange();
}
void SymbolControl::activatePart(const SymbolPartP& part) {
selected_parts.clear();
selected_parts.insert(part);
switchEditor(new_shared2<SymbolPointEditor>(this, part));
switchEditor(new_intrusive2<SymbolPointEditor>(this, part));
}
void SymbolControl::signalSelectionChange() {
......
......@@ -22,7 +22,7 @@ class SymbolControl;
* Differrent SymbolEditors represent different tools.
* NOTE : Do not confuse with SymbolEditor (a FieldEditor)
*/
class SymbolEditorBase {
class SymbolEditorBase : public IntrusivePtrVirtualBase {
protected:
/// The control for which we are editing
SymbolControl& control;
......
......@@ -84,7 +84,7 @@ wxThread::ExitCode ThumbnailThreadWorker::Entry() {
{
wxMutexLocker lock(parent->mutex);
parent->closed_requests.push_back(make_pair(current,img));
current.reset();
current = ThumbnailRequestP();
parent->completed.Signal();
}
}
......
......@@ -20,7 +20,7 @@ class ThumbnailThreadWorker;
// ----------------------------------------------------------------------------- : ThumbnailRequest
/// A request for some kind of thumbnail
class ThumbnailRequest {
class ThumbnailRequest : public IntrusivePtrVirtualBase {
public:
ThumbnailRequest(void* owner, const String& cache_name, const wxDateTime& modified)
: owner(owner), cache_name(cache_name), modified(modified) {}
......
......@@ -21,7 +21,7 @@ DECLARE_POINTER_TYPE(VersionData);
// ----------------------------------------------------------------------------- : Update data
/// Information on available packages
class PackageVersionData {
class PackageVersionData : public IntrusivePtrBase<PackageVersionData> {
public:
PackageVersionData() : is_installer(true) {}
......@@ -34,7 +34,7 @@ class PackageVersionData {
};
/// Information on the latest availible version
class VersionData {
class VersionData : public IntrusivePtrBase<VersionData> {
public:
Version version; ///< Latest version number of MSE
String description; ///< html description of the latest MSE release
......
......@@ -163,7 +163,7 @@ void DropDownChoiceListBase::generateThumbnailImages() {
ThumbnailStatus status = style().thumbnails_status[i];
if (i >= image_count || status != THUMB_OK) {
// request this thumbnail
thumbnail_thread.request( new_shared3<ChoiceThumbnailRequest>(&cve, i, status == THUMB_NOT_MADE) );
thumbnail_thread.request( new_intrusive3<ChoiceThumbnailRequest>(&cve, i, status == THUMB_NOT_MADE) );
}
}
}
......
......@@ -14,7 +14,7 @@
#include <gui/drop_down_list.hpp>
#include <render/value/choice.hpp>
DECLARE_POINTER_TYPE(DropDownList);
DECLARE_SHARED_POINTER_TYPE(DropDownList);
// ----------------------------------------------------------------------------- : ChoiceValueEditor
......
......@@ -13,7 +13,7 @@
#include <gui/value/editor.hpp>
#include <render/value/color.hpp>
DECLARE_POINTER_TYPE(DropDownList);
DECLARE_SHARED_POINTER_TYPE(DropDownList);
// ----------------------------------------------------------------------------- : ColorValueEditor
......
......@@ -37,7 +37,7 @@ void ImageValueEditor::sliceImage(const Image& image) {
if (mask_image.LoadFile(*image_file)) {
Image resampled(style().width, style().height);
resample(mask_image, resampled);
mask = new_shared1<AlphaMask>(resampled);
mask = new_intrusive1<AlphaMask>(resampled);
}
}
// slice
......
......@@ -89,8 +89,8 @@ void WelcomeWindow::onNewSet(wxCommandEvent&) {
// TODO: MOVEME
template <typename T>
shared_ptr<T> open_package(const String& filename) {
shared_ptr<T> package(new T);
intrusive_ptr<T> open_package(const String& filename) {
intrusive_ptr<T> package(new T);
package->open(filename);
return package;
}
......
......@@ -22,6 +22,8 @@ DECLARE_TYPEOF_NO_REV(IndexMap<FieldP COMMA StyleP>);
// ----------------------------------------------------------------------------- : DataViewer
DataViewer::DataViewer() : drawing(false) {}
DataViewer::~DataViewer() {}
// ----------------------------------------------------------------------------- : Drawing
......@@ -84,10 +86,11 @@ Rotation DataViewer::getRotation() const {
void DataViewer::setCard(const CardP& card, bool refresh) {
if (!card) return; // TODO: clear viewer?
if (!refresh && this->card == card && this->stylesheet == set->stylesheetFor(card)) return; // already set
StyleSheetP new_stylesheet = set->stylesheetForP(card);
if (!refresh && this->card == card && this->stylesheet == new_stylesheet) return; // already set
assert(set);
this->card = card;
stylesheet = set->stylesheetFor(card);
stylesheet = new_stylesheet;
setStyles(stylesheet, stylesheet->card_style);
setData(card->data);
onChangeSize();
......
......@@ -22,7 +22,8 @@ class Context;
/// A viewer can generate an image of some values, usually a card.
class DataViewer : public SetView {
public:
DataViewer() : drawing(false) {}
DataViewer();
~DataViewer();
// --------------------------------------------------- : Drawing
......@@ -57,7 +58,7 @@ class DataViewer : public SetView {
/// The rotation to use
virtual Rotation getRotation() const;
/// The card we are viewing
inline CardP getCard() const { return card; }
inline const CardP& getCard() const { return card; }
/// Invalidate and redraw (the area of) a single value viewer
virtual void redraw(const ValueViewer&) {}
......
......@@ -53,24 +53,24 @@ Image render_symbol(const SymbolP& symbol, const SymbolFilter& filter, double bo
// ----------------------------------------------------------------------------- : SymbolFilter
IMPLEMENT_REFLECTION(SymbolFilter) {
IMPLEMENT_REFLECTION_NO_SCRIPT(SymbolFilter) {
REFLECT_IF_NOT_READING {
String fill_type = fillType();
REFLECT(fill_type);
}
}
template <> void GetMember::handle(const shared_ptr<SymbolFilter>& f) {
template <> void GetMember::handle(const intrusive_ptr<SymbolFilter>& f) {
handle(*f);
}
template <>
shared_ptr<SymbolFilter> read_new<SymbolFilter>(Reader& reader) {
intrusive_ptr<SymbolFilter> read_new<SymbolFilter>(Reader& reader) {
// there must be a fill type specified
String fill_type;
reader.handle(_("fill type"), fill_type);
if (fill_type == _("solid")) return new_shared<SolidFillSymbolFilter>();
else if (fill_type == _("linear gradient")) return new_shared<LinearGradientSymbolFilter>();
else if (fill_type == _("radial gradient")) return new_shared<RadialGradientSymbolFilter>();
if (fill_type == _("solid")) return new_intrusive<SolidFillSymbolFilter>();
else if (fill_type == _("linear gradient")) return new_intrusive<LinearGradientSymbolFilter>();
else if (fill_type == _("radial gradient")) return new_intrusive<RadialGradientSymbolFilter>();
else {
throw ParseError(_ERROR_1_("unsupported fill type", fill_type));
}
......
......@@ -46,7 +46,7 @@ enum SymbolSet
// ----------------------------------------------------------------------------- : SymbolFilter
/// Base class for symbol filters
class SymbolFilter {
class SymbolFilter : public IntrusivePtrVirtualBase {
public:
virtual ~SymbolFilter() {}
/// What color should the symbol have at location (x, y)?
......@@ -59,7 +59,7 @@ class SymbolFilter {
};
template <>
shared_ptr<SymbolFilter> read_new<SymbolFilter>(Reader& reader);
intrusive_ptr<SymbolFilter> read_new<SymbolFilter>(Reader& reader);
// ----------------------------------------------------------------------------- : SymbolFilter types
......
......@@ -128,14 +128,14 @@ struct TextElementsFromString {
else if (is_substr(text, tag_start, _("<atom"))) {
// 'atomic' indicator
size_t end_tag = min(end, match_close_tag(text, tag_start));
shared_ptr<AtomTextElement> e(new AtomTextElement(text, pos, end_tag));
intrusive_ptr<AtomTextElement> e(new AtomTextElement(text, pos, end_tag));
fromString(e->elements, text, pos, end_tag, style, ctx);
te.elements.push_back(e);
pos = skip_tag(text, end_tag);
} else if (is_substr(text, tag_start, _( "<error"))) {
// error indicator
size_t end_tag = min(end, match_close_tag(text, tag_start));
shared_ptr<ErrorTextElement> e(new ErrorTextElement(text, pos, end_tag));
intrusive_ptr<ErrorTextElement> e(new ErrorTextElement(text, pos, end_tag));
fromString(e->elements, text, pos, end_tag, style, ctx);
te.elements.push_back(e);
pos = skip_tag(text, end_tag);
......
......@@ -12,6 +12,7 @@
#include <util/prec.hpp>
#include <util/rotation.hpp>
#include <util/real_point.hpp>
#include <data/font.hpp>
DECLARE_POINTER_TYPE(TextElement);
DECLARE_POINTER_TYPE(Font);
......@@ -47,7 +48,7 @@ struct CharInfo {
};
/// A section of text that can be rendered using a TextViewer
class TextElement {
class TextElement : public IntrusivePtrBase<TextElement> {
public:
/// The text of which a subsection is drawn
String text;
......
......@@ -303,7 +303,7 @@ void TextViewer::setExactScrollPosition(double pos) {
void TextViewer::prepareElements(const String& text, const TextStyle& style, Context& ctx) {
if (style.always_symbol) {
elements.elements.clear();
elements.elements.push_back(new_shared5<SymbolTextElement>(text, 0, text.size(), style.symbol_font, &ctx));
elements.elements.push_back(new_intrusive5<SymbolTextElement>(text, 0, text.size(), style.symbol_font, &ctx));
} else {
elements.fromString(text, 0, text.size(), style, ctx);
}
......
......@@ -101,6 +101,6 @@ void ColorValueViewer::loadMask(const Rotation& rot) const {
if (image.LoadFile(*image_file)) {
Image resampled(w,h);
resample(image, resampled);
alpha_mask = new_shared1<AlphaMask>(resampled);
alpha_mask = new_intrusive1<AlphaMask>(resampled);
}
}
......@@ -93,7 +93,7 @@ void ImageValueViewer::loadMask(const Rotation& rot) const {
if (image.LoadFile(*image_file)) {
Image resampled(w,h);
resample(image, resampled);
alpha_mask = new_shared1<AlphaMask>(resampled);
alpha_mask = new_intrusive1<AlphaMask>(resampled);
}
}
......
......@@ -24,7 +24,7 @@ DECLARE_POINTER_TYPE(Value);
/// The virtual viewer control for a single field on a card (or in the set data)
/** A viewer can only display a value, not edit it, ValueEditor is used for that */
class ValueViewer : public StyleListener{
class ValueViewer : public StyleListener {
public:
/// Construct a ValueViewer, set the value at a later time
ValueViewer(DataViewer& parent, const StyleP& style);
......
......@@ -148,15 +148,15 @@ WXCURSOR_HAND CURSOR DISCARDABLE "wx/msw/hand.cur"
// -------------------------------------------------------- : Version info
1 VERSIONINFO
FILEVERSION 0,3,1
PRODUCTVERSION 0,3,1
FILEVERSION 0,3,2
PRODUCTVERSION 0,3,2
FILETYPE VFT_APP
{
BLOCK "StringFileInfo"
{
BLOCK "040904E4"
{
VALUE "FileVersion", "0.3.1"
VALUE "FileVersion", "0.3.2"
VALUE "License", "GNU General Public License 2 or later; This is free software, and you are welcome to redistribute it under certain conditions; See the help file for details"
VALUE "FileDescription", "Magic Set Editor"
VALUE "InternalName", "mse2/8"
......
......@@ -10,6 +10,7 @@
#include <script/functions/util.hpp>
#include <util/tagged_string.hpp>
#include <data/set.hpp>
#include <data/card.hpp>
#include <data/game.hpp>
DECLARE_TYPEOF_COLLECTION(pair<String COMMA ScriptValueP>);
......
......@@ -11,6 +11,7 @@
#include <script/image.hpp>
// used by the functions
#include <data/set.hpp>
#include <data/card.hpp>
#include <data/stylesheet.hpp>
#include <data/symbol.hpp>
#include <data/field/symbol.hpp>
......@@ -78,7 +79,7 @@ SCRIPT_FUNCTION(symbol_variation) {
// find style
SCRIPT_PARAM(Set*, set);
SCRIPT_OPTIONAL_PARAM_(CardP, card);
SymbolStyleP style = dynamic_pointer_cast<SymbolStyle>(set->stylesheetFor(card)->styleFor(value->fieldP));
SymbolStyleP style = dynamic_pointer_cast<SymbolStyle>(set->stylesheetForP(card)->styleFor(value->fieldP));
if (!style) throw InternalError(_("Symbol value has a style of the wrong type"));
// find variation
FOR_EACH(v, style->variations) {
......
......@@ -12,7 +12,7 @@
#include <util/prec.hpp>
#include <script/value.hpp>
DECLARE_INTRUSIVE_POINTER_TYPE(Script);
DECLARE_POINTER_TYPE(Script);
// ----------------------------------------------------------------------------- : Instructions
......
......@@ -71,7 +71,7 @@ Context& SetScriptContext::getContext(const StyleSheetP& stylesheet) {
}
}
Context& SetScriptContext::getContext(const CardP& card) {
Context& ctx = getContext(set.stylesheetFor(card));
Context& ctx = getContext(set.stylesheetForP(card));
if (card) {
ctx.setVariable(_("card"), to_script(card));
} else {
......@@ -185,15 +185,13 @@ void SetScriptManager::onAction(const Action& action, bool undone) {
void SetScriptManager::updateStyles(const CardP& card) {
// lastUpdatedCard = card;
StyleSheetP stylesheet = set.stylesheetFor(card);
const StyleSheet& stylesheet = set.stylesheetFor(card);
Context& ctx = getContext(card);
// update all styles
FOR_EACH(s, stylesheet->card_style) {
FOR_EACH_CONST(s, stylesheet.card_style) {
if (s->update(ctx)) {
s->tellListeners();
// style has changed, tell listeners
//%% ScriptStyleEvent change(stylesheet.get(), s.get());
// set->actions.tellListeners(change);
s->tellListeners();
}
}
}
......
......@@ -50,7 +50,7 @@ class SetScriptContext {
/** Whenever there is an action all necessary scripts are executed.
* Executes both Value scripts and Style scriptables.
*
* The context contains a normal pointer to the set, not a shared_ptr, because the set
* The context contains a normal pointer to the set, not a shared/intrusive_ptr, because the set
* itself owns this object.
*/
class SetScriptManager : public SetScriptContext, public ActionListener {
......
......@@ -17,7 +17,7 @@
#include <script/parser.hpp>
#include <script/to_value.hpp>
DECLARE_INTRUSIVE_POINTER_TYPE(Script);
DECLARE_POINTER_TYPE(Script);
// ----------------------------------------------------------------------------- : Store
......
......@@ -219,7 +219,7 @@ inline ScriptValueP to_script(const map<K,V>* v) { return new_intrusive1<Sc
template <typename K, typename V>
inline ScriptValueP to_script(const IndexMap<K,V>* v) { return new_intrusive1<ScriptMap<IndexMap<K,V> > >(v); }
template <typename T>
inline ScriptValueP to_script(const shared_ptr<T>& v) { return new_intrusive1<ScriptObject<shared_ptr<T> > >(v); }
inline ScriptValueP to_script(const intrusive_ptr<T>& v) { return new_intrusive1<ScriptObject<intrusive_ptr<T> > >(v); }
template <typename T>
inline ScriptValueP to_script(const Defaultable<T>& v) { return to_script(v()); }
......
......@@ -15,7 +15,7 @@ class Dependency;
// ----------------------------------------------------------------------------- : ScriptValue
DECLARE_INTRUSIVE_POINTER_TYPE(ScriptValue);
DECLARE_POINTER_TYPE(ScriptValue);
enum ScriptType
{ SCRIPT_NIL
......@@ -33,7 +33,7 @@ enum ScriptType
/// A value that can be handled by the scripting engine.
/// Actual values are derived types
class ScriptValue : public IntrusivePtrBase {
class ScriptValue : public IntrusivePtrBaseWithDelete {
public:
virtual ~ScriptValue() {}
......
......@@ -13,7 +13,7 @@
#include <script/value.hpp>
class Script;
DECLARE_INTRUSIVE_POINTER_TYPE(Script);
DECLARE_POINTER_TYPE(Script);
template <typename T> class Defaultable;
template <typename T> class Scriptable;
......@@ -39,6 +39,9 @@ class GetDefaultMember {
/// Handle an object: we don't match things with a name
template <typename T>
void handle(const Char* name, const T& object) {}
/// Don't handle a value
template <typename T>
inline void handleNoScript(const Char* name, T& value) {}
/// Handle an object: investigate children, or store it if we know how
void handle(const Char *);
......@@ -50,7 +53,7 @@ class GetDefaultMember {
template <typename T> void handle(const vector<T>& c) { value = to_script(&c); }
template <typename K, typename V> void handle(const map<K,V>& c) { value = to_script(&c); }
template <typename K, typename V> void handle(const IndexMap<K,V>& c) { value = to_script(&c); }
template <typename T> void handle(const shared_ptr<T>& p) { value = to_script(p); }
template <typename T> void handle(const intrusive_ptr<T>& p) { value = to_script(p); }
void handle(const ScriptValueP&);
void handle(const ScriptP&);
private:
......@@ -85,6 +88,9 @@ class GetMember : private GetDefaultMember {
gdm.handle(object);
}
}
/// Don't handle a value
template <typename T>
inline void handleNoScript(const Char* name, T& value) {}
/// Handle an object: investigate children
template <typename T> void handle(const T&);
/// Handle an index map: invistigate keys
......
......@@ -412,9 +412,9 @@ IMPLEMENT_REFLECTION(Packaged) {
REFLECT(short_name);
REFLECT(full_name);
REFLECT_N("icon", icon_filename);
REFLECT(position_hint);
REFLECT_NO_SCRIPT(position_hint);
REFLECT(version);
REFLECT_N("depends ons", dependencies); // hack for singular_form
REFLECT_NO_SCRIPT_N("depends ons", dependencies); // hack for singular_form
}
Packaged::Packaged()
......
......@@ -45,7 +45,7 @@ DECLARE_DYNAMIC_ARG(Package*, clipboard_package);
*
* TODO: maybe support sub packages (a package inside another package)?
*/
class Package {
class Package : public IntrusivePtrVirtualBase {
public:
// --------------------------------------------------- : Managing the outside of the package
......@@ -177,7 +177,7 @@ class Package {
// ----------------------------------------------------------------------------- : Packaged
/// Dependencies of a package
class PackageDependency {
class PackageDependency : public IntrusivePtrBase<PackageDependency> {
public:
String package; ///< Name of the package someone depends on
Version version; ///< Minimal required version of that package
......
......@@ -65,12 +65,12 @@ PackagedP PackageManager::openAny(const String& name, bool just_header) {
return p;
} else {
// load with the right type, based on extension
if (fn.GetExt() == _("mse-game")) p = new_shared<Game>();
else if (fn.GetExt() == _("mse-style")) p = new_shared<StyleSheet>();
else if (fn.GetExt() == _("mse-locale")) p = new_shared<Locale>();
else if (fn.GetExt() == _("mse-include")) p = new_shared<IncludePackage>();
else if (fn.GetExt() == _("mse-symbol-font")) p = new_shared<SymbolFont>();
else if (fn.GetExt() == _("mse-export-template")) p = new_shared<ExportTemplate>();
if (fn.GetExt() == _("mse-game")) p = new_intrusive<Game>();
else if (fn.GetExt() == _("mse-style")) p = new_intrusive<StyleSheet>();
else if (fn.GetExt() == _("mse-locale")) p = new_intrusive<Locale>();
else if (fn.GetExt() == _("mse-include")) p = new_intrusive<IncludePackage>();
else if (fn.GetExt() == _("mse-symbol-font")) p = new_intrusive<SymbolFont>();
else if (fn.GetExt() == _("mse-export-template")) p = new_intrusive<ExportTemplate>();
else {
throw PackageError(_("Unrecognized package type: '") + fn.GetExt() + _("'\nwhile trying to open: ") + name);
}
......
......@@ -33,19 +33,19 @@ class PackageManager {
/// Open a package with the specified name (including extension)
template <typename T>
shared_ptr<T> open(const String& name) {
intrusive_ptr<T> open(const String& name) {
wxFileName fn(data_directory + _("/") + name);
fn.Normalize();
String filename = fn.GetFullPath();
// Is this package already loaded?
PackagedP& p = loaded_packages[filename];
shared_ptr<T> typedP = dynamic_pointer_cast<T>(p);
intrusive_ptr<T> typedP = dynamic_pointer_cast<T>(p);
if (typedP) {
typedP->loadFully();
return typedP;
} else {
// not loaded, or loaded with wrong type (i.e. with just_header)
p = typedP = new_shared<T>();
p = typedP = new_intrusive<T>();
typedP->open(filename);
return typedP;
}
......
......@@ -82,14 +82,18 @@ class Reader {
exitBlock();
}
}
/// Handle a value
template <typename T>
inline void handleNoScript(const Char* name, T& value) { handle(name,value); }
/// Reads a vector from the input stream
template <typename T>
void handle(const Char* name, vector<T>& vector);
/// Reads an object of type T from the input stream
template <typename T> void handle(T& object);
/// Reads a shared_ptr from the input stream
template <typename T> void handle(shared_ptr<T>& pointer);
/// Reads a intrusive_ptr from the input stream
template <typename T> void handle(intrusive_ptr<T>& pointer);
/// Reads a map from the input stream
template <typename V> void handle(map<String,V>& m);
/// Reads an IndexMap from the input stream, reads only keys that already exist in the map
......@@ -178,8 +182,8 @@ class Reader {
* This function can be overloaded to provide different behaviour
*/
template <typename T>
shared_ptr<T> read_new(Reader& reader) {
return new_shared<T>();
intrusive_ptr<T> read_new(Reader& reader) {
return new_intrusive<T>();
}
/// Update the 'index' member of a value for use by IndexMap
......@@ -197,7 +201,7 @@ void Reader::handle(const Char* name, vector<T>& vector) {
}
template <typename T>
void Reader::handle(shared_ptr<T>& pointer) {
void Reader::handle(intrusive_ptr<T>& pointer) {
if (!pointer) pointer = read_new<T>(*this);
handle(*pointer);
}
......
......@@ -45,6 +45,10 @@ class Writer {
handle(object);
exitBlock();
}
/// Handle a value
template <typename T>
inline void handleNoScript(const Char* name, T& value) { handle(name,value); }
/// Write a vector to the output stream
template <typename T>
void handle(const Char* name, const vector<T>& vector);
......@@ -55,8 +59,8 @@ class Writer {
/// Write an object of type T to the output stream
template <typename T> void handle(const T& object);
/// Write a shared_ptr to the output stream
template <typename T> void handle(const shared_ptr<T>& pointer);
/// Write a intrusive_ptr to the output stream
template <typename T> void handle(const intrusive_ptr<T>& pointer);
/// Write a map to the output stream
template <typename K, typename V> void handle(const map<K,V>& map);
/// Write an IndexMap to the output stream
......@@ -107,7 +111,7 @@ void Writer::handle(const Char* name, const vector<T>& vec) {
}
template <typename T>
void Writer::handle(const shared_ptr<T>& pointer) {
void Writer::handle(const intrusive_ptr<T>& pointer) {
if (pointer) handle(*pointer);
}
......
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment