Skip to content

Commit

Permalink
Cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
skyjake committed Apr 20, 2014
1 parent cad919e commit 1cd1082
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 37 deletions.
4 changes: 2 additions & 2 deletions doomsday/libdeng2/include/de/data/variable.h
Expand Up @@ -131,14 +131,14 @@ class DENG2_PUBLIC Variable : public ISerializable
/**
* Sets the value of the variable.
*
* @param v New value. Variable gets ownership.
* @param v New value. Variable gets ownership. Cannot be NULL.
*/
Variable &set(Value *v);

/**
* Sets the value of the variable.
*
* @param v New value. Variable gets ownership.
* @param v New value. Variable gets ownership. Cannot be NULL.
*/
Variable &operator = (Value *v);

Expand Down
3 changes: 1 addition & 2 deletions doomsday/libdeng2/src/filesys/file.cpp
Expand Up @@ -326,7 +326,6 @@ File *File::reinterpret()
{
Folder *folder = parent();
File *original = source();
File *result = this;
bool deleteThis = false;

if(original != this)
Expand All @@ -342,7 +341,7 @@ File *File::reinterpret()
}

original->flush();
result = fileSystem().interpret(original);
File *result = fileSystem().interpret(original);

// The interpreter should use whatever origin feed the file was previously using.
result->setOriginFeed(d->originFeed);
Expand Down
63 changes: 31 additions & 32 deletions doomsday/libdeng2/src/scriptsys/builtinexpression.cpp
Expand Up @@ -56,31 +56,30 @@ void BuiltInExpression::push(Evaluator &evaluator, Record *) const
Value *BuiltInExpression::evaluate(Evaluator &evaluator) const
{
std::auto_ptr<Value> value(evaluator.popResult());
ArrayValue *args = dynamic_cast<ArrayValue *>(value.get());
DENG2_ASSERT(args != NULL); // must be an array
ArrayValue const &args = value.get()->as<ArrayValue>();

switch(_type)
{
case LENGTH:
if(args->size() != 2)
if(args.size() != 2)
{
throw WrongArgumentsError("BuiltInExpression::evaluate",
"Expected exactly one argument for LENGTH");
}
return new NumberValue(args->at(1).size());
return new NumberValue(args.at(1).size());

case DICTIONARY_KEYS:
case DICTIONARY_VALUES:
{
if(args->size() != 2)
if(args.size() != 2)
{
throw WrongArgumentsError("BuiltInExpression::evaluate",
"Expected exactly one argument for " +
String(_type == DICTIONARY_KEYS?
"DICTIONARY_KEYS" : "DICTIONARY_VALUES"));
}

DictionaryValue const *dict = dynamic_cast<DictionaryValue const *>(&args->at(1));
DictionaryValue const *dict = dynamic_cast<DictionaryValue const *>(&args.at(1));
if(!dict)
{
throw WrongArgumentsError("BuiltInExpression::evaluate",
Expand All @@ -105,14 +104,14 @@ Value *BuiltInExpression::evaluate(Evaluator &evaluator) const
case RECORD_MEMBERS:
case RECORD_SUBRECORDS:
{
if(args->size() != 2)
if(args.size() != 2)
{
throw WrongArgumentsError("BuiltInExpression::evaluate",
"Expected exactly one argument for " +
String(_type == RECORD_MEMBERS? "RECORD_MEMBERS" : "RECORD_SUBRECORDS"));
}

RecordValue const *rec = dynamic_cast<RecordValue const *>(&args->at(1));
RecordValue const *rec = dynamic_cast<RecordValue const *>(&args.at(1));
if(!rec)
{
throw WrongArgumentsError("BuiltInExpression::evaluate",
Expand Down Expand Up @@ -140,15 +139,15 @@ Value *BuiltInExpression::evaluate(Evaluator &evaluator) const

case AS_RECORD:
{
if(args->size() == 1)
if(args.size() == 1)
{
// No arguments: produce an owned, empty Record.
return new RecordValue(new Record, RecordValue::OwnsRecord);
}
if(args->size() == 2)
if(args.size() == 2)
{
// One argument: make an owned copy of a referenced record.
RecordValue const *rec = dynamic_cast<RecordValue const *>(&args->at(1));
RecordValue const *rec = dynamic_cast<RecordValue const *>(&args.at(1));
if(!rec)
{
throw WrongArgumentsError("BuiltInExpression::evaluate",
Expand All @@ -161,34 +160,34 @@ Value *BuiltInExpression::evaluate(Evaluator &evaluator) const
}

case AS_NUMBER:
if(args->size() != 2)
if(args.size() != 2)
{
throw WrongArgumentsError("BuiltInExpression::evaluate",
"Expected exactly one argument for AS_NUMBER");
}
return new NumberValue(args->at(1).asNumber());
return new NumberValue(args.at(1).asNumber());

case AS_TEXT:
if(args->size() != 2)
if(args.size() != 2)
{
throw WrongArgumentsError("BuiltInExpression::evaluate",
"Expected exactly one argument for AS_TEXT");
}
return new TextValue(args->at(1).asText());
return new TextValue(args.at(1).asText());

case AS_TIME:
if(args->size() == 1)
if(args.size() == 1)
{
// Current time.
return new TimeValue;
}
if(args->size() == 2)
if(args.size() == 2)
{
Time t = Time::fromText(args->at(1).asText());
Time t = Time::fromText(args.at(1).asText());
if(!t.isValid())
{
// Maybe just a date?
t = Time::fromText(args->at(1).asText(), Time::ISODateOnly);
t = Time::fromText(args.at(1).asText(), Time::ISODateOnly);
}
return new TimeValue(t);
}
Expand All @@ -197,17 +196,17 @@ Value *BuiltInExpression::evaluate(Evaluator &evaluator) const

case TIME_DELTA:
{
if(args->size() != 3)
if(args.size() != 3)
{
throw WrongArgumentsError("BuiltInExpression::evaluate",
"Expected exactly two arguments for TIME_DELTA");
}
TimeValue const *fromTime = dynamic_cast<TimeValue const *>(&args->at(1));
TimeValue const *fromTime = dynamic_cast<TimeValue const *>(&args.at(1));
if(!fromTime)
{
throw WrongArgumentsError("BuiltInExpression::evaluate", "Argument 1 of TIME_DELTA must be a time");
}
TimeValue const *toTime = dynamic_cast<TimeValue const *>(&args->at(2));
TimeValue const *toTime = dynamic_cast<TimeValue const *>(&args.at(2));
if(!toTime)
{
throw WrongArgumentsError("BuiltInExpression::evaluate", "Argument 2 of TIME_DELTA must be a time");
Expand All @@ -217,7 +216,7 @@ Value *BuiltInExpression::evaluate(Evaluator &evaluator) const

case LOCAL_NAMESPACE:
{
if(args->size() != 1)
if(args.size() != 1)
{
throw WrongArgumentsError("BuiltInExpression::evaluate",
"No arguments expected for LOCAL_NAMESPACE");
Expand All @@ -227,32 +226,32 @@ Value *BuiltInExpression::evaluate(Evaluator &evaluator) const

case SERIALIZE:
{
if(args->size() != 2)
if(args.size() != 2)
{
throw WrongArgumentsError("BuiltInExpression::evaluate",
"Expected exactly one argument for SERIALIZE");
}
std::auto_ptr<BlockValue> data(new BlockValue);
Writer(*data.get()) << args->at(1);
Writer(*data.get()) << args.at(1);
return data.release();
}

case DESERIALIZE:
{
if(args->size() != 2)
if(args.size() != 2)
{
throw WrongArgumentsError("BuiltInExpression::evaluate",
"Expected exactly one argument for DESERIALIZE");
}
BlockValue const *block = dynamic_cast<BlockValue const *>(&args->at(1));
BlockValue const *block = dynamic_cast<BlockValue const *>(&args.at(1));
if(block)
{
Reader reader(*block);
return Value::constructFrom(reader);
}
/*
// Alternatively allow deserializing from a text value.
TextValue const *text = dynamic_cast<TextValue const *>(&args->at(1));
TextValue const *text = dynamic_cast<TextValue const *>(&args.at(1));
if(text)
{
return Value::constructFrom(Reader(Block(text->asText().toUtf8())));
Expand All @@ -263,24 +262,24 @@ Value *BuiltInExpression::evaluate(Evaluator &evaluator) const
}

case FLOOR:
if(args->size() != 2)
if(args.size() != 2)
{
throw WrongArgumentsError("BuiltInExpression::evaluate",
"Expected exactly one argument for FLOOR");
}
return new NumberValue(std::floor(args->at(1).asNumber()));
return new NumberValue(std::floor(args.at(1).asNumber()));

case EVALUATE:
{
if(args->size() != 2)
if(args.size() != 2)
{
throw WrongArgumentsError("BuiltInExpression::evaluate",
"Expected exactly one argument for EVALUATE");
}
// Set up a subprocess in the local namespace.
Process subProcess(evaluator.localNamespace());
// Parse the argument as a script.
Script subScript(args->at(1).asText());
Script subScript(args.at(1).asText());
subProcess.run(subScript);
subProcess.execute();
// A copy of the result value is returned.
Expand Down
2 changes: 1 addition & 1 deletion doomsday/libdeng2/src/widgets/rulerectangle.cpp
Expand Up @@ -210,7 +210,7 @@ DENG2_PIMPL(RuleRectangle)
{
outputRules[deltaOutput]->setSource(*outputRules[maxOutput] - *outputRules[minOutput]);

deltaDefined = true;
//deltaDefined = true;
}
}
};
Expand Down

0 comments on commit 1cd1082

Please sign in to comment.