Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
6 changes: 4 additions & 2 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,9 @@ find_package(ignition-cmake3 REQUIRED)
#============================================================================
# Configure the project
#============================================================================
ign_configure_project(VERSION_SUFFIX pre1)
ign_configure_project(
REPLACE_IGNITION_INCLUDE_PATH gz/msgs
VERSION_SUFFIX pre1)

#============================================================================
# Set project-specific options
Expand Down Expand Up @@ -115,7 +117,7 @@ configure_file(${CMAKE_SOURCE_DIR}/tutorials.md.in ${CMAKE_BINARY_DIR}/tutorials
ign_create_docs(
API_MAINPAGE_MD "${CMAKE_BINARY_DIR}/api.md"
TUTORIALS_MAINPAGE_MD "${CMAKE_BINARY_DIR}/tutorials.md"
AUTOGENERATED_DOC "${CMAKE_BINARY_DIR}/include/ignition/msgs/"
AUTOGENERATED_DOC "${CMAKE_BINARY_DIR}/include/gz/msgs/"
TAGFILES
"${IGNITION-MATH_DOXYGEN_TAGFILE} = ${IGNITION-MATH_API_URL}"
)
Expand Down
3 changes: 2 additions & 1 deletion include/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
add_subdirectory(ignition/msgs)
add_subdirectory(gz)
install(DIRECTORY ignition DESTINATION ${IGN_INCLUDE_INSTALL_DIR_FULL})
1 change: 1 addition & 0 deletions include/gz/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
add_subdirectory(msgs)
4 changes: 4 additions & 0 deletions include/gz/msgs/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
ign_install_all_headers(
GENERATED_HEADERS
MessageTypes.hh
)
135 changes: 135 additions & 0 deletions include/gz/msgs/Factory.hh
Original file line number Diff line number Diff line change
@@ -0,0 +1,135 @@
/*
* Copyright (C) 2016 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 GZ_MSGS_FACTORY_HH_
#define GZ_MSGS_FACTORY_HH_

#ifdef _MSC_VER
#pragma warning(push)
#pragma warning(disable: 4100 4512 4127 4068 4244 4267 4251 4146)
#endif
#include <google/protobuf/message.h>
#ifdef _MSC_VER
#pragma warning(pop)
#endif

#include <string>
#include <map>
#include <memory>
#include <vector>

#include "gz/msgs/config.hh"
#include "gz/msgs/Export.hh"

namespace ignition
{
namespace msgs
{
// Inline bracket to help doxygen filtering.
inline namespace IGNITION_MSGS_VERSION_NAMESPACE {
//
/// \typedef FactoryFn
/// \brief Prototype for message factory generation
typedef std::unique_ptr<google::protobuf::Message> (*FactoryFn) ();

/// \class Factory Factory.hh ignition/msgs.hh
/// \brief A factory that generates protobuf message based on a string type.
/// This class will also try to load all Protobuf descriptors specified
/// in the IGN_DESCRIPTOR_PATH environment variable on program start.
class IGNITION_MSGS_VISIBLE Factory
{
/// \brief Register a message.
/// \param[in] _msgType Type of message to register.
/// \param[in] _factoryfn Function that generates the message.
public: static void Register(const std::string &_msgType,
FactoryFn _factoryfn);

/// \brief Create a new instance of a message.
/// \param[in] _msgType Type of message to create.
/// \return Pointer to a google protobuf message. Null if the message
/// type could not be handled.
public: template<typename T>
static std::unique_ptr<T> New(const std::string &_msgType)
{
return std::unique_ptr<T>(
static_cast<T*>(New(_msgType).release()));
}

/// \brief Create a new instance of a message.
/// \param[in] _msgType Type of message to create.
/// \param[in] _args Message arguments. This will populate the message.
/// \return Pointer to a google protobuf message. Null if the message
/// type could not be handled.
public: template<typename T>
static std::unique_ptr<T> New(const std::string &_msgType,
const std::string &_args)
{
return std::unique_ptr<T>(
static_cast<T*>(New(_msgType, _args).release()));
}

/// \brief Create a new instance of a message.
/// \param[in] _msgType Type of message to create.
/// \return Pointer to a google protobuf message. Null if the message
/// type could not be handled.
public: static std::unique_ptr<google::protobuf::Message> New(
const std::string &_msgType);

/// \brief Create a new instance of a message.
/// \param[in] _msgType Type of message to create.
/// \param[in] _args Message arguments. This will populate the message.
/// \return Pointer to a google protobuf message. Null if the message
/// type could not be handled.
public: static std::unique_ptr<google::protobuf::Message> New(
const std::string &_msgType, const std::string &_args);

/// \brief Get all the message types
/// \param[out] _types Vector of strings of the message types.
public: static void Types(std::vector<std::string> &_types);

/// \brief Load a collection of descriptor .desc files.
/// \param[in] _paths A set of directories containing .desc decriptor
/// files. Each directory should be separated by ":".
public: static void LoadDescriptors(const std::string &_paths);

/// \brief A list of registered message types
private: static std::map<std::string, FactoryFn> *msgMap;
};

/// \brief Static message registration macro
///
/// Use this macro to register messages.
/// \param[in] _msgtype Message type name.
/// \param[in] _classname Class name for message.
#define IGN_REGISTER_STATIC_MSG(_msgtype, _classname) \
IGNITION_MSGS_VISIBLE \
std::unique_ptr<google::protobuf::Message> New##_classname() \
{ \
return std::unique_ptr<ignition::msgs::_classname>(\
new ignition::msgs::_classname); \
} \
class IGNITION_MSGS_VISIBLE IgnMsg##_classname \
{ \
public: IgnMsg##_classname() \
{ \
ignition::msgs::Factory::Register(_msgtype, New##_classname);\
} \
}; \
static IgnMsg##_classname IgnitionMessagesInitializer##_classname;
}
}
}
#endif
93 changes: 93 additions & 0 deletions include/gz/msgs/Filesystem.hh
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
/*
* Copyright 2018 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 GZ_MSGS_FILESYSTEM_HH_
#define GZ_MSGS_FILESYSTEM_HH_

#include <memory>
#include <string>

#include <gz/msgs/Export.hh>
#include <gz/utils/SuppressWarning.hh>

namespace ignition
{
namespace msgs
{
/// \brief Options for how to handle errors that occur in functions that
/// manipulate the filesystem.
enum FilesystemWarningOp
{
/// \brief Errors that occur during filesystem manipulation should be
/// logged as warnings using ignwarn. (Recommended)
FSWO_LOG_WARNINGS = 0,

/// \brief Errors that occur during filesystem manipulation should not be
/// logged. The user will be responsible for checking the system's error
/// flags.
FSWO_SUPPRESS_WARNINGS
};

// /// \internal
class DirIterPrivate;

/// \class DirIter Filesystem.hh
/// \brief A class for iterating over all items in a directory.
class IGNITION_MSGS_VISIBLE DirIter
{
/// \brief Constructor.
/// \param[in] _in Directory to iterate over.
public: explicit DirIter(const std::string &_in);

/// \brief Constructor for end element.
public: DirIter();

/// \brief Dereference operator; returns current directory record.
/// \return A string representing the entire path of the directory record.
public: std::string operator*() const;

/// \brief Pre-increment operator; moves to next directory record.
/// \return This iterator.
public: const DirIter& operator++();

/// \brief Comparison operator to see if this iterator is at the
/// same point as another iterator.
/// \param[in] _other The other iterator to compare against.
/// \return true if the iterators are equal, false otherwise.
public: bool operator!=(const DirIter &_other) const;

/// \brief Destructor
public: ~DirIter();

/// \brief Move to the next directory record, skipping . and .. records.
private: void Next();

/// \brief Set the internal variable to the empty string.
private: void SetInternalEmpty();

/// \brief Close an open directory handle.
private: void CloseHandle();

IGN_UTILS_WARN_IGNORE__DLL_INTERFACE_MISSING
/// \brief Private data.
private: std::unique_ptr<DirIterPrivate> dataPtr;
IGN_UTILS_WARN_RESUME__DLL_INTERFACE_MISSING
};
}
}

#endif
Loading