##

CommonIface.hh
Go to the documentation of this file.
/*
* Copyright (C) 2012 Open Source Robotics Foundation
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/
#ifndef GAZEBO_COMMON_COMMONIFACE_HH_
#define GAZEBO_COMMON_COMMONIFACE_HH_
#include <string>
#include <vector>
#include <boost/version.hpp>
#if BOOST_VERSION < 106600
#include <boost/uuid/sha1.hpp>
#else
#include <boost/uuid/detail/sha1.hpp>
#endif
#include <boost/filesystem.hpp>
#include <iomanip>
#include <sstream>
#include "gazebo/util/system.hh"
namespace gazebo
{
namespace common
{
GZ_COMMON_VISIBLE
void load();
GZ_COMMON_VISIBLE
void add_search_path_suffix(const std::string &_suffix);
GZ_COMMON_VISIBLE
std::string find_file(const std::string &_file);
GZ_COMMON_VISIBLE
std::string find_file(const std::string &_file,
bool _searchLocalPath);
GZ_COMMON_VISIBLE
std::string find_file_path(const std::string &_file);
template<typename T>
std::string get_sha1(const T &_buffer);
GZ_COMMON_VISIBLE
const char *getEnv(const char *_name);
GZ_COMMON_VISIBLE
std::string cwd();
GZ_COMMON_VISIBLE
bool exists(const std::string &_path);
GZ_COMMON_VISIBLE
bool isDirectory(const std::string &_path);
GZ_COMMON_VISIBLE
bool isFile(const std::string &_path);
GZ_COMMON_VISIBLE
std::string absPath(const std::string &_path);
GZ_COMMON_VISIBLE
bool copyFile(const std::string &_existingFilename,
const std::string &_newFilename);
GZ_COMMON_VISIBLE
bool copyDir(const boost::filesystem::path &_source,
const boost::filesystem::path &_destination);
GZ_COMMON_VISIBLE
bool moveFile(const std::string &_existingFilename,
const std::string &_newFilename);
GZ_COMMON_VISIBLE
void replaceAll(std::string &_result,
const std::string &_orig,
const std::string &_key,
const std::string &_replacement);
GZ_COMMON_VISIBLE
std::string replaceAll(const std::string &_orig,
const std::string &_key,
const std::string &_replacement);
GZ_COMMON_VISIBLE
std::vector<std::string> split(const std::string &_str,
const std::string &_delim);
GZ_COMMON_VISIBLE
std::string unique_file_path(const std::string &_pathAndName,
const std::string &_extension);
}
// Implementation of get_sha1
template<typename T>
std::string common::get_sha1(const T &_buffer)
{
boost::uuids::detail::sha1 sha1;
unsigned int hash[5];
std::stringstream stream;
if (_buffer.size() == 0)
{
sha1.process_bytes(nullptr, 0);
}
else
{
sha1.process_bytes(&(_buffer[0]), _buffer.size() * sizeof(_buffer[0]));
}
sha1.get_digest(hash);
for (std::size_t i = 0; i < sizeof(hash) / sizeof(hash[0]); ++i)
{
stream << std::setfill('0')
<< std::setw(sizeof(hash[0]) * 2)
<< std::hex
<< hash[i];
}
return stream.str();
}
}
#endif
gazebo::common::getEnv
const char * getEnv(const char *_name)
Cross platform retrieval of an environment variable.
gazebo::common::split
std::vector< std::string > split(const std::string &_str, const std::string &_delim)
Splits a string into tokens.
gazebo
Forward declarations for the common classes.
Definition: Animation.hh:26
gazebo::common::find_file_path
std::string find_file_path(const std::string &_file)
search for a file in common::SystemPaths
common
common
Definition: FuelModelDatabase.hh:37
gazebo::common::isFile
bool isFile(const std::string &_path)
Check if the given path is a file.
gazebo::common::load
void load()
Load the common library.
gazebo::common::copyDir
bool copyDir(const boost::filesystem::path &_source, const boost::filesystem::path &_destination)
Copy a directory, overwrite the destination directory if exists.
system.hh
gazebo::common::cwd
std::string cwd()
Get the current working directory.
gazebo::common::unique_file_path
std::string unique_file_path(const std::string &_pathAndName, const std::string &_extension)
Generates a path for a file which doesn't collide with existing files, by appending numbers to it (i....
gazebo::common::copyFile
bool copyFile(const std::string &_existingFilename, const std::string &_newFilename)
Copy a file.
gazebo::common::find_file
std::string find_file(const std::string &_file)
search for file in common::SystemPaths
gazebo::common::isDirectory
bool isDirectory(const std::string &_path)
Check if the given path is a directory.
gazebo::common::absPath
std::string absPath(const std::string &_path)
Get the absolute path of a provided path.
gazebo::common::add_search_path_suffix
void add_search_path_suffix(const std::string &_suffix)
add path sufix to common::SystemPaths
gazebo::common::moveFile
bool moveFile(const std::string &_existingFilename, const std::string &_newFilename)
Move a file.
gazebo::common::exists
bool exists(const std::string &_path)
Returns true if _path is a file or directory.
gazebo::common::replaceAll
void replaceAll(std::string &_result, const std::string &_orig, const std::string &_key, const std::string &_replacement)
Replace all occurances of _key with _replacement.
gazebo::common::get_sha1
std::string get_sha1(const T &_buffer)
Compute the SHA1 hash of an array of bytes.
Definition: CommonIface.hh:190