Skip to content

Commit

Permalink
Style fixes
Browse files Browse the repository at this point in the history
Signed-off-by: Aditya Agrawal <[email protected]>
  • Loading branch information
[email protected] authored and aagrawal05 committed Aug 16, 2024
1 parent 2a66550 commit e8e45a8
Show file tree
Hide file tree
Showing 75 changed files with 565 additions and 196 deletions.
74 changes: 35 additions & 39 deletions format_schema.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,23 +6,19 @@
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 inline std::string_view SchemaFile();
"""
addHeader = """\n /// \\brief Get the schema file name accessor
public: static inline std::string_view SchemaFile();\n"""

addImpl = f"""
/////////////////////////////////////////////////
inline std::string_view {camel_case}::SchemaFile()
inline std::string_view {camel_case}::SchemaFile()
{{
static const char kSchemaFile[] = "{line}";
return kSchemaFile;
}}\n\n"""

# Debug print statements
# print(addHeader)
# print(addImpl)
Expand All @@ -31,31 +27,31 @@

print(line)

# # Edit './include/sdf/{camel_case}.hh'
# # Find the line with 'class SDFFORMAT_VISIBLE {camel_case}`
# try:
# f = open('./include/sdf/' + camel_case + '.hh', 'r')
# read_lines = f.readlines()
# f.close()
# line_number = 0
# for i, line_raw in enumerate(read_lines):
# if line_raw == " 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_raw in enumerate(read_lines):
# file.write(line_raw)
# 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 './include/sdf/{camel_case}.hh'
# Find the line with 'class SDFFORMAT_VISIBLE {camel_case}`
try:
f = open('./include/sdf/' + camel_case + '.hh', 'r')
read_lines = f.readlines()
f.close()
line_number = 0
for i, line_raw in enumerate(read_lines):
if line_raw == " 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_raw in enumerate(read_lines):
file.write(line_raw)
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.")

# Replace all instances of `line` with `std::string(this->SchemaFile())`
if (os.path.exists('./src/' + camel_case + '.cc')):
try:
Expand All @@ -72,12 +68,12 @@
except:
print("Unexpected error while reading from: " + camel_case + ".cc.")

# # 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")
# 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")
2 changes: 1 addition & 1 deletion include/sdf/Actor.hh
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,7 @@ namespace sdf

/// \brief Get the schema file name accessor
public: static inline std::string_view 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
2 changes: 1 addition & 1 deletion include/sdf/AirPressure.hh
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ namespace sdf

/// \brief Get the schema file name accessor
public: static inline std::string_view 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
2 changes: 1 addition & 1 deletion include/sdf/AirSpeed.hh
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ namespace sdf

/// \brief Get the schema file name accessor
public: static inline std::string_view 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
2 changes: 1 addition & 1 deletion include/sdf/Altimeter.hh
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ namespace sdf

/// \brief Get the schema file name accessor
public: static inline std::string_view 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
2 changes: 1 addition & 1 deletion include/sdf/Atmosphere.hh
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ namespace sdf

/// \brief Get the schema file name accessor
public: static inline std::string_view 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
2 changes: 1 addition & 1 deletion include/sdf/Camera.hh
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ namespace sdf

/// \brief Get the schema file name accessor
public: static inline std::string_view 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
2 changes: 1 addition & 1 deletion include/sdf/Collision.hh
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ namespace sdf

/// \brief Get the schema file name accessor
public: static inline std::string_view 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/Error.hh
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,9 @@ namespace sdf
/// \brief The joint axis mimic does not refer to a valid joint in the
/// current scope.
JOINT_AXIS_MIMIC_INVALID,

/// \brief Error at the XML level.
XML_ERROR,
};

class SDFORMAT_VISIBLE Error
Expand Down
3 changes: 2 additions & 1 deletion include/sdf/ForceTorque.hh
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,8 @@ namespace sdf
/// \brief Default constructor
public: ForceTorque();

public: static inline std::string_view SchemaFile();
/// \brief Get the schema file name accessor
public: static inline std::string_view 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
Expand Down
2 changes: 1 addition & 1 deletion include/sdf/Frame.hh
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ namespace sdf

/// \brief Get the schema file name accessor
public: static inline std::string_view 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
2 changes: 1 addition & 1 deletion include/sdf/Geometry.hh
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ namespace sdf

/// \brief Get the schema file name accessor
public: static inline std::string_view 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
2 changes: 1 addition & 1 deletion include/sdf/Gui.hh
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ namespace sdf

/// \brief Get the schema file name accessor
public: static inline std::string_view 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
2 changes: 1 addition & 1 deletion include/sdf/Imu.hh
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ namespace sdf

/// \brief Get the schema file name accessor
public: static inline std::string_view 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
2 changes: 1 addition & 1 deletion include/sdf/Joint.hh
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ namespace sdf

/// \brief Get the schema file name accessor
public: static inline std::string_view 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
2 changes: 1 addition & 1 deletion include/sdf/Lidar.hh
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ namespace sdf

/// \brief Get the schema file name accessor
public: static inline std::string_view 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
2 changes: 1 addition & 1 deletion include/sdf/Light.hh
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ namespace sdf

/// \brief Get the schema file name accessor
public: static inline std::string_view 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
2 changes: 1 addition & 1 deletion include/sdf/Link.hh
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ namespace sdf

/// \brief Get the schema file name accessor
public: static inline std::string_view 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
2 changes: 1 addition & 1 deletion include/sdf/Magnetometer.hh
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ namespace sdf

/// \brief Get the schema file name accessor
public: static inline std::string_view 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
2 changes: 1 addition & 1 deletion include/sdf/Material.hh
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ namespace sdf

/// \brief Get the schema file name accessor
public: static inline std::string_view 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
2 changes: 1 addition & 1 deletion include/sdf/Model.hh
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ namespace sdf

/// \brief Get the schema file name accessor
public: static inline std::string_view 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
7 changes: 4 additions & 3 deletions include/sdf/NavSat.hh
Original file line number Diff line number Diff line change
Expand Up @@ -76,15 +76,16 @@ namespace sdf
{
/// \brief Default constructor
public: NavSat();

/// \brief Get the schema file name accessor
public: static inline std::string_view 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
/// \return Errors, which is a vector of Error objects. Each Error includes
/// an error code and message. An empty vector indicates no error.

public: static inline std::string_view SchemaFile();

public: Errors Load(ElementPtr _sdf);

/// \brief Get a pointer to the SDF element that was used during
Expand Down
2 changes: 1 addition & 1 deletion include/sdf/Noise.hh
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ namespace sdf

/// \brief Get the schema file name accessor
public: static inline std::string_view 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
2 changes: 1 addition & 1 deletion include/sdf/ParticleEmitter.hh
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ namespace sdf

/// \brief Get the schema file name accessor
public: static inline std::string_view 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
2 changes: 1 addition & 1 deletion include/sdf/Physics.hh
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ namespace sdf

/// \brief Get the schema file name accessor
public: static inline std::string_view 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
2 changes: 1 addition & 1 deletion include/sdf/Plugin.hh
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ namespace sdf

/// \brief Get the schema file name accessor
public: static inline std::string_view SchemaFile();

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

Expand Down
2 changes: 1 addition & 1 deletion include/sdf/Projector.hh
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ namespace sdf

/// \brief Get the schema file name accessor
public: static inline std::string_view 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
2 changes: 1 addition & 1 deletion include/sdf/Root.hh
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ namespace sdf

/// \brief Get the schema file name accessor
public: static inline std::string_view 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
Loading

0 comments on commit e8e45a8

Please sign in to comment.