Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

clang-tidy: use dynamic cast #1670

Merged
merged 1 commit into from
May 20, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 14 additions & 15 deletions samples/Jzon.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -92,37 +92,37 @@ namespace Jzon
Object &Node::AsObject()
{
if (IsObject())
return static_cast<Object&>(*this);
return dynamic_cast<Object &>(*this);
throw TypeException();
}
const Object &Node::AsObject() const
{
if (IsObject())
return static_cast<const Object&>(*this);
return dynamic_cast<const Object &>(*this);
throw TypeException();
}
Array &Node::AsArray()
{
if (IsArray())
return static_cast<Array &>(*this);
return dynamic_cast<Array &>(*this);
throw TypeException();
}
const Array &Node::AsArray() const
{
if (IsArray())
return static_cast<const Array &>(*this);
return dynamic_cast<const Array &>(*this);
throw TypeException();
}
Value &Node::AsValue()
{
if (IsValue())
return static_cast<Value &>(*this);
return dynamic_cast<Value &>(*this);
throw TypeException();
}
const Value &Node::AsValue() const
{
if (IsValue())
return static_cast<const Value &>(*this);
return dynamic_cast<const Value &>(*this);
throw TypeException();
}

Expand Down Expand Up @@ -1072,15 +1072,14 @@ namespace Jzon

if (data.front().first == Value::VT_STRING)
{
static_cast<Value*>(node)->Set(data.front().second); // This method calls UnescapeString()
}
else
{
static_cast<Value*>(node)->Set(data.front().first, data.front().second);
}
data.pop();

if (!nodeStack.empty())
dynamic_cast<Value *>(node)->Set(
data.front().second); // This method calls UnescapeString()
} else {
dynamic_cast<Value *>(node)->Set(data.front().first, data.front().second);
}
data.pop();

if (!nodeStack.empty())
{
if (nodeStack.top().second->IsObject())
nodeStack.top().second->AsObject().Add(name, *node);
Expand Down
4 changes: 2 additions & 2 deletions samples/exiv2json.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ Jzon::Node& addToTree(Jzon::Node& r1, const Token& token)

std::string key = token.n ;
size_t index = token.i-1; // array Eg: "History[1]" indexed from 1. Jzon expects 0 based index.
Jzon::Node& empty = token.a ? (Jzon::Node&) array : (Jzon::Node&) object ;
auto& empty = token.a ? static_cast<Jzon::Node&>(array) : static_cast<Jzon::Node&>(object);

if ( r1.IsObject() ) {
Jzon::Object& o1 = r1.AsObject();
Expand Down Expand Up @@ -246,7 +246,7 @@ void push(Jzon::Node& node,const std::string& key,T i)

void fileSystemPush(const char* path,Jzon::Node& nfs)
{
auto& fs = (Jzon::Object&)nfs;
auto& fs = dynamic_cast<Jzon::Object&>(nfs);
fs.Add("path",path);
char resolved_path[2000]; // PATH_MAX];
fs.Add("realpath",realpath(path,resolved_path));
Expand Down