Skip to content

Commit

Permalink
created SchemaFile accessor for DOM elements
Browse files Browse the repository at this point in the history
  • Loading branch information
aagrawal05 committed Apr 2, 2024
1 parent 6d3672c commit 55260ad
Show file tree
Hide file tree
Showing 66 changed files with 383 additions and 1 deletion.
Binary file added .DS_Store
Binary file not shown.
72 changes: 72 additions & 0 deletions format_schema.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
import os

lines = os.listdir('./sdf/1.11/')
# Only keep the files that end with .sdf
lines = [line for line in lines if line.endswith('.sdf')]

for line in lines:
# Remove .sdf extension
snake_case = line.strip().split('.')[0]

# Convert from snake_case to CamelCase
camel_case = ''.join([word.capitalize() for word in snake_case.split('_')])

addHeader = """
/// \\brief Get the schema file name accessor
public: static const std::string& SchemaFile();
"""

addImpl = f"""
/////////////////////////////////////////////////
const std::string& {camel_case}::SchemaFile()
{{
static const std::string* kSchemaFile = new std::string("{line}");
return *kSchemaFile;
}}"""

addTest = f"""EXPECT_EQ({camel_case}::SchemaFile(), "{line}");"""

# Debug print statements
# print(addHeader)
# print(addImpl)
# print(addTest)
# print("\n")

# Edit './include/sdf/{camel_case}.hh'
# Find the line with 'class SDFFORMAT_VISIBLE {camel_case}`
try:
f = open('./include/sdf/' + camel_case + '.hh', 'r')
lines = f.readlines()
f.close()
line_number = 0
for i, line in enumerate(lines):
if line == " class SDFORMAT_VISIBLE " + camel_case + '\n':
line_number = i+3 # After the class line there is `\n{\n` and then the constructor
break
if line_number == 0:
print("Error: Could not find class declaration in " + camel_case + ".hh")
exit(1)

try:
with open('./include/sdf/' + camel_case + '.hh', 'w') as file:
for i, line in enumerate(lines):
file.write(line)
if i == line_number:
file.write(addHeader)
except:
print("Unexpected error while writing to: " + camel_case + ".hh.")
except:
print("Error while writing to: " + camel_case + ".hh." + " Check if file exists.")

# Edit './src/{camel_case}.cc' if it exists
# Add implementation to end of document
if os.path.exists('./src/' + camel_case + '.cc'):
with open('./src/' + camel_case + '.cc', 'a') as file:
file.write(addImpl)
else:
print("Error: Could not find " + camel_case + ".cc")

print("Changes written to source successfully")

# TODO: Add tests
# Edit './test/{camel_case}_TEST.cc'
3 changes: 3 additions & 0 deletions include/sdf/Actor.hh
Original file line number Diff line number Diff line change
Expand Up @@ -193,6 +193,9 @@ namespace sdf
/// \brief Default constructor
public: Actor();

/// \brief Get the schema file name accessor
public: static const std::string& SchemaFile();

/// \brief Load the actor based on a element pointer. This is *not* the
/// usual entry point. Typical usage of the SDF DOM is through the Root
/// object.
Expand Down
3 changes: 3 additions & 0 deletions include/sdf/AirPressure.hh
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,9 @@ namespace sdf
/// \brief Default constructor
public: AirPressure();

/// \brief Get the schema file name accessor
public: static const std::string& SchemaFile();

/// \brief Load the airPressure based on an element pointer.
/// This is *not* the usual entry point. Typical usage of the SDF DOM is
/// through the Root object.
Expand Down
3 changes: 3 additions & 0 deletions include/sdf/AirSpeed.hh
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,9 @@ namespace sdf
/// \brief Default constructor
public: AirSpeed();

/// \brief Get the schema file name accessor
public: static const std::string& SchemaFile();

