Skip to content

Commit

Permalink
Change naming convention on intern string class in runtime library. (#…
Browse files Browse the repository at this point in the history
…1193)

* Class rename RtIdentifier -> RtString

* Rename namespace with string constants

* Change data type name from 'identifier' to 'internstring'

* Fix codacy issue

* Move all intern string constants into RtString class
  • Loading branch information
niklasharrysson authored May 13, 2021
1 parent 3df99ab commit 5e01cf4
Show file tree
Hide file tree
Showing 97 changed files with 1,820 additions and 1,860 deletions.
31 changes: 15 additions & 16 deletions source/MaterialXRuntime/Codegen/RtSourceCodeImpl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@

#include <MaterialXRuntime/Codegen/RtSourceCodeImpl.h>
#include <MaterialXRuntime/RtApi.h>
#include <MaterialXRuntime/Identifiers.h>

#include <MaterialXRuntime/Private/PvtPath.h>
#include <MaterialXRuntime/Private/PvtPrim.h>
Expand All @@ -18,12 +17,12 @@ namespace MaterialX

DEFINE_TYPED_SCHEMA(RtSourceCodeImpl, "nodeimpl:sourcecodeimpl");

RtPrim RtSourceCodeImpl::createPrim(const RtIdentifier& typeName, const RtIdentifier& name, RtPrim parent)
RtPrim RtSourceCodeImpl::createPrim(const RtString& typeName, const RtString& name, RtPrim parent)
{
PvtPrim::validateCreation(_typeInfo, typeName, name, parent.getPath());

static const RtIdentifier DEFAULT_NAME("sourcecodeimpl1");
const RtIdentifier primName = name == EMPTY_IDENTIFIER ? DEFAULT_NAME : name;
static const RtString DEFAULT_NAME("sourcecodeimpl1");
const RtString primName = name.empty() ? DEFAULT_NAME : name;
PvtObjHandle primH = PvtPrim::createNew(&_typeInfo, primName, PvtObject::cast<PvtPrim>(parent));

return primH;
Expand All @@ -37,7 +36,7 @@ const RtPrimSpec& RtSourceCodeImpl::getPrimSpec() const

void RtSourceCodeImpl::setFile(const string& file)
{
RtTypedValue* attr = prim()->createAttribute(Identifiers::FILE, RtType::STRING);
RtTypedValue* attr = prim()->createAttribute(RtString::FILE, RtType::STRING);
attr->asString() = file;

const FilePath path = RtApi::get().getSearchPath().find(file);
Expand All @@ -52,43 +51,43 @@ void RtSourceCodeImpl::setFile(const string& file)

const string& RtSourceCodeImpl::getFile() const
{
RtTypedValue* attr = prim()->getAttribute(Identifiers::FILE, RtType::STRING);
RtTypedValue* attr = prim()->getAttribute(RtString::FILE, RtType::STRING);
return attr ? attr->asString() : EMPTY_STRING;
}

void RtSourceCodeImpl::setSourceCode(const string& source)
{
RtTypedValue* attr = prim()->createAttribute(Identifiers::SOURCECODE, RtType::STRING);
RtTypedValue* attr = prim()->createAttribute(RtString::SOURCECODE, RtType::STRING);
attr->asString() = source;
}

const string& RtSourceCodeImpl::getSourceCode() const
{
RtTypedValue* attr = prim()->getAttribute(Identifiers::SOURCECODE, RtType::STRING);
RtTypedValue* attr = prim()->getAttribute(RtString::SOURCECODE, RtType::STRING);
return attr ? attr->asString() : EMPTY_STRING;
}

void RtSourceCodeImpl::setFormat(const RtIdentifier& format)
void RtSourceCodeImpl::setFormat(const RtString& format)
{
RtTypedValue* attr = prim()->createAttribute(Identifiers::FORMAT, RtType::IDENTIFIER);
attr->asIdentifier() = format;
RtTypedValue* attr = prim()->createAttribute(RtString::FORMAT, RtType::INTERNSTRING);
attr->asInternString() = format;
}

const RtIdentifier& RtSourceCodeImpl::getFormat() const
const RtString& RtSourceCodeImpl::getFormat() const
{
RtTypedValue* attr = prim()->getAttribute(Identifiers::FORMAT, RtType::IDENTIFIER);
return attr ? attr->asIdentifier() : Identifiers::SHADER;
RtTypedValue* attr = prim()->getAttribute(RtString::FORMAT, RtType::INTERNSTRING);
return attr ? attr->asInternString() : RtString::SHADER;
}

void RtSourceCodeImpl::setFunction(const string& source)
{
RtTypedValue* attr = prim()->createAttribute(Identifiers::FUNCTION, RtType::STRING);
RtTypedValue* attr = prim()->createAttribute(RtString::FUNCTION, RtType::STRING);
attr->asString() = source;
}

const string& RtSourceCodeImpl::getFunction() const
{
RtTypedValue* attr = prim()->getAttribute(Identifiers::FUNCTION, RtType::STRING);
RtTypedValue* attr = prim()->getAttribute(RtString::FUNCTION, RtType::STRING);
return attr ? attr->asString() : EMPTY_STRING;
}

Expand Down
4 changes: 2 additions & 2 deletions source/MaterialXRuntime/Codegen/RtSourceCodeImpl.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,10 @@ class RtSourceCodeImpl : public RtCodegenImpl
const string& getSourceCode() const;

/// Set the format used by the source code in this implementation.
void setFormat(const RtIdentifier& format);
void setFormat(const RtString& format);

/// Return the format used by the source code in this implementation.
const RtIdentifier& getFormat() const;
const RtString& getFormat() const;

/// Set the function name to use for this implementation.
void setFunction(const string& function);
Expand Down
9 changes: 4 additions & 5 deletions source/MaterialXRuntime/Codegen/RtSubGraphImpl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
//

#include <MaterialXRuntime/Codegen/RtSubGraphImpl.h>
#include <MaterialXRuntime/Identifiers.h>

#include <MaterialXRuntime/Private/PvtPath.h>
#include <MaterialXRuntime/Private/PvtPrim.h>
Expand All @@ -14,16 +13,16 @@ namespace MaterialX

DEFINE_TYPED_SCHEMA(RtSubGraphImpl, "nodeimpl:subgraphimpl");

RtPrim RtSubGraphImpl::createPrim(const RtIdentifier& typeName, const RtIdentifier& name, RtPrim parent)
RtPrim RtSubGraphImpl::createPrim(const RtString& typeName, const RtString& name, RtPrim parent)
{
PvtPrim::validateCreation(_typeInfo, typeName, name, parent.getPath());

static const RtIdentifier DEFAULT_NAME("subgraphimpl1");
const RtIdentifier primName = name == EMPTY_IDENTIFIER ? DEFAULT_NAME : name;
static const RtString DEFAULT_NAME("subgraphimpl1");
const RtString primName = name.empty() ? DEFAULT_NAME : name;
PvtObjHandle primH = PvtPrim::createNew(&_typeInfo, primName, PvtObject::cast<PvtPrim>(parent));

PvtPrim* prim = primH->asA<PvtPrim>();
prim->createRelationship(Identifiers::NODEIMPL);
prim->createRelationship(RtString::NODEIMPL);

return primH;
}
Expand Down
4 changes: 2 additions & 2 deletions source/MaterialXRuntime/Commands/AttributeCommands.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ namespace MaterialX
namespace RtCommand
{

void setAttributeFromString(const RtObject& obj, const RtIdentifier& name, const string& value, RtCommandResult& result)
void setAttributeFromString(const RtObject& obj, const RtString& name, const string& value, RtCommandResult& result)
{
// Use try/catch since the conversion from string might fail and throw.
try
Expand All @@ -33,7 +33,7 @@ void setAttributeFromString(const RtObject& obj, const RtIdentifier& name, const
}
}

void removeAttribute(const RtObject& obj, const RtIdentifier& name, RtCommandResult& result)
void removeAttribute(const RtObject& obj, const RtString& name, RtCommandResult& result)
{
try
{
Expand Down
6 changes: 3 additions & 3 deletions source/MaterialXRuntime/Commands/AttributeCommands.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,18 +10,18 @@
/// Commands for attribute handling.

#include <MaterialXRuntime/RtCommand.h>
#include <MaterialXRuntime/RtIdentifier.h>
#include <MaterialXRuntime/RtString.h>

namespace MaterialX
{

namespace RtCommand
{
/// Set an attribute value from data given as a value string. Creates the attribute if it doesn't exist.
void setAttributeFromString(const RtObject& obj, const RtIdentifier& name, const string& value, RtCommandResult& result);
void setAttributeFromString(const RtObject& obj, const RtString& name, const string& value, RtCommandResult& result);

/// Remove an attribute.
void removeAttribute(const RtObject& obj, const RtIdentifier& name, RtCommandResult& result);
void removeAttribute(const RtObject& obj, const RtString& name, RtCommandResult& result);
}

}
Expand Down
2 changes: 1 addition & 1 deletion source/MaterialXRuntime/Commands/PortCommands.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ void setPortValue(const RtPort& port, const Vector4& value, RtCommandResult& res
PvtApi::cast(RtApi::get())->getCommandEngine().execute(cmd, result);
}

void setPortValue(const RtPort& port, const RtIdentifier& value, RtCommandResult& result)
void setPortValue(const RtPort& port, const RtString& value, RtCommandResult& result)
{
RtValue v(value);
PvtCommandPtr cmd = PvtSetPortValueCmd::create(port, v);
Expand Down
2 changes: 1 addition & 1 deletion source/MaterialXRuntime/Commands/PortCommands.h
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ namespace RtCommand
void setPortValue(const RtPort& port, const Vector4& value, RtCommandResult& result);

/// Set value on a string port.
void setPortValue(const RtPort& port, const RtIdentifier& value, RtCommandResult& result);
void setPortValue(const RtPort& port, const RtString& value, RtCommandResult& result);

/// Set value on a pointer port.
void setPortValue(const RtPort& port, void* value, RtCommandResult& result);
Expand Down
10 changes: 5 additions & 5 deletions source/MaterialXRuntime/Commands/PrimCommands.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,21 +20,21 @@ namespace MaterialX
namespace RtCommand
{

void createPrim(RtStagePtr stage, const RtIdentifier& typeName, RtCommandResult& result)
void createPrim(RtStagePtr stage, const RtString& typeName, RtCommandResult& result)
{
PvtCommandPtr cmd = PvtCreatePrimCmd::create(stage, typeName, RtPath("/"), EMPTY_IDENTIFIER);
PvtCommandPtr cmd = PvtCreatePrimCmd::create(stage, typeName, RtPath("/"), RtString::EMPTY);
PvtApi::cast(RtApi::get())->getCommandEngine().execute(cmd, result);
}

void createPrim(RtStagePtr stage, const RtIdentifier& typeName, const RtPath& path, RtCommandResult& result)
void createPrim(RtStagePtr stage, const RtString& typeName, const RtPath& path, RtCommandResult& result)
{
RtPath parentPath(path);
parentPath.pop();
PvtCommandPtr cmd = PvtCreatePrimCmd::create(stage, typeName, parentPath, path.getName());
PvtApi::cast(RtApi::get())->getCommandEngine().execute(cmd, result);
}

void createPrim(RtStagePtr stage, const RtIdentifier& typeName, const RtPath& parentPath, const RtIdentifier& name, RtCommandResult& result)
void createPrim(RtStagePtr stage, const RtString& typeName, const RtPath& parentPath, const RtString& name, RtCommandResult& result)
{
PvtCommandPtr cmd = PvtCreatePrimCmd::create(stage, typeName, parentPath, name);
PvtApi::cast(RtApi::get())->getCommandEngine().execute(cmd, result);
Expand All @@ -58,7 +58,7 @@ void removePrim(RtStagePtr stage, const RtPath& path, RtCommandResult& result)
PvtApi::cast(RtApi::get())->getCommandEngine().execute(cmd, result);
}

void renamePrim(RtStagePtr stage, const RtPath& path, const RtIdentifier& newName, RtCommandResult& result)
void renamePrim(RtStagePtr stage, const RtPath& path, const RtString& newName, RtCommandResult& result)
{
PvtCommandPtr cmd = PvtRenamePrimCmd::create(stage, path, newName);
PvtApi::cast(RtApi::get())->getCommandEngine().execute(cmd, result);
Expand Down
8 changes: 4 additions & 4 deletions source/MaterialXRuntime/Commands/PrimCommands.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,14 @@ namespace MaterialX
namespace RtCommand
{
/// Create a new prim at the root of the stage.
void createPrim(RtStagePtr stage, const RtIdentifier& typeName, RtCommandResult& result);
void createPrim(RtStagePtr stage, const RtString& typeName, RtCommandResult& result);

/// Create a new prim at the given path.
void createPrim(RtStagePtr stage, const RtIdentifier& typeName, const RtPath& path, RtCommandResult& result);
void createPrim(RtStagePtr stage, const RtString& typeName, const RtPath& path, RtCommandResult& result);

/// Create a new prim inside the parent given by path.
/// If an empty name is given a name will be generated.
void createPrim(RtStagePtr stage, const RtIdentifier& typeName, const RtPath& parentPath, const RtIdentifier& name, RtCommandResult& result);
void createPrim(RtStagePtr stage, const RtString& typeName, const RtPath& parentPath, const RtString& name, RtCommandResult& result);

/// Make a copy of the given prim and place the copy at the same parent path.
void copyPrim(RtStagePtr stage, const RtPrim& prim, RtCommandResult& result);
Expand All @@ -38,7 +38,7 @@ namespace RtCommand
void removePrim(RtStagePtr stage, const RtPath& path, RtCommandResult& result);

/// Rename a prim.
void renamePrim(RtStagePtr stage, const RtPath& path, const RtIdentifier& newName, RtCommandResult& result);
void renamePrim(RtStagePtr stage, const RtPath& path, const RtString& newName, RtCommandResult& result);

/// Reparent a prim.
void reparentPrim(RtStagePtr stage, const RtPath& path, const RtPath& newParentPath, RtCommandResult& result);
Expand Down
79 changes: 0 additions & 79 deletions source/MaterialXRuntime/Identifiers.cpp

This file was deleted.

Loading

0 comments on commit 5e01cf4

Please sign in to comment.