Skip to content

Commit

Permalink
Cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
skyjake committed Aug 1, 2014
1 parent b684a59 commit 93b4434
Showing 1 changed file with 35 additions and 32 deletions.
67 changes: 35 additions & 32 deletions doomsday/libcore/src/data/record.cpp
Expand Up @@ -52,21 +52,24 @@ DENG2_PIMPL(Record)

typedef QMap<duint32, Record *> RefMap;

Instance(Public &r) : Base(r), uniqueId(++recordIdCounter), oldUniqueId(0)
Instance(Public &r)
: Base(r)
, uniqueId(++recordIdCounter)
, oldUniqueId(0)
{}

struct ExcludeBasedOnBehavior {
struct ExcludeByBehavior {
Behavior behavior;
ExcludeBasedOnBehavior(Behavior b) : behavior(b) {}
ExcludeByBehavior(Behavior b) : behavior(b) {}
bool operator () (Variable const &member) {
return (behavior == IgnoreDoubleUnderscoreMembers &&
member.name().startsWith("__"));
}
};

struct ExcludeBasedOnRegExp {
struct ExcludeByRegExp {
QRegExp omitted;
ExcludeBasedOnRegExp(QRegExp const &omit) : omitted(omit) {}
ExcludeByRegExp(QRegExp const &omit) : omitted(omit) {}
bool operator () (Variable const &member) {
return omitted.exactMatch(member.name());
}
Expand Down Expand Up @@ -97,6 +100,29 @@ DENG2_PIMPL(Record)
}
}

template <typename Predicate>
void copyMembersFrom(Record const &other, Predicate excluded)
{
DENG2_FOR_EACH_CONST(Members, i, other.d->members)
{
if(excluded(*i.value())) continue;

bool const alreadyExists = members.contains(i.key());

Variable *var = new Variable(*i.value());
var->audienceForDeletion() += self;
members[i.key()] = var;

if(!alreadyExists)
{
// Notify about newly added members.
DENG2_FOR_PUBLIC_AUDIENCE2(Addition, i) i->recordMemberAdded(self, *var);
}

/// @todo Should also notify if the value of an existing variable changes. -jk
}
}

bool isSubrecord(Variable const &var) const
{
RecordValue const *value = var.value().maybeAs<RecordValue>();
Expand Down Expand Up @@ -222,29 +248,6 @@ DENG2_PIMPL(Record)
}
}

template <typename Predicate>
void copyMembersFrom(Record const &other, Predicate excluded)
{
DENG2_FOR_EACH_CONST(Members, i, other.d->members)
{
if(excluded(*i.value())) continue;

bool const alreadyExists = members.contains(i.key());

Variable *var = new Variable(*i.value());
var->audienceForDeletion() += self;
members[i.key()] = var;

if(!alreadyExists)
{
// Notify about newly added members.
DENG2_FOR_PUBLIC_AUDIENCE2(Addition, i) i->recordMemberAdded(self, *var);
}

/// @todo Should also notify if the value of an existing variable changes. -jk
}
}

DENG2_PIMPL_AUDIENCE(Deletion)
DENG2_PIMPL_AUDIENCE(Addition)
DENG2_PIMPL_AUDIENCE(Removal)
Expand Down Expand Up @@ -275,12 +278,12 @@ Record::~Record()

void Record::clear(Behavior behavior)
{
d->clear(Instance::ExcludeBasedOnBehavior(behavior));
d->clear(Instance::ExcludeByBehavior(behavior));
}

void Record::copyMembersFrom(Record const &other, Behavior behavior)
{
d->copyMembersFrom(other, Instance::ExcludeBasedOnBehavior(behavior));
d->copyMembersFrom(other, Instance::ExcludeByBehavior(behavior));
}

Record &Record::operator = (Record const &other)
Expand All @@ -297,8 +300,8 @@ Record &Record::assign(Record const &other, Behavior behavior)

Record &Record::assign(Record const &other, QRegExp const &excluded)
{
d->clear(Instance::ExcludeBasedOnRegExp(excluded));
d->copyMembersFrom(other, Instance::ExcludeBasedOnRegExp(excluded));
d->clear(Instance::ExcludeByRegExp(excluded));
d->copyMembersFrom(other, Instance::ExcludeByRegExp(excluded));
return *this;
}

Expand Down

0 comments on commit 93b4434

Please sign in to comment.