/// \brief Load the air speed based on an element pointer.
/// This is *not* the usual entry point. Typical usage of the SDF DOM is
/// through the Root object.
Expand Down
3 changes: 3 additions & 0 deletions include/sdf/Altimeter.hh
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,9 @@ namespace sdf
/// \brief Default constructor
public: Altimeter();

/// \brief Get the schema file name accessor
public: static const std::string& SchemaFile();

/// \brief Load the altimeter based on an element pointer. This is *not*
/// the usual entry point. Typical usage of the SDF DOM is through the Root
/// object.
Expand Down
3 changes: 3 additions & 0 deletions include/sdf/Atmosphere.hh
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,9 @@ namespace sdf
/// \brief Default constructor
public: Atmosphere();

/// \brief Get the schema file name accessor
public: static const std::string& SchemaFile();

/// \brief Load the atmosphere based on a element pointer. This is *not* the
/// usual entry point. Typical usage of the SDF DOM is through the Root
/// object.
Expand Down
3 changes: 3 additions & 0 deletions include/sdf/Camera.hh
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,9 @@ namespace sdf
/// \brief Constructor
public: Camera();

/// \brief Get the schema file name accessor
public: static const std::string& SchemaFile();

/// \brief Return true if both Camera objects contain the same values.
/// \param[_in] _alt Camera value to compare.
/// \returen True if 'this' == _alt.
Expand Down
3 changes: 3 additions & 0 deletions include/sdf/Collision.hh
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,9 @@ namespace sdf
/// \brief Default constructor
public: Collision();

/// \brief Get the schema file name accessor
public: static const std::string& SchemaFile();

/// \brief Load the collision based on a element pointer. This is *not* the
/// usual entry point. Typical usage of the SDF DOM is through the Root
/// object.
Expand Down
3 changes: 3 additions & 0 deletions include/sdf/ForceTorque.hh
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,9 @@ namespace sdf
/// \brief Default constructor
public: ForceTorque();

/// \brief Get the schema file name accessor
public: static const std::string& SchemaFile();

/// \brief Load the force torque sensor based on an element pointer. This is
/// *not* the usual entry point. Typical usage of the SDF DOM is through the
/// Root object.
Expand Down
3 changes: 3 additions & 0 deletions include/sdf/Frame.hh
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,9 @@ namespace sdf
/// \brief Default constructor
public: Frame();

/// \brief Get the schema file name accessor
public: static const std::string& SchemaFile();

/// \brief Load the frame based on a element pointer. This is *not* the
/// usual entry point. Typical usage of the SDF DOM is through the Root
/// object.
Expand Down
3 changes: 3 additions & 0 deletions include/sdf/Geometry.hh
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,9 @@ namespace sdf
/// \brief Default constructor
public: Geometry();

/// \brief Get the schema file name accessor
public: static const std::string& SchemaFile();

/// \brief Load the geometry based on a element pointer. This is *not* the
/// usual entry point. Typical usage of the SDF DOM is through the Root
/// object.
Expand Down
3 changes: 3 additions & 0 deletions include/sdf/Gui.hh
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,9 @@ namespace sdf
/// \brief Default constructor
public: Gui();

/// \brief Get the schema file name accessor
public: static const std::string& SchemaFile();

/// \brief Load the gui based on a element pointer. This is *not* the
/// usual entry point. Typical usage of the SDF DOM is through the Root
/// object.
Expand Down
3 changes: 3 additions & 0 deletions include/sdf/Imu.hh
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,9 @@ namespace sdf
/// \brief Default constructor
public: Imu();

/// \brief Get the schema file name accessor
public: static const std::string& SchemaFile();

/// \brief Load the IMU based on an element pointer. This is *not*
/// the usual entry point. Typical usage of the SDF DOM is through the Root
/// object.
Expand Down
3 changes: 3 additions & 0 deletions include/sdf/Joint.hh
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,9 @@ namespace sdf
/// \brief Default constructor
public: Joint();

/// \brief Get the schema file name accessor
public: static const std::string& SchemaFile();

