Skip to content

Commit

Permalink
Removed inlines in cpp files when possible (#1030)
Browse files Browse the repository at this point in the history
  • Loading branch information
xelatihy authored Aug 20, 2020
1 parent f5cb7f3 commit 809ef37
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 82 deletions.
6 changes: 3 additions & 3 deletions libs/yocto/yocto_image.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -433,7 +433,7 @@ vec3f lookup_image(const image<vec3b>& img, const vec2i& ij, bool as_linear) {

// Evaluate a texture
template <typename T, typename R>
inline R eval_image_generic(const image<T>& img, const vec2f& uv,
static R eval_image_generic(const image<T>& img, const vec2f& uv,
bool as_linear, bool no_interpolation, bool clamp_to_edge) {
if (img.empty()) return R{};

Expand Down Expand Up @@ -1339,13 +1339,13 @@ image<vec4b> add_logo(const image<vec4b>& img, const string& type) {
namespace yocto {

// Lookup volume
inline float lookup_volume(
static float lookup_volume(
const volume<float>& vol, const vec3i& ijk, bool as_linear) {
return vol[ijk];
}

// Evaluates a color image at a point `uv`.
inline float eval_volume(const volume<float>& vol, const vec3f& uvw,
static float eval_volume(const volume<float>& vol, const vec3f& uvw,
bool ldr_as_linear, bool no_interpolation, bool clamp_to_edge) {
if (vol.empty()) return 0;

Expand Down
6 changes: 3 additions & 3 deletions libs/yocto/yocto_mesh.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,13 +43,13 @@ using namespace std::string_literals;
namespace yocto {

// find a value in a vector or vecs
inline int find_in_vec(const vector<int>& vec, int x) {
static int find_in_vec(const vector<int>& vec, int x) {
for (int i = 0; i < size(vec); i++)
if (vec[i] == x) return i;
return -1;
}

inline int find_in_vec(const vec3i& vec, int x) {
static int find_in_vec(const vec3i& vec, int x) {
for (auto i = 0; i < 3; i++)
if (vec[i] == x) return i;
return -1;
Expand Down Expand Up @@ -1814,7 +1814,7 @@ vector<int> strip_on_dual_graph(const dual_geodesic_solver& solver,
return strip;
}

inline int node_is_neighboor(const geodesic_solver& solver, int vid, int node) {
static int node_is_neighboor(const geodesic_solver& solver, int vid, int node) {
auto nbr = solver.graph[vid];
for (auto i = 0; i < nbr.size(); ++i) {
if (nbr[i].node == node) {
Expand Down
78 changes: 2 additions & 76 deletions libs/yocto_gui/yocto_imgui.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@

#include "yocto_imgui.h"

#include <yocto/yocto_commonio.h>

#include <algorithm>
#include <cstdarg>
#include <filesystem>
Expand Down Expand Up @@ -68,82 +70,6 @@ using namespace std::string_literals;

} // namespace yocto

// -----------------------------------------------------------------------------
// FILE UTILITIES
// -----------------------------------------------------------------------------
namespace yocto {

// Make a path from a utf8 string
inline std::filesystem::path make_path(const string& filename) {
return std::filesystem::u8path(filename);
}

// Normalize path
inline string normalize_path(const string& filename) {
return make_path(filename).generic_u8string();
}

// Get directory name (not including /)
inline string path_dirname(const string& filename) {
return make_path(filename).parent_path().generic_u8string();
}

// Get extension (including .)
inline string path_extension(const string& filename) {
return make_path(filename).extension().u8string();
}

// Get filename without directory.
inline string path_filename(const string& filename) {
return make_path(filename).filename().u8string();
}

// Get filename without directory and extension.
inline string path_basename(const string& filename) {
return make_path(filename).stem().u8string();
}

// Joins paths
inline string path_join(const string& patha, const string& pathb) {
return (make_path(patha) / make_path(pathb)).generic_u8string();
}
inline string path_join(
const string& patha, const string& pathb, const string& pathc) {
return (make_path(patha) / make_path(pathb) / make_path(pathc))
.generic_u8string();
}

// Replaces extensions
inline string replace_extension(const string& filename, const string& ext) {
return make_path(filename).replace_extension(ext).u8string();
}

// Check if a file can be opened for reading.
inline bool path_exists(const string& filename) {
return exists(make_path(filename));
}

// Check if a file is a directory
inline bool path_isdir(const string& filename) {
return is_directory(make_path(filename));
}

// Check if a file is a file
inline bool path_isfile(const string& filename) {
return is_regular_file(make_path(filename));
}

// List the contents of a directory
inline vector<string> list_directory(const string& filename) {
auto entries = vector<string>{};
for (auto entry : std::filesystem::directory_iterator(make_path(filename))) {
entries.push_back(entry.path().generic_u8string());
}
return entries;
}

} // namespace yocto

// -----------------------------------------------------------------------------
// UI APPLICATION
// -----------------------------------------------------------------------------
Expand Down

0 comments on commit 809ef37

Please sign in to comment.