Skip to content

Commit 21d2c4e

Browse files
committed
Variable: Refactor
1 parent bd1360c commit 21d2c4e

File tree

2 files changed

+11
-20
lines changed

2 files changed

+11
-20
lines changed

src/scratch/variable.cpp

Lines changed: 3 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
using namespace libscratchcpp;
66

77
/*! Constructs Variable. */
8-
Variable::Variable(std::string id, std::string name, Value value, bool isCloudVariable) :
8+
Variable::Variable(const std::string &id, const std::string &name, const Value &value, bool isCloudVariable) :
99
m_name(name),
1010
m_value(value),
1111
m_isCloudVariable(isCloudVariable)
@@ -14,29 +14,17 @@ Variable::Variable(std::string id, std::string name, Value value, bool isCloudVa
1414
}
1515

1616
/*! Constructs an empty Variable. */
17-
Variable::Variable(std::string id, std::string name, bool isCloudVariable) :
17+
Variable::Variable(const std::string &id, const std::string &name, bool isCloudVariable) :
1818
Variable(id, name, Value(), isCloudVariable)
1919
{
2020
}
2121

2222
/*! Returns the name of the variable. */
23-
std::string Variable::name() const
23+
const std::string &Variable::name() const
2424
{
2525
return m_name;
2626
}
2727

28-
/*! Returns the value. */
29-
const Value &Variable::value() const
30-
{
31-
return m_value;
32-
}
33-
34-
/*! Sets the value. */
35-
void Variable::setValue(const Value &value)
36-
{
37-
m_value = value;
38-
}
39-
4028
/*! Returns true if the variable is a cloud variable. */
4129
bool Variable::isCloudVariable() const
4230
{

src/scratch/variable.h

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,14 +13,17 @@ namespace libscratchcpp
1313
class LIBSCRATCHCPP_EXPORT Variable : public IEntity
1414
{
1515
public:
16-
Variable(std::string id, std::string name, Value value = Value(), bool isCloudVariable = false);
17-
Variable(std::string id, std::string name, bool isCloudVariable);
16+
Variable(const std::string &id, const std::string &name, const Value &value = Value(), bool isCloudVariable = false);
17+
Variable(const std::string &id, const std::string &name, bool isCloudVariable);
1818
Variable(const Variable &) = delete;
1919

20-
std::string name() const;
20+
const std::string &name() const;
2121

22-
const Value &value() const;
23-
void setValue(const Value &value);
22+
/*! Returns the value. */
23+
inline const Value &value() const { return m_value; }
24+
25+
/*! Sets the value. */
26+
inline void setValue(const Value &value) { m_value = value; }
2427

2528
bool isCloudVariable() const;
2629
void setIsCloudVariable(bool isCloudVariable);

0 commit comments

Comments
 (0)