/// \brief Load the joint based on a element pointer. This is *not* the
/// usual entry point. Typical usage of the SDF DOM is through the Root
/// object.
Expand Down
3 changes: 3 additions & 0 deletions include/sdf/Lidar.hh
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,9 @@ namespace sdf
/// \brief Default constructor
public: Lidar();

/// \brief Get the schema file name accessor
public: static const std::string& SchemaFile();

/// \brief Load the lidar based on an element pointer. This is *not*
/// the usual entry point. Typical usage of the SDF DOM is through the Root
/// object.
Expand Down
3 changes: 3 additions & 0 deletions include/sdf/Light.hh
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,9 @@ namespace sdf
/// \brief Default constructor
public: Light();

/// \brief Get the schema file name accessor
public: static const std::string& SchemaFile();

/// \brief Load the light based on a element pointer. This is *not* the
/// usual entry point. Typical usage of the SDF DOM is through the Root
/// object.
Expand Down
3 changes: 3 additions & 0 deletions include/sdf/Link.hh
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,9 @@ namespace sdf
/// \brief Default constructor
public: Link();

/// \brief Get the schema file name accessor
public: static const std::string& SchemaFile();

/// \brief Load the link based on a element pointer. This is *not* the
/// usual entry point. Typical usage of the SDF DOM is through the Root
/// object.
Expand Down
3 changes: 3 additions & 0 deletions include/sdf/Magnetometer.hh
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,9 @@ namespace sdf
/// \brief Default constructor
public: Magnetometer();

/// \brief Get the schema file name accessor
public: static const std::string& SchemaFile();

/// \brief Load the magnetometer based on an element pointer. This is *not*
/// the usual entry point. Typical usage of the SDF DOM is through the Root
/// object.
Expand Down
3 changes: 3 additions & 0 deletions include/sdf/Material.hh
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,9 @@ namespace sdf
/// \brief Default constructor
public: Material();

/// \brief Get the schema file name accessor
public: static const std::string& SchemaFile();

/// \brief Load the material based on a element pointer. This is *not* the
/// usual entry point. Typical usage of the SDF DOM is through the Root
/// object.
Expand Down
3 changes: 3 additions & 0 deletions include/sdf/Model.hh
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,9 @@ namespace sdf
/// \brief Default constructor
public: Model();

/// \brief Get the schema file name accessor
public: static const std::string& SchemaFile();

