Skip to content

Commit

Permalink
project: allow passing rvalue references to parse(...) functions
Browse files Browse the repository at this point in the history
  • Loading branch information
lmichaelis committed Aug 27, 2022
1 parent bdc2479 commit 7e7affb
Show file tree
Hide file tree
Showing 15 changed files with 139 additions and 13 deletions.
11 changes: 10 additions & 1 deletion include/phoenix/animation.hh
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,16 @@ namespace phoenix {
* @param in The reader to read from.
* @return The animation pared.
*/
static animation parse(buffer& in);
[[nodiscard]] static animation parse(buffer& in);

/**
* @brief Parses the animation from the given reader.
* @param in The reader to read from.
* @return The animation pared.
*/
[[nodiscard]] inline static animation parse(buffer&& in) {
return parse(in);
}

/**
* @return The name of the animation
Expand Down
12 changes: 11 additions & 1 deletion include/phoenix/font.hh
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,17 @@ namespace phoenix {
* @return The font parsed.
* @throws parser_error if parsing fails.
*/
static font parse(buffer& in);
[[nodiscard]] static font parse(buffer& in);

/**
* @brief Parses in a font from the given reader.
* @param in The reader to read from
* @return The font parsed.
* @throws parser_error if parsing fails.
*/
[[nodiscard]] inline static font parse(buffer&& in) {
return parse(in);
}

/**
* @return The name of the font
Expand Down
12 changes: 11 additions & 1 deletion include/phoenix/material.hh
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,17 @@ namespace phoenix {
* @return The material.
* @throws parser_error if parsing fails.
*/
static material parse(archive_reader_ref& in);
[[nodiscard]] static material parse(archive_reader_ref& in);

/**
* @brief Reads a material from the archive.
* @param[in] in The reader to read from.
* @return The material.
* @throws parser_error if parsing fails.
*/
[[nodiscard]] inline static material parse(archive_reader_ref&& in) {
return parse(in);
}

public:
std::string name;
Expand Down
9 changes: 9 additions & 0 deletions include/phoenix/mesh.hh
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,15 @@ namespace phoenix {
*/
[[nodiscard]] static mesh parse(buffer& in, const std::vector<std::uint32_t>& leaf_polygons);

/**
* @brief Parses a mesh from the given reader.
* @param in The reader to read from.
* @return The mesh parsed.
*/
[[nodiscard]] inline static mesh parse(buffer&& in, const std::vector<std::uint32_t>& leaf_polygons) {
return parse(in, leaf_polygons);
}

/**
* @return The creation date of the mesh.
*/
Expand Down
11 changes: 10 additions & 1 deletion include/phoenix/messages.hh
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,16 @@ namespace phoenix {
* @param path The path of the file to read from
* @return A proxy to the message database.
*/
static messages parse(buffer& path);
[[nodiscard]] static messages parse(buffer& path);

/**
* @brief Parses a message database from a file.
* @param path The path of the file to read from
* @return A proxy to the message database.
*/
[[nodiscard]] inline static messages parse(buffer&& path) {
return parse(path);
}

/**
* @return All message blocks in the database.
Expand Down
13 changes: 11 additions & 2 deletions include/phoenix/model.hh
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,19 @@ namespace phoenix {
public:
/**
* @brief Parses a model from a file.
* @param path The path of the file to read from
* @param in The buffer to read from.
* @return The model just read.
*/
static model parse(buffer& path);
[[nodiscard]] static model parse(buffer& in);

/**
* @brief Parses a model from a file.
* @param in The buffer to read from.
* @return The model just read.
*/
[[nodiscard]] inline static model parse(buffer&& in) {
return parse(in);
}

[[nodiscard]] const model_hierachy& hierachy() const noexcept {
return _m_hierarchy;
Expand Down
6 changes: 5 additions & 1 deletion include/phoenix/model_hierarchy.hh
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,11 @@ namespace phoenix {

class model_hierachy {
public:
static model_hierachy parse(buffer& in);
[[nodiscard]] static model_hierachy parse(buffer& in);

[[nodiscard]] inline static model_hierachy parse(buffer&& in) {
return parse(in);
}

[[nodiscard]] const std::vector<model_hierarchy_node>& nodes() const noexcept {
return _m_nodes;
Expand Down
6 changes: 5 additions & 1 deletion include/phoenix/model_mesh.hh
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,11 @@ namespace phoenix {

class model_mesh {
public:
static model_mesh parse(buffer& in);
[[nodiscard]] static model_mesh parse(buffer& in);

[[nodiscard]] inline static model_mesh parse(buffer&& in) {
return parse(in);
}

const std::vector<softskin_mesh>& meshes() const noexcept {
return _m_meshes;
Expand Down
11 changes: 10 additions & 1 deletion include/phoenix/model_script.hh
Original file line number Diff line number Diff line change
Expand Up @@ -244,7 +244,16 @@ namespace phoenix {
* @param buf A buffer to parse from.
* @return The parsed model script.
*/
static model_script parse(buffer& buf);
[[nodiscard]] static model_script parse(buffer& buf);

/**
* @brief Parses a model script (MDS) file from the given buffer.
* @param buf A buffer to parse from.
* @return The parsed model script.
*/
[[nodiscard]] inline static model_script parse(buffer&& buf) {
return parse(buf);
}

/**
* @brief Parses a binary model script (MSB) file from the given buffer.
Expand Down
11 changes: 10 additions & 1 deletion include/phoenix/morph_mesh.hh
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,16 @@ namespace phoenix {
* @param in The reader to read from.
* @return The mesh parsed.
*/
static morph_mesh parse(buffer& in);
[[nodiscard]] static morph_mesh parse(buffer& in);

/**
* @brief Parses a morph mesh from the given reader.
* @param in The reader to read from.
* @return The mesh parsed.
*/
[[nodiscard]] inline static morph_mesh parse(buffer&& in) {
return parse(in);
}

/**
* @return All animations associated with the mesh
Expand Down
11 changes: 10 additions & 1 deletion include/phoenix/proto_mesh.hh
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,16 @@ namespace phoenix {
* @param in The reader to read from.
* @return The mesh read.
*/
static proto_mesh parse(buffer& in);
[[nodiscard]] static proto_mesh parse(buffer& in);

/**
* @brief Read a mesh from the given reader.
* @param in The reader to read from.
* @return The mesh read.
*/
[[nodiscard]] static proto_mesh parse(buffer&& in) {
return parse(in);
}

/**
* @brief Reads a proto mesh directly from a section.
Expand Down
6 changes: 5 additions & 1 deletion include/phoenix/softskin_mesh.hh
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,11 @@ namespace phoenix {
*/
class softskin_mesh {
public:
static softskin_mesh parse(buffer& in);
[[nodiscard]] static softskin_mesh parse(buffer& in);

[[nodiscard]] inline static softskin_mesh parse(buffer&& in) {
return parse(in);
}

/**
* @return The embedded proto-mesh.
Expand Down
14 changes: 13 additions & 1 deletion include/phoenix/texture.hh
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,19 @@ namespace phoenix {
* @param in The reader to read from
* @return The texture.
*/
static texture parse(buffer& in);
[[nodiscard]] static texture parse(buffer& in);

/**
* @brief Parses a texture from the given reader.
*
* If the texture is compressed using DXT1, DXT3 or DXT5 it is automatically decompressed.
*
* @param in The reader to read from
* @return The texture.
*/
[[nodiscard]] inline static texture parse(buffer&& in) {
return parse(in);
}

/**
* @brief Parses a texture from the given file.
Expand Down
10 changes: 10 additions & 0 deletions include/phoenix/world.hh
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,16 @@ namespace phoenix {
*/
[[nodiscard]] static world parse(buffer& in, game_version version);

/**
* @brief Parses a world from the given reader.
* @param in The reader to read from.
* @return The world parsed.
* @throws parser_error if parsing fails.
*/
[[nodiscard]] inline static world parse(buffer&& in, game_version version) {
return parse(in, version);
}

std::vector<std::unique_ptr<vobs::vob>> world_vobs;
mesh world_mesh;
bsp_tree world_bsp_tree;
Expand Down
9 changes: 9 additions & 0 deletions include/phoenix/world/bsp_tree.hh
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,15 @@ namespace phoenix {
*/
[[nodiscard]] static bsp_tree parse(buffer& in, std::uint32_t version);

/**
* @brief Parses a BSP tree from the given reader.
* @param in The reader to read from.
* @return The tree parsed.
*/
[[nodiscard]] inline static bsp_tree parse(buffer&& in, std::uint32_t version) {
return parse(in, version);
}

/**
* @return The mode of the tree (either indoor or outdoor).
*/
Expand Down

0 comments on commit 7e7affb

Please sign in to comment.