From fda96ea9258be1b9ba239cc64b803688655827da Mon Sep 17 00:00:00 2001 From: Mathieu Westphal Date: Thu, 26 Dec 2024 07:22:10 +0100 Subject: [PATCH] libf3d: Improve API for [[nodiscard]] and missing this* return (#1830) - Adding [[nodiscard]] on all method where it makes sense - Updating test to use std::ignore when needed - Return this* whenever is was missing - Part of https://github.com/f3d-app/f3d/issues/1624 --- library/private/interactor_impl.h | 16 +++++------ library/public/camera.h | 10 +++---- library/public/context.h | 12 ++++----- library/public/engine.h | 40 ++++++++++++++-------------- library/public/image.h | 34 +++++++++++------------ library/public/interactor.h | 38 +++++++++++++------------- library/public/options.h.in | 23 ++++++++-------- library/public/scene.h | 4 +-- library/public/utils.h | 9 ++++--- library/public/window.h | 16 +++++------ library/src/engine.cxx | 3 ++- library/src/image.cxx | 7 ++--- library/src/interactor_impl.cxx | 24 +++++++++++------ library/src/options.cxx | 6 +++-- library/testing/TestSDKImage.cxx | 23 ++++++++-------- library/testing/TestSDKOptions.cxx | 20 +++++++------- library/testing/TestSDKOptionsIO.cxx | 3 ++- library/testing/TestSDKUtils.cxx | 4 +-- 18 files changed, 155 insertions(+), 137 deletions(-) diff --git a/library/private/interactor_impl.h b/library/private/interactor_impl.h index ec901eba1b..c9701ddb7c 100644 --- a/library/private/interactor_impl.h +++ b/library/private/interactor_impl.h @@ -56,21 +56,21 @@ class interactor_impl : public interactor std::pair getBindingDocumentation( const interaction_bind_t& bind) const override; - void toggleAnimation() override; - void startAnimation() override; - void stopAnimation() override; + interactor& toggleAnimation() override; + interactor& startAnimation() override; + interactor& stopAnimation() override; bool isPlayingAnimation() override; - void enableCameraMovement() override; - void disableCameraMovement() override; + interactor& enableCameraMovement() override; + interactor& disableCameraMovement() override; bool playInteraction( const std::string& file, double deltaTime, std::function userCallBack) override; bool recordInteraction(const std::string& file) override; - void start(double deltaTime, std::function userCallBack) override; - void stop() override; - void requestRender() override; + interactor& start(double deltaTime, std::function userCallBack) override; + interactor& stop() override; + interactor& requestRender() override; ///@} /** diff --git a/library/public/camera.h b/library/public/camera.h index bba321b1a1..670afec571 100644 --- a/library/public/camera.h +++ b/library/public/camera.h @@ -35,19 +35,19 @@ class F3D_EXPORT camera * Angles are in degrees. */ virtual camera& setPosition(const point3_t& pos) = 0; - virtual point3_t getPosition() = 0; + [[nodiscard]] virtual point3_t getPosition() = 0; virtual void getPosition(point3_t& pos) = 0; virtual camera& setFocalPoint(const point3_t& foc) = 0; - virtual point3_t getFocalPoint() = 0; + [[nodiscard]] virtual point3_t getFocalPoint() = 0; virtual void getFocalPoint(point3_t& foc) = 0; virtual camera& setViewUp(const vector3_t& up) = 0; - virtual vector3_t getViewUp() = 0; + [[nodiscard]] virtual vector3_t getViewUp() = 0; virtual void getViewUp(vector3_t& up) = 0; virtual camera& setViewAngle(const angle_deg_t& angle) = 0; - virtual angle_deg_t getViewAngle() = 0; + [[nodiscard]] virtual angle_deg_t getViewAngle() = 0; virtual void getViewAngle(angle_deg_t& angle) = 0; virtual camera& setState(const camera_state_t& state) = 0; - virtual camera_state_t getState() = 0; + [[nodiscard]] virtual camera_state_t getState() = 0; virtual void getState(camera_state_t& state) = 0; ///@} diff --git a/library/public/context.h b/library/public/context.h index b190740726..b4309edee3 100644 --- a/library/public/context.h +++ b/library/public/context.h @@ -29,34 +29,34 @@ class F3D_EXPORT context * Create a GLX context function. * Only supported on Linux. */ - static function glx(); + [[nodiscard]] static function glx(); /** * Create a WGL context function. * Only supported on Windows. */ - static function wgl(); + [[nodiscard]] static function wgl(); /** * Create a COCOA context function. * This is usually required when using a headless context and a GPU device. * Only supported on macOS. */ - static function cocoa(); + [[nodiscard]] static function cocoa(); /** * Create a EGL context function. * This is usually required when using a headless context and a GPU device. * Only supported on Linux and Windows. */ - static function egl(); + [[nodiscard]] static function egl(); /** * Create a OSMesa context function. * This is usually required when using a headless context and no GPU device. * Only supported on Linux and Windows. */ - static function osmesa(); + [[nodiscard]] static function osmesa(); /** * Create a context function from a library name and a function name. @@ -64,7 +64,7 @@ class F3D_EXPORT context * For example, `getSymbol("EGL", "eglGetProcAddress")` looks for the symbol * `eglGetProcAddress` in the library `libEGL.so` on Linux. */ - static function getSymbol(const std::string& lib, const std::string& func); + [[nodiscard]] static function getSymbol(const std::string& lib, const std::string& func); /** * An exception that can be thrown when the requested library cannot be loaded. diff --git a/library/public/engine.h b/library/public/engine.h index 230b3f18a3..7d0aac1bce 100644 --- a/library/public/engine.h +++ b/library/public/engine.h @@ -45,12 +45,12 @@ class F3D_EXPORT engine * Windows: Try Win32, then EGL, then OSMesa * macOS: Always use Cocoa */ - static engine create(bool offscreen = false); + [[nodiscard]] static engine create(bool offscreen = false); /** * Create an engine with no window. */ - static engine createNone(); + [[nodiscard]] static engine createNone(); /** * Create an engine with a GLX window. @@ -59,7 +59,7 @@ class F3D_EXPORT engine * Optionally, the window can be hidden by setting offscreen to true. * Throws engine::loading_exception in case of window creation failure. */ - static engine createGLX(bool offscreen = false); + [[nodiscard]] static engine createGLX(bool offscreen = false); /** * Create an engine with a WGL window. @@ -68,7 +68,7 @@ class F3D_EXPORT engine * Optionally, the window can be hidden by setting offscreen to true. * Throws engine::loading_exception in case of window creation failure. */ - static engine createWGL(bool offscreen = false); + [[nodiscard]] static engine createWGL(bool offscreen = false); /** * Create an engine with an offscreen EGL window. @@ -77,14 +77,14 @@ class F3D_EXPORT engine * `VTK_DEFAULT_EGL_DEVICE_INDEX` allows its selection. * Throws engine::loading_exception in case of failure. */ - static engine createEGL(); + [[nodiscard]] static engine createEGL(); /** * Create an engine with an offscreen OSMesa window. * VTK >= 9.4 required. * Throws engine::loading_exception in case of window creation failure. */ - static engine createOSMesa(); + [[nodiscard]] static engine createOSMesa(); /** * Create an engine with an external window. @@ -95,7 +95,7 @@ class F3D_EXPORT engine * f3d::engine eng = f3d::engine::createExternal(glfwGetProcAddress); * \endcode */ - static engine createExternal(const context::function& getProcAddress); + [[nodiscard]] static engine createExternal(const context::function& getProcAddress); /** * Create an engine with an external GLX context. @@ -103,7 +103,7 @@ class F3D_EXPORT engine * VTK >= 9.4 required. * Throws context::loading_exception if GLX library is not found or if not running on Linux. */ - static engine createExternalGLX(); + [[nodiscard]] static engine createExternalGLX(); /** * Create an engine with an external WGL context. @@ -111,7 +111,7 @@ class F3D_EXPORT engine * VTK >= 9.4 required. * Throws context::loading_exception if WGL library is not found or if not running on Windows. */ - static engine createExternalWGL(); + [[nodiscard]] static engine createExternalWGL(); /** * Create an engine with an external COCOA context. @@ -119,7 +119,7 @@ class F3D_EXPORT engine * VTK >= 9.4 required. * Throws context::loading_exception if WGL library is not found or if not running on Windows. */ - static engine createExternalCOCOA(); + [[nodiscard]] static engine createExternalCOCOA(); /** * Create an engine with an external EGL context. @@ -127,7 +127,7 @@ class F3D_EXPORT engine * VTK >= 9.4 required. * Throws context::loading_exception if EGL library is not found. */ - static engine createExternalEGL(); + [[nodiscard]] static engine createExternalEGL(); /** * Create an engine with an external OSMesa context. @@ -135,7 +135,7 @@ class F3D_EXPORT engine * VTK >= 9.4 required. * Throws context::loading_exception if OSMesa library is not found. */ - static engine createExternalOSMesa(); + [[nodiscard]] static engine createExternalOSMesa(); /** * Engine destructor, delete all object instances as well. @@ -160,7 +160,7 @@ class F3D_EXPORT engine * - Linux: ~/.cache/f3d * - macOS: ~/Library/Caches/f3d */ - void setCachePath(const std::string& cachePath); + engine& setCachePath(const std::string& cachePath); /** * Engine provide a default options that you can use using engine::getOptions(). @@ -179,24 +179,24 @@ class F3D_EXPORT engine /** * Get the default options provided by the engine. */ - options& getOptions(); + [[nodiscard]] options& getOptions(); /** * Get the window provided by the engine, if any. * If not, will throw a engine::no_window_exception. */ - window& getWindow(); + [[nodiscard]] window& getWindow(); /** * Get the loaded provided by the engine. */ - scene& getScene(); + [[nodiscard]] scene& getScene(); /** * Get the interactor provided by the engine, if any. * If not, will throw a engine::no_interactor_exception. */ - interactor& getInteractor(); + [[nodiscard]] interactor& getInteractor(); /** * Load a plugin. @@ -225,7 +225,7 @@ class F3D_EXPORT engine * Listed plugins can be loaded using engine::loadPlugin function. * Note that the listed plugins may fail to load if the library is not found or incompatible. */ - static std::vector getPluginsList(const std::string& pluginPath); + [[nodiscard]] static std::vector getPluginsList(const std::string& pluginPath); /** * A structure providing information about the libf3d. @@ -247,7 +247,7 @@ class F3D_EXPORT engine /** * Get a struct containing info about the libf3d. */ - static libInformation getLibInfo(); + [[nodiscard]] static libInformation getLibInfo(); /** * A structure providing information about a reader. @@ -267,7 +267,7 @@ class F3D_EXPORT engine /** * Get a vector of struct containing info about the supported readers. */ - static std::vector getReadersInfo(); + [[nodiscard]] static std::vector getReadersInfo(); /** * An exception that can be thrown by the engine diff --git a/library/public/image.h b/library/public/image.h index faa2930873..679f2d7d76 100644 --- a/library/public/image.h +++ b/library/public/image.h @@ -76,8 +76,8 @@ class F3D_EXPORT image /** * Comparison operators, uses image::compare with a threshold of 1e-14. */ - bool operator==(const image& reference) const; - bool operator!=(const image& reference) const; + [[nodiscard]] bool operator==(const image& reference) const; + [[nodiscard]] bool operator!=(const image& reference) const; ///@} /** @@ -86,12 +86,12 @@ class F3D_EXPORT image * \warning Because of the normalization, this function can be slow, prefer getContent when * reading several pixels and normalization is not needed. */ - std::vector getNormalizedPixel(const std::pair& xy) const; + [[nodiscard]] std::vector getNormalizedPixel(const std::pair& xy) const; /** * Get the list of supported image format extensions when opening a file. */ - static std::vector getSupportedFormats(); + [[nodiscard]] static std::vector getSupportedFormats(); ///@{ @name Resolution /** @@ -99,8 +99,8 @@ class F3D_EXPORT image * * \deprecated { setResolution is deprecated, use the appropriate constructor } */ - unsigned int getWidth() const; - unsigned int getHeight() const; + [[nodiscard]] unsigned int getWidth() const; + [[nodiscard]] unsigned int getHeight() const; ///@} ///@{ @name Channel Count @@ -109,19 +109,19 @@ class F3D_EXPORT image * * \deprecated { setChannelCount is deprecated, use the appropriate constructor } */ - unsigned int getChannelCount() const; + [[nodiscard]] unsigned int getChannelCount() const; ///@} /** * Get image channel type. * throw an `image::read_exception` if the type is unknown. */ - ChannelType getChannelType() const; + [[nodiscard]] ChannelType getChannelType() const; /** * Get image channel type size in bytes. */ - unsigned int getChannelTypeSize() const; + [[nodiscard]] unsigned int getChannelTypeSize() const; ///@{ @name Buffer Data /** @@ -131,7 +131,7 @@ class F3D_EXPORT image * \deprecated { setData and getData are deprecated, use setContent and getContent instead } */ image& setContent(void* buffer); - void* getContent() const; + [[nodiscard]] void* getContent() const; ///@} /** @@ -163,10 +163,10 @@ class F3D_EXPORT image * Throw an `image::write_exception` if the format is incompatible with with image channel type or * channel count */ - void save(const std::string& path, SaveFormat format = SaveFormat::PNG) const; + const image& save(const std::string& path, SaveFormat format = SaveFormat::PNG) const; /** - * Save an image to a memory buffer in the specified format. + * Save an image to a memory buffer in the specified format and returns it. * Default format is PNG if not specified. * PNG: Supports channel type BYTE and SHORT with channel count of 1 to 4 * JPG: Supports channel type BYTE with channel count of 1 or 3 @@ -175,7 +175,7 @@ class F3D_EXPORT image * Throw an `image::write_exception` if the type is TIF or * if the format is incompatible with with image channel type or channel count. */ - std::vector saveBuffer(SaveFormat format = SaveFormat::PNG) const; + [[nodiscard]] std::vector saveBuffer(SaveFormat format = SaveFormat::PNG) const; /** * Convert to colored text using ANSI escape sequences for printing in a terminal. @@ -188,14 +188,14 @@ class F3D_EXPORT image * - 24-bit escape codes (`ESC[38;2;{r};{g};{b}m`, `ESC[48;2;{r};{g};{b}m`) * Throw a `image::write_exception` if the type is not byte RGB or RGBA. */ - const f3d::image& toTerminalText(std::ostream& stream) const; + const image& toTerminalText(std::ostream& stream) const; /** * Convert to colored text using ANSI escape sequences for printing in a terminal. * See `toTerminalText(std::ostream& stream)`. * Throw a `image::write_exception` if the type is not byte RGB or RGBA. */ - std::string toTerminalText() const; + [[nodiscard]] std::string toTerminalText() const; /** * Set the value for a metadata key. Setting an empty value (`""`) removes the key. @@ -206,12 +206,12 @@ class F3D_EXPORT image * Get the value for a metadata key. * Throw a `image::read_exception` if key does not exist. */ - std::string getMetadata(const std::string& key) const; + [[nodiscard]] std::string getMetadata(const std::string& key) const; /** * List all the metadata keys which have a value set. */ - std::vector allMetadata() const; + [[nodiscard]] std::vector allMetadata() const; /** * An exception that can be thrown by the image when there. diff --git a/library/public/interactor.h b/library/public/interactor.h index d62d5e8ea2..7e20dbf336 100644 --- a/library/public/interactor.h +++ b/library/public/interactor.h @@ -35,24 +35,24 @@ struct interaction_bind_t * Operator to be able to store binds in maps and other structs * Compare modifier and interaction */ - bool operator<(const interaction_bind_t& bind) const; + [[nodiscard]] bool operator<(const interaction_bind_t& bind) const; /** * Operator to be able to store binds in maps and other structs * Compare modifier and interaction */ - bool operator==(const interaction_bind_t& bind) const; + [[nodiscard]] bool operator==(const interaction_bind_t& bind) const; /** * Format this binding into a string * eg: "A", "Any+Question", "Shift+L". */ - std::string format() const; + [[nodiscard]] std::string format() const; /** * Create and return an interaction bind from provided string */ - static interaction_bind_t parse(const std::string& str); + [[nodiscard]] static interaction_bind_t parse(const std::string& str); }; /** @@ -90,7 +90,7 @@ class F3D_EXPORT interactor /** * Return a string vector containing all currently defined actions of commands */ - virtual std::vector getCommandActions() const = 0; + [[nodiscard]] virtual std::vector getCommandActions() const = 0; /** * Trigger provided command, see COMMANDS.md for details about supported @@ -172,19 +172,20 @@ class F3D_EXPORT interactor /** * Return a vector of available bind groups, in order of addition */ - virtual std::vector getBindGroups() const = 0; + [[nodiscard]] virtual std::vector getBindGroups() const = 0; /** * Return a vector of bind for the specified group, in order of addition * * Getting binds for a group that does not exists will throw a does_not_exists_exception. */ - virtual std::vector getBindsForGroup(std::string group) const = 0; + [[nodiscard]] virtual std::vector getBindsForGroup( + std::string group) const = 0; /** * Return a vector of all binds, in order of addition */ - virtual std::vector getBinds() const = 0; + [[nodiscard]] virtual std::vector getBinds() const = 0; /** * Get a pair of string documenting a binding. @@ -198,7 +199,7 @@ class F3D_EXPORT interactor * * Getting documentation for a bind that does not exists will throw a does_not_exists_exception. */ - virtual std::pair getBindingDocumentation( + [[nodiscard]] virtual std::pair getBindingDocumentation( const interaction_bind_t& bind) const = 0; ///@} @@ -206,18 +207,18 @@ class F3D_EXPORT interactor /** * Control the animation. */ - virtual void toggleAnimation() = 0; - virtual void startAnimation() = 0; - virtual void stopAnimation() = 0; - virtual bool isPlayingAnimation() = 0; + virtual interactor& toggleAnimation() = 0; + virtual interactor& startAnimation() = 0; + virtual interactor& stopAnimation() = 0; + [[nodiscard]] virtual bool isPlayingAnimation() = 0; ///@} ///@{ @name Movement /** * Control if camera movements are enabled, which they are by default. */ - virtual void enableCameraMovement() = 0; - virtual void disableCameraMovement() = 0; + virtual interactor& enableCameraMovement() = 0; + virtual interactor& disableCameraMovement() = 0; ///@} /** @@ -236,18 +237,19 @@ class F3D_EXPORT interactor * The event loop will be triggered every deltaTime in seconds, and userCallBack will be called at * the start of the event loop */ - virtual void start(double deltaTime = 1.0 / 30, std::function userCallBack = nullptr) = 0; + virtual interactor& start( + double deltaTime = 1.0 / 30, std::function userCallBack = nullptr) = 0; /** * Stop the interactor. */ - virtual void stop() = 0; + virtual interactor& stop() = 0; /** * Request a render to be done on the next event loop * Safe to call in a multithreaded environment */ - virtual void requestRender() = 0; + virtual interactor& requestRender() = 0; /** * An exception that can be thrown by the interactor diff --git a/library/public/options.h.in b/library/public/options.h.in index 01dd6c5a4f..d59d3a6fad 100644 --- a/library/public/options.h.in +++ b/library/public/options.h.in @@ -53,7 +53,7 @@ public: * Throw an options::inexistent_exception if option does not exist. * Throw an options::no_value_exception if option has not been set. */ - option_variant_t get(const std::string& name) const; + [[nodiscard]] option_variant_t get(const std::string& name) const; /** * Set an option as a string based on its name @@ -69,7 +69,7 @@ public: * Throw an options::inexistent_exception if option does not exist. * Throw an options::no_value_exception if option has not been set. */ - std::string getAsString(const std::string& name) const; + [[nodiscard]] std::string getAsString(const std::string& name) const; /** * A boolean option specific method to toggle it. @@ -84,14 +84,14 @@ public: * Return true if they are the same value, false otherwise. * Throw an options::inexistent_exception if option does not exist. */ - bool isSame(const options& other, const std::string& name) const; + [[nodiscard]] bool isSame(const options& other, const std::string& name) const; /** * Return true if an option has a value, false otherwise * Always returns true for non-optional options. * Throw an options::inexistent_exception if option does not exist. */ - bool hasValue(const std::string& name) const; + [[nodiscard]] bool hasValue(const std::string& name) const; /** * Copy the value of an option from this to the provided other. @@ -102,35 +102,36 @@ public: /** * Get all available option names. */ - static std::vector getAllNames(); + [[nodiscard]] static std::vector getAllNames(); /** * Get all option names that currently have values. */ - std::vector getNames() const; + [[nodiscard]] std::vector getNames() const; /** * Get the closest option name and its Levenshtein distance. */ - std::pair getClosestOption(const std::string& option) const; + [[nodiscard]] std::pair getClosestOption( + const std::string& option) const; /** * Returns true if the option is optional else returns false. * Throws an options::inexistent_exception if option does not exist. */ - bool isOptional(const std::string& option) const; + [[nodiscard]] bool isOptional(const std::string& option) const; /** * Resets the option to default value. * Throws an options::inexistent_exception if option does not exist. */ - void reset(const std::string& name); + options& reset(const std::string& name); /** * Unset the option if it is optional else throws options::incompatible_exception. * Throws an options::inexistent_exception if option does not exist. */ - void removeValue(const std::string& name); + options& removeValue(const std::string& name); /** * Templated parsing method used internally to parse strings. @@ -149,7 +150,7 @@ public: * Throw an options::parsing_exception if parsing failed. */ template - static T parse(const std::string& str); + [[nodiscard]] static T parse(const std::string& str); /** * An exception that can be thrown by the options diff --git a/library/public/scene.h b/library/public/scene.h index 52a7f7572c..960975f6c6 100644 --- a/library/public/scene.h +++ b/library/public/scene.h @@ -80,7 +80,7 @@ class F3D_EXPORT scene /** * Return true if provided file path is supported, false otherwise. */ - virtual bool supports(const std::filesystem::path& filePath) = 0; + [[nodiscard]] virtual bool supports(const std::filesystem::path& filePath) = 0; /** * Load added files at provided time value if they contain any animation @@ -94,7 +94,7 @@ class F3D_EXPORT scene * Get animation time range of currently added files. * Returns [0, 0] if there is no animations. */ - virtual std::pair animationTimeRange() = 0; + [[nodiscard]] virtual std::pair animationTimeRange() = 0; protected: //! @cond diff --git a/library/public/utils.h b/library/public/utils.h index 45609af8b9..925e03283d 100644 --- a/library/public/utils.h +++ b/library/public/utils.h @@ -26,7 +26,7 @@ class F3D_EXPORT utils * Compute the Levenshtein distance between two strings. * Can be useful for spell checking and typo detection. */ - static unsigned int textDistance(const std::string& strA, const std::string& strB); + [[nodiscard]] static unsigned int textDistance(const std::string& strA, const std::string& strB); // clang-format off /** @@ -52,7 +52,7 @@ class F3D_EXPORT utils * `set scene.up.direction "+Z` -> tokenize_exception * `set scene.up.direction +Z\` -> tokenize_exception */ - static std::vector tokenize(std::string_view str); + [[nodiscard]] static std::vector tokenize(std::string_view str); // clang-format on /** @@ -89,10 +89,11 @@ class F3D_EXPORT utils */ string_template& substitute(const std::map& lookup); - std::string str() const; + /** Return a string representation of the string template */ + [[nodiscard]] std::string str() const; /** List the remaining un-substituted variables. */ - std::vector variables() const; + [[nodiscard]] std::vector variables() const; /** * Exception to be thrown by substitution functions to let untouched variables through. diff --git a/library/public/window.h b/library/public/window.h index 37d2cf75e2..33d7aa9c6a 100644 --- a/library/public/window.h +++ b/library/public/window.h @@ -49,17 +49,17 @@ class F3D_EXPORT window /** * Get the type of the window. */ - virtual Type getType() = 0; + [[nodiscard]] virtual Type getType() = 0; /** * Is the window offscreen. */ - virtual bool isOffscreen() = 0; + [[nodiscard]] virtual bool isOffscreen() = 0; /** * Get the camera provided by the window. */ - virtual camera& getCamera() = 0; + [[nodiscard]] virtual camera& getCamera() = 0; /** * Perform a render of the window to the screen. @@ -74,7 +74,7 @@ class F3D_EXPORT window * Set noBackground to true to have a transparent background. * Return the resulting f3d::image. */ - virtual image renderToImage(bool noBackground = false) = 0; + [[nodiscard]] virtual image renderToImage(bool noBackground = false) = 0; /** * Set the size of the window. @@ -84,12 +84,12 @@ class F3D_EXPORT window /** * Get the width of the window. */ - virtual int getWidth() const = 0; + [[nodiscard]] virtual int getWidth() const = 0; /** * Get the height of the window. */ - virtual int getHeight() const = 0; + [[nodiscard]] virtual int getHeight() const = 0; /** * Set the position of the window. @@ -111,12 +111,12 @@ class F3D_EXPORT window /** * Convert a point in display coordinate to world coordinate. */ - virtual point3_t getWorldFromDisplay(const point3_t& displayPoint) const = 0; + [[nodiscard]] virtual point3_t getWorldFromDisplay(const point3_t& displayPoint) const = 0; /** * Convert a point in world coordinate to display coordinate. */ - virtual point3_t getDisplayFromWorld(const point3_t& worldPoint) const = 0; + [[nodiscard]] virtual point3_t getDisplayFromWorld(const point3_t& worldPoint) const = 0; protected: //! @cond diff --git a/library/src/engine.cxx b/library/src/engine.cxx index 1a7a95b17e..ec01290948 100644 --- a/library/src/engine.cxx +++ b/library/src/engine.cxx @@ -442,9 +442,10 @@ std::vector engine::getReadersInfo() } //---------------------------------------------------------------------------- -void engine::setCachePath(const std::string& cachePath) +engine& engine::setCachePath(const std::string& cachePath) { this->Internals->Window->SetCachePath(cachePath); + return *this; } //---------------------------------------------------------------------------- diff --git a/library/src/image.cxx b/library/src/image.cxx index a6ae3f457f..921583b0fd 100644 --- a/library/src/image.cxx +++ b/library/src/image.cxx @@ -467,7 +467,7 @@ std::vector image::getNormalizedPixel(const std::pair& xy) con } //---------------------------------------------------------------------------- -void image::save(const std::string& path, SaveFormat format) const +const image& image::save(const std::string& path, SaveFormat format) const { internals::checkSaveFormatCompatibility(*this, format); @@ -500,6 +500,7 @@ void image::save(const std::string& path, SaveFormat format) const { throw write_exception("Cannot write " + path); } + return *this; } //---------------------------------------------------------------------------- @@ -526,7 +527,7 @@ std::vector image::saveBuffer(SaveFormat format) const } //---------------------------------------------------------------------------- -const f3d::image& image::toTerminalText(std::ostream& stream) const +const image& image::toTerminalText(std::ostream& stream) const { const int depth = this->getChannelCount(); if (this->getChannelType() != ChannelType::BYTE || depth < 3 || depth > 4) @@ -667,7 +668,7 @@ std::string image::toTerminalText() const } //---------------------------------------------------------------------------- -f3d::image& image::setMetadata(const std::string& key, const std::string& value) +image& image::setMetadata(const std::string& key, const std::string& value) { if (value.empty()) { diff --git a/library/src/interactor_impl.cxx b/library/src/interactor_impl.cxx index 99a13f83ca..7da030b183 100644 --- a/library/src/interactor_impl.cxx +++ b/library/src/interactor_impl.cxx @@ -1053,24 +1053,27 @@ std::pair interactor_impl::getBindingDocumentation( } //---------------------------------------------------------------------------- -void interactor_impl::toggleAnimation() +interactor& interactor_impl::toggleAnimation() { assert(this->Internals->AnimationManager); this->Internals->AnimationManager->ToggleAnimation(); + return *this; } //---------------------------------------------------------------------------- -void interactor_impl::startAnimation() +interactor& interactor_impl::startAnimation() { assert(this->Internals->AnimationManager); this->Internals->AnimationManager->StartAnimation(); + return *this; } //---------------------------------------------------------------------------- -void interactor_impl::stopAnimation() +interactor& interactor_impl::stopAnimation() { assert(this->Internals->AnimationManager); this->Internals->AnimationManager->StopAnimation(); + return *this; } //---------------------------------------------------------------------------- @@ -1081,15 +1084,17 @@ bool interactor_impl::isPlayingAnimation() } //---------------------------------------------------------------------------- -void interactor_impl::enableCameraMovement() +interactor& interactor_impl::enableCameraMovement() { this->Internals->Style->SetCameraMovementDisabled(false); + return *this; } //---------------------------------------------------------------------------- -void interactor_impl::disableCameraMovement() +interactor& interactor_impl::disableCameraMovement() { this->Internals->Style->SetCameraMovementDisabled(true); + return *this; } //---------------------------------------------------------------------------- @@ -1165,23 +1170,26 @@ bool interactor_impl::recordInteraction(const std::string& file) } //---------------------------------------------------------------------------- -void interactor_impl::start(double loopTime, std::function userCallBack) +interactor& interactor_impl::start(double loopTime, std::function userCallBack) { this->Internals->StartEventLoop(loopTime, std::move(userCallBack)); this->Internals->VTKInteractor->Start(); + return *this; } //---------------------------------------------------------------------------- -void interactor_impl::stop() +interactor& interactor_impl::stop() { this->Internals->StopEventLoop(); this->Internals->VTKInteractor->ExitCallback(); + return *this; } //---------------------------------------------------------------------------- -void interactor_impl::requestRender() +interactor& interactor_impl::requestRender() { this->Internals->RenderRequested = true; + return *this; } //---------------------------------------------------------------------------- diff --git a/library/src/options.cxx b/library/src/options.cxx index b22338aae6..2253f779eb 100644 --- a/library/src/options.cxx +++ b/library/src/options.cxx @@ -146,13 +146,14 @@ bool options::isOptional(const std::string& option) const } //---------------------------------------------------------------------------- -void options::reset(const std::string& name) +options& options::reset(const std::string& name) { options_tools::reset(*this, name); + return *this; } //---------------------------------------------------------------------------- -void options::removeValue(const std::string& name) +options& options::removeValue(const std::string& name) { if (this->isOptional(name)) { @@ -162,6 +163,7 @@ void options::removeValue(const std::string& name) { throw options::incompatible_exception("Option " + name + " is not not optional"); } + return *this; } //---------------------------------------------------------------------------- diff --git a/library/testing/TestSDKImage.cxx b/library/testing/TestSDKImage.cxx index 336f225794..96b704c063 100644 --- a/library/testing/TestSDKImage.cxx +++ b/library/testing/TestSDKImage.cxx @@ -69,7 +69,7 @@ int TestSDKImage(int argc, char* argv[]) test("generated JPG buffer not empty", bufferJPG.size() != 0); test.expect("save incompatible buffer to TIF format", - [&]() { generated.saveBuffer(f3d::image::SaveFormat::TIF); }); + [&]() { std::ignore = generated.saveBuffer(f3d::image::SaveFormat::TIF); }); std::vector bufferBMP = generated.saveBuffer(f3d::image::SaveFormat::BMP); test("generated BMP buffer not empty", bufferBMP.size() != 0); @@ -82,16 +82,16 @@ int TestSDKImage(int argc, char* argv[]) test.expect( "save buffer to incorrect path", [&]() { generated.save("/dummy/folder/img.png"); }); test.expect("save incompatible buffer to BMP format", - [&]() { img16.saveBuffer(f3d::image::SaveFormat::BMP); }); + [&]() { std::ignore = img16.saveBuffer(f3d::image::SaveFormat::BMP); }); test.expect("save incompatible buffer to PNG format", - [&]() { img32.saveBuffer(f3d::image::SaveFormat::PNG); }); + [&]() { std::ignore = img32.saveBuffer(f3d::image::SaveFormat::PNG); }); f3d::image img2Ch(4, 4, 2); f3d::image img5Ch(4, 4, 5); test.expect("save incompatible channel count to BMP format", - [&]() { img5Ch.saveBuffer(f3d::image::SaveFormat::BMP); }); + [&]() { std::ignore = img5Ch.saveBuffer(f3d::image::SaveFormat::BMP); }); test.expect("save incompatible channel count to JPG format", - [&]() { img2Ch.saveBuffer(f3d::image::SaveFormat::JPG); }); + [&]() { std::ignore = img2Ch.saveBuffer(f3d::image::SaveFormat::JPG); }); test.expect( "read image from incorrect path", [&]() { f3d::image img("/dummy/folder/img.png"); }); @@ -221,9 +221,10 @@ int TestSDKImage(int argc, char* argv[]) // test toTerminalText { test.expect("invalid toTerminalText with BYTE", - [&]() { f3d::image(3, 3, 1, f3d::image::ChannelType::BYTE).toTerminalText(); }); - test.expect("invalid toTerminalText with SHORT", - [&]() { f3d::image(3, 3, 4, f3d::image::ChannelType::SHORT).toTerminalText(); }); + [&]() { std::ignore = f3d::image(3, 3, 1, f3d::image::ChannelType::BYTE).toTerminalText(); }); + test.expect("invalid toTerminalText with SHORT", [&]() { + std::ignore = f3d::image(3, 3, 4, f3d::image::ChannelType::SHORT).toTerminalText(); + }); const auto fileToString = [](const std::string& path) { std::ifstream file(path); @@ -253,11 +254,11 @@ int TestSDKImage(int argc, char* argv[]) std::set(keys.begin(), keys.end()) == std::set({ "foo", "hello" })); test.expect( - "invalid get metadata", [&]() { img.getMetadata("baz"); }); + "invalid get metadata", [&]() { std::ignore = img.getMetadata("baz"); }); test.expect("remove and get metadata", [&]() { - img.setMetadata("foo", ""); // empty value, should remove key - img.getMetadata("foo"); // expected to throw + img.setMetadata("foo", ""); // empty value, should remove key + std::ignore = img.getMetadata("foo"); // expected to throw }); test( diff --git a/library/testing/TestSDKOptions.cxx b/library/testing/TestSDKOptions.cxx index d9822e0be8..abbeeb9d2f 100644 --- a/library/testing/TestSDKOptions.cxx +++ b/library/testing/TestSDKOptions.cxx @@ -175,7 +175,7 @@ int TestSDKOptions(int argc, char* argv[]) // Test isSame/copy error path test.expect( - "inexistent_exception exception on isSame", [&]() { opt.isSame(opt2, "dummy"); }); + "inexistent_exception exception on isSame", [&]() { std::ignore = opt.isSame(opt2, "dummy"); }); test.expect( "inexistent_exception exception on copy", [&]() { opt.copy(opt2, "dummy"); }); @@ -188,20 +188,20 @@ int TestSDKOptions(int argc, char* argv[]) "inexistent_exception exception on set", [&]() { opt.set("dummy", 2.13); }); test.expect( - "inexistent_exception exception on get", [&]() { opt.get("dummy"); }); + "inexistent_exception exception on get", [&]() { std::ignore = opt.get("dummy"); }); test.expect( - "no_value_exception exception on get", [&]() { opt.get("render.point_size"); }); + "no_value_exception exception on get", [&]() { std::ignore = opt.get("render.point_size"); }); // Test setAsString/getAsString error paths test.expect( "inexistent_exception exception on setAsString", [&]() { opt.setAsString("dummy", "2.13"); }); - test.expect( - "inexistent_exception exception on getAsString", [&]() { opt.getAsString("dummy"); }); + test.expect("inexistent_exception exception on getAsString", + [&]() { std::ignore = opt.getAsString("dummy"); }); - test.expect( - "no_value_exception exception on getAsString", [&]() { opt.getAsString("render.point_size"); }); + test.expect("no_value_exception exception on getAsString", + [&]() { std::ignore = opt.getAsString("render.point_size"); }); f3d::options opt6{}; @@ -215,7 +215,7 @@ int TestSDKOptions(int argc, char* argv[]) // Test isOptional non-existent options test.expect( - "isOptional with non-existent option", [&]() { opt6.isOptional("dummy"); }); + "isOptional with non-existent option", [&]() { std::ignore = opt6.isOptional("dummy"); }); f3d::options opt7{}; @@ -228,7 +228,7 @@ int TestSDKOptions(int argc, char* argv[]) opt7.model.scivis.array_name = "dummy"; opt7.reset("model.scivis.array_name"); test.expect( - "reset non-optional values", [&]() { opt7.get("model.scivis.array_name"); }); + "reset non-optional values", [&]() { std::ignore = opt7.get("model.scivis.array_name"); }); // Test reset non-existent option test.expect( @@ -240,7 +240,7 @@ int TestSDKOptions(int argc, char* argv[]) opt8.model.scivis.array_name = "dummy"; opt8.removeValue("model.scivis.array_name"); test.expect( - "removeValue optional values", [&]() { opt8.get("model.scivis.array_name"); }); + "removeValue optional values", [&]() { std::ignore = opt8.get("model.scivis.array_name"); }); // Test removeValue non-optional values test.expect( diff --git a/library/testing/TestSDKOptionsIO.cxx b/library/testing/TestSDKOptionsIO.cxx index 333fb22321..28448107e6 100644 --- a/library/testing/TestSDKOptionsIO.cxx +++ b/library/testing/TestSDKOptionsIO.cxx @@ -23,7 +23,8 @@ class ParsingTest : public PseudoUnitTest template void parse_expect(const std::string& label, const std::string& input) { - PseudoUnitTest::expect(label + " `" + input + "`", [&]() { f3d::options::parse(input); }); + PseudoUnitTest::expect( + label + " `" + input + "`", [&]() { std::ignore = f3d::options::parse(input); }); } }; diff --git a/library/testing/TestSDKUtils.cxx b/library/testing/TestSDKUtils.cxx index e4157d616b..2ca8f94452 100644 --- a/library/testing/TestSDKUtils.cxx +++ b/library/testing/TestSDKUtils.cxx @@ -63,10 +63,10 @@ int TestSDKUtils(int argc, char* argv[]) std::vector{ "set", "render.hdri.file", R"(file\pa\th\backsl\ashes)" }); test.expect("tokenize_exception with incomplete quotes", - [&]() { f3d::utils::tokenize(R"(set render.hdri.file "file path back)"); }); + [&]() { std::ignore = f3d::utils::tokenize(R"(set render.hdri.file "file path back)"); }); test.expect("tokenize_exception with unfinishied escape", - [&]() { f3d::utils::tokenize(R"(set render.hdri.file file path back\)"); }); + [&]() { std::ignore = f3d::utils::tokenize(R"(set render.hdri.file file path back\)"); }); //