Page MenuHomePhorge

project_path.hpp
No OneTemporary

Size
2 KB
Referenced Files
None
Subscribers
None

project_path.hpp

//===-- rosa/config/project_path.hpp ----------------------------*- C++ -*-===//
//
// The RoSA Framework
//
// Distributed under the terms and conditions of the Boost Software License 1.0.
// See accompanying file LICENSE.
//
// If you did not receive a copy of the license file, see
// http://www.boost.org/LICENSE_1_0.txt.
//
//===----------------------------------------------------------------------===//
///
/// \file rosa/config/project_path.hpp
///
/// \author David Juhasz (david.juhasz@tuwien.ac.at)
///
/// \date 2017-2020
///
/// \brief Facility for compile-time manipulation of paths.
///
//===----------------------------------------------------------------------===//
#ifndef ROSA_CONFIG_PROJECT_PATH_HPP
#define ROSA_CONFIG_PROJECT_PATH_HPP
#include "rosa/config/rosa_config.h"
#include "rosa/support/diagnostics.h"
#include <cstdlib>
namespace rosa {
/// Nested namespace with implementation of the provided features,
/// consider it private.
namespace {
/// Tells the index of the project-relative part of an absolute path.
///
/// \param path absolute path to check
/// \param project the absolute path of the project
/// \param index number of leading characters already checked and found
/// matching
///
/// \return index of the part relative to \c project in \p path; \c 0 if \p path
/// is not under \p project
constexpr size_t
project_relative_path_index_impl(const char *const path,
const char *const project = ROSA_SRC_DIR,
const size_t index = 0) {
return project[index] == '\0'
? index // Found it.
: (path[index] == '\0' || project[index] != path[index])
? 0 // Path is not under project.
: project_relative_path_index_impl(
path, project,
index + 1); // Continue searching...
}
} // End namespace
/// Tells the index of the project-relative part of an absolute path.
///
/// \param path absolute path to check
///
/// \return index of the project-relative part of \p path; \c 0 if \p path is
/// not under the RoSA source directory.
constexpr size_t project_relative_path_index(const char *const path) {
return project_relative_path_index_impl(path);
}
/// Gives the project-relative part of an absolute path.
///
/// \param path absolute path to check
///
/// \return the project-relative part of \p path; \c path if it is not under the
/// RoSA source directory.
constexpr const char *project_relative_path(const char *const path) {
// NOTE: Some compilers warn about adding int to string.
ROSA_DISABLE_WARNING_PUSH;
ROSA_DISABLE_WARNING_ADDING_INT_TO_STRING;
return path + project_relative_path_index(path);
ROSA_DISABLE_WARNING_POP;
}
} // End namespace rosa
#endif // ROSA_CONFIG_PROJECT_PATH_HPP

File Metadata

Mime Type
text/x-c++
Expires
Sun, Mar 1, 9:33 PM (1 d, 9 h)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
287616
Default Alt Text
project_path.hpp (2 KB)

Event Timeline