Skip to content

Commit

Permalink
Made a numeric_t typedef to make changing it later on easier
Browse files Browse the repository at this point in the history
This is pretty much related to issue #5, numeric_t currently is still int,
so everything is behaving exactly as it was.
  • Loading branch information
Toon Schoenmakers committed Apr 23, 2014
1 parent cc221a7 commit aa29346
Show file tree
Hide file tree
Showing 13 changed files with 30 additions and 24 deletions.
2 changes: 1 addition & 1 deletion include/data.h
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ class Data
* @return Data Same object for chaining
*/
Data &assign(const char *name, const std::string &value);
Data &assign(const char *name, int value);
Data &assign(const char *name, numeric_t value);
Data &assign(const char *name, Value *value);

/**
Expand Down
4 changes: 2 additions & 2 deletions include/empty.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,9 @@ class EmptyValue : public Value

/**
* Convert the variable to a numeric value
* @return int
* @return numeric
*/
virtual int toNumeric() override
virtual numeric_t toNumeric() override
{
return 0;
}
Expand Down
6 changes: 3 additions & 3 deletions include/map.h
Original file line number Diff line number Diff line change
Expand Up @@ -69,9 +69,9 @@ class MapValue : public Value

/**
* Convert the variable to a numeric value
* @return int
* @return numeric
*/
virtual int toNumeric() override
virtual numeric_t toNumeric() override
{
return 0;
}
Expand Down Expand Up @@ -113,7 +113,7 @@ class MapValue : public Value
* @param value Value of the variable
* @return MapValue Same object for chaining
*/
MapValue& assign(const char *name, int value)
MapValue& assign(const char *name, numeric_t value)
{
// append variable
_values[name] = std::unique_ptr<Value>(new NumericValue(value));
Expand Down
10 changes: 5 additions & 5 deletions include/numeric.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,9 @@ class NumericValue : public Value
private:
/**
* Underlying value
* @var int
* @var numeric
*/
const int _value;
const numeric_t _value;

/**
* String representation
Expand All @@ -35,7 +35,7 @@ class NumericValue : public Value
* Constructor
* @param value
*/
NumericValue(int value) : _value(value) {}
NumericValue(numeric_t value) : _value(value) {}

/**
* Destructor
Expand All @@ -58,9 +58,9 @@ class NumericValue : public Value

/**
* Convert the variable to a numeric value
* @return int
* @return numeric
*/
virtual int toNumeric() override
virtual numeric_t toNumeric() override
{
return _value;
}
Expand Down
8 changes: 4 additions & 4 deletions include/string.h
Original file line number Diff line number Diff line change
Expand Up @@ -49,12 +49,12 @@ class StringValue : public Value

/**
* Convert the variable to a numeric value
* @see std::atoi
* @return int
* @see std::strtoul
* @return numeric
*/
virtual int toNumeric() override
virtual numeric_t toNumeric() override
{
return std::atoi(_value.c_str());
return std::strtoul(_value.c_str(), (char**) NULL, 10);
}

/**
Expand Down
10 changes: 8 additions & 2 deletions include/value.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,12 @@
* Set up namespace
*/
namespace SmartTpl {

/**
* Typedef for a general numeric type, if we ever decide to change it we'll just
* have to modify this.
*/
typedef int numeric_t;

/**
* Class definition
Expand All @@ -28,9 +34,9 @@ class Value

/**
* Convert the variable to a numeric value
* @return int
* @return numeric
*/
virtual int toNumeric() = 0;
virtual numeric_t toNumeric() = 0;

/**
* Convert the variable to a boolean value
Expand Down
2 changes: 1 addition & 1 deletion src/bytecode.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -275,7 +275,7 @@ void Bytecode::string(const std::string &value)
* @param value
* @note +1 on the stack
*/
void Bytecode::numeric(int value)
void Bytecode::numeric(numeric_t value)
{
// push value
_stack.push(_function.new_constant(value, jit_type_sys_int));
Expand Down
2 changes: 1 addition & 1 deletion src/bytecode.h
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ class Bytecode : private Generator, public Executor
* @param value
*/
virtual void string(const std::string &value) override;
virtual void numeric(int value) override;
virtual void numeric(numeric_t value) override;

/**
* Create a string or numeric constant for a variable
Expand Down
2 changes: 1 addition & 1 deletion src/ccode.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,7 @@ void CCode::string(const std::string &value)
* Create a numeric literal
* @param value
*/
void CCode::numeric(int value)
void CCode::numeric(numeric_t value)
{
// output number
_out << value;
Expand Down
2 changes: 1 addition & 1 deletion src/ccode.h
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ class CCode : public Generator
* @param value
*/
virtual void string(const std::string &value) override;
virtual void numeric(int value) override;
virtual void numeric(numeric_t value) override;

/**
* Create a string, numeric or boolean constant for a variable
Expand Down
2 changes: 1 addition & 1 deletion src/data.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ Data &Data::assign(const char *name, const std::string &value)
* @param value Value of the variable
* @return Data Same object for chaining
*/
Data &Data::assign(const char *name, int value)
Data &Data::assign(const char *name, numeric_t value)
{
// append variable
_variables[name] = std::unique_ptr<Value>(new NumericValue(value));
Expand Down
2 changes: 1 addition & 1 deletion src/generator.h
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ class Generator
* @param value
*/
virtual void string(const std::string &value) = 0;
virtual void numeric(int value) = 0;
virtual void numeric(numeric_t value) = 0;
//virtual void boolean(bool value) = 0;

/**
Expand Down
2 changes: 1 addition & 1 deletion src/includes.h
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/**
* Includes.h
*
* Header file that includes all public header files of the SmartTpl library
* Header file that includes all header files of the SmartTpl library
*
* @author Emiel Bruijntjes <[email protected]>
* @copyright 2014 Copernica BV
Expand Down

0 comments on commit aa29346

Please sign in to comment.