/// \brief Load the model based on a element pointer. This is *not* the
/// usual entry point. Typical usage of the SDF DOM is through the Root
/// object.
Expand Down
5 changes: 4 additions & 1 deletion include/sdf/NavSat.hh
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,10 @@ namespace sdf
{
/// \brief Default constructor
public: NavSat();
/// \brief Load the navsat based on an element pointer. This is *not*

/// \brief Get the schema file name accessor
public: static const std::string& SchemaFile();
/// \brief Load the navsat based on an element pointer. This is *not*
/// the usual entry point. Typical usage of the SDF DOM is through the Root
/// object.
/// \param[in] _sdf The SDF Element pointer
Expand Down
3 changes: 3 additions & 0 deletions include/sdf/Noise.hh
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,9 @@ namespace sdf
/// \brief Default constructor
public: Noise();

/// \brief Get the schema file name accessor
public: static const std::string& SchemaFile();

/// \brief Return true if both Noise objects contain the same values.
/// \param[_in] _noise Noise value to compare.
/// \return True if 'this' == _noise.
Expand Down
3 changes: 3 additions & 0 deletions include/sdf/ParticleEmitter.hh
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,9 @@ namespace sdf
/// \brief Default constructor
public: ParticleEmitter();

/// \brief Get the schema file name accessor
public: static const std::string& SchemaFile();

/// \brief Load the particle emitter based on an element pointer. This is
/// *not* the usual entry point. Typical usage of the SDF DOM is through
/// the Root object.
Expand Down
3 changes: 3 additions & 0 deletions include/sdf/Physics.hh
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,9 @@ namespace sdf
/// \brief Default constructor
public: Physics();

/// \brief Get the schema file name accessor
public: static const std::string& SchemaFile();

/// \brief Load the physics based on an element pointer. This is *not* the
/// usual entry point. Typical usage of the SDF DOM is through the Root
/// object.
Expand Down
3 changes: 3 additions & 0 deletions include/sdf/Plugin.hh
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,9 @@ namespace sdf
/// \brief Default constructor
public: Plugin();

/// \brief Get the schema file name accessor
public: static const std::string& SchemaFile();

/// \brief Default destructor
public: ~Plugin();

Expand Down
3 changes: 3 additions & 0 deletions include/sdf/Projector.hh
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,9 @@ namespace sdf
/// \brief Default constructor
public: Projector();

/// \brief Get the schema file name accessor
public: static const std::string& SchemaFile();

/// \brief Load the projector based on an element pointer. This is
/// *not* the usual entry point. Typical usage of the SDF DOM is through
/// the Root object.
Expand Down
3 changes: 3 additions & 0 deletions include/sdf/Root.hh
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,9 @@ namespace sdf
/// \brief Default constructor
public: Root();

/// \brief Get the schema file name accessor
public: static const std::string& SchemaFile();

/// \brief Get the name of the world without loading the entire world
/// Users shouldn't normally need to use this API.
/// This doesn't load the world, it might return the world name even if the
Expand Down
3 changes: 3 additions & 0 deletions include/sdf/Scene.hh
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,9 @@ namespace sdf
/// \brief Default constructor
public: Scene();

/// \brief Get the schema file name accessor
public: static const std::string& SchemaFile();

/// \brief Load the scene based on a element pointer. This is *not* the
/// usual entry point. Typical usage of the SDF DOM is through the Root
/// object.
Expand Down
3 changes: 3 additions & 0 deletions include/sdf/Sensor.hh
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,9 @@ namespace sdf
/// \brief Default constructor
public: Sensor();

/// \brief Get the schema file name accessor
public: static const std::string& SchemaFile();

/// \brief Load the sensor based on a element pointer. This is *not* the
/// usual entry point. Typical usage of the SDF DOM is through the Root
/// object.
Expand Down
3 changes: 3 additions & 0 deletions include/sdf/Surface.hh
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,9 @@ namespace sdf
/// \brief Default constructor
public: Surface();

/// \brief Get the schema file name accessor
public: static const std::string& SchemaFile();

/// \brief Load the surface based on a element pointer. This is *not* the
/// usual entry point. Typical usage of the SDF DOM is through the Root
/// object.
Expand Down
3 changes: 3 additions & 0 deletions include/sdf/Visual.hh
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,9 @@ namespace sdf
/// \brief Default constructor
public: Visual();

/// \brief Get the schema file name accessor
public: static const std::string& SchemaFile();

/// \brief Load the visual based on a element pointer. This is *not* the
/// usual entry point. Typical usage of the SDF DOM is through the Root
/// object.
Expand Down
3 changes: 3 additions & 0 deletions include/sdf/World.hh
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,9 @@ namespace sdf
/// \brief Default constructor
public: World();

/// \brief Get the schema file name accessor
public: static const std::string& SchemaFile();

/// \brief Load the world based on a element pointer. This is *not* the
/// usual entry point. Typical usage of the SDF DOM is through the Root
/// object.
Expand Down
File renamed without changes.
File renamed without changes.
7 changes: 7 additions & 0 deletions src/Actor.cc
Original file line number Diff line number Diff line change
Expand Up @@ -819,3 +819,10 @@ void Actor::AddPlugin(const Plugin &_plugin)
{
this->dataPtr->plugins.push_back(_plugin);
}

/////////////////////////////////////////////////
const std::string& Actor::SchemaFile()
{
static const std::string* kSchemaFile = new std::string("actor.sdf");
return *kSchemaFile;
}
Loading

0 comments on commit 55260ad

Please sign in to comment.