Get rid of some dynamic_pointer_casts by updating return types

This commit is contained in:
Aleksei Nikiforov 2020-01-15 18:41:53 +03:00
parent 7a04b13645
commit bb98d8809a
2 changed files with 16 additions and 16 deletions

View File

@ -278,9 +278,9 @@ void CommonStringRecordField::setStringValue(const boost::optional<std::string>
m_value = value;
}
std::shared_ptr<AbstractRecordField> StringRecordField::createRecord(const std::string &name)
std::shared_ptr<StringRecordField> StringRecordField::createRecord(const std::string &name)
{
std::shared_ptr<AbstractRecordField> result;
std::shared_ptr<StringRecordField> result;
result.reset(new StringRecordField(name));
return result;
}
@ -307,9 +307,9 @@ AbstractRecordField::Type StringRecordField::getType() const
return AbstractRecordField::Type::String;
}
std::shared_ptr<AbstractRecordField> InterpretedStringRecordField::createRecord(const std::string &name)
std::shared_ptr<InterpretedStringRecordField> InterpretedStringRecordField::createRecord(const std::string &name)
{
std::shared_ptr<AbstractRecordField> result;
std::shared_ptr<InterpretedStringRecordField> result;
result.reset(new InterpretedStringRecordField(name));
return result;
}
@ -336,9 +336,9 @@ AbstractRecordField::Type InterpretedStringRecordField::getType() const
return AbstractRecordField::Type::InterpretedString;
}
std::shared_ptr<AbstractRecordField> IntegerRecordField::createRecord(const std::string &name)
std::shared_ptr<IntegerRecordField> IntegerRecordField::createRecord(const std::string &name)
{
std::shared_ptr<AbstractRecordField> result;
std::shared_ptr<IntegerRecordField> result;
result.reset(new IntegerRecordField(name));
return result;
}
@ -427,9 +427,9 @@ void IntegerRecordField::setIntValue(const boost::optional<int> &value)
m_int_value = value;
}
std::shared_ptr<AbstractRecordField> InterpretedStringArrayRecordField::createRecord(const std::string &name)
std::shared_ptr<InterpretedStringArrayRecordField> InterpretedStringArrayRecordField::createRecord(const std::string &name)
{
std::shared_ptr<AbstractRecordField> result;
std::shared_ptr<InterpretedStringArrayRecordField> result;
result.reset(new InterpretedStringArrayRecordField(name));
return result;
}
@ -657,7 +657,7 @@ AuditRecord AuditRecord::fromPtree(const boost::property_tree::ptree &data)
{
case AbstractRecordField::Type::Int:
{
auto record_field = std::dynamic_pointer_cast<IntegerRecordField>(IntegerRecordField::createRecord(iter->first));
auto record_field = IntegerRecordField::createRecord(iter->first);
if (record_field)
{
auto int_value = iter->second.get_child_optional("value_int");
@ -679,7 +679,7 @@ AuditRecord AuditRecord::fromPtree(const boost::property_tree::ptree &data)
case AbstractRecordField::Type::String:
{
auto record_field = std::dynamic_pointer_cast<StringRecordField>(StringRecordField::createRecord(iter->first));
auto record_field = StringRecordField::createRecord(iter->first);
if (record_field)
{
auto str_value = iter->second.get_child_optional("value_str");
@ -695,7 +695,7 @@ AuditRecord AuditRecord::fromPtree(const boost::property_tree::ptree &data)
case AbstractRecordField::Type::InterpretedString:
{
auto record_field = std::dynamic_pointer_cast<InterpretedStringRecordField>(InterpretedStringRecordField::createRecord(iter->first));
auto record_field = InterpretedStringRecordField::createRecord(iter->first);
if (record_field)
{
auto str_value = iter->second.get_child_optional("value_str");
@ -711,7 +711,7 @@ AuditRecord AuditRecord::fromPtree(const boost::property_tree::ptree &data)
case AbstractRecordField::Type::InterpretedStringArray:
{
auto record_field = std::dynamic_pointer_cast<InterpretedStringArrayRecordField>(InterpretedStringArrayRecordField::createRecord(iter->first));
auto record_field = InterpretedStringArrayRecordField::createRecord(iter->first);
if (record_field)
{
std::list<std::string> names, values;

View File

@ -118,7 +118,7 @@ protected:
class StringRecordField: public CommonStringRecordField
{
public:
static std::shared_ptr<AbstractRecordField> createRecord(const std::string &name);
static std::shared_ptr<StringRecordField> createRecord(const std::string &name);
virtual void addOrUpdateValue(auparse_state_t *record) override;
virtual Type getType() const override;
@ -130,7 +130,7 @@ protected:
class InterpretedStringRecordField: public CommonStringRecordField
{
public:
static std::shared_ptr<AbstractRecordField> createRecord(const std::string &name);
static std::shared_ptr<InterpretedStringRecordField> createRecord(const std::string &name);
virtual void addOrUpdateValue(auparse_state_t *record) override;
virtual Type getType() const override;
@ -142,7 +142,7 @@ protected:
class IntegerRecordField: public InterpretedStringRecordField
{
public:
static std::shared_ptr<AbstractRecordField> createRecord(const std::string &name);
static std::shared_ptr<IntegerRecordField> createRecord(const std::string &name);
virtual void addOrUpdateValue(auparse_state_t *record) override;
virtual std::vector<Column> generateColumnsAndNames() const override;
@ -161,7 +161,7 @@ protected:
class InterpretedStringArrayRecordField: public AbstractRecordField
{
public:
static std::shared_ptr<AbstractRecordField> createRecord(const std::string &name);
static std::shared_ptr<InterpretedStringArrayRecordField> createRecord(const std::string &name);
virtual void addOrUpdateValue(auparse_state_t *record) override;
virtual std::vector<Column> generateColumnsAndNames() const override;