Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[ign to gz] C++ namespaces #50

Closed
wants to merge 6 commits into from
Closed
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
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions Migration.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,11 @@ Deprecated code produces compile-time warnings. These warning serve as
notification to users that their code should be upgraded. The next major
release will remove the deprecated code.

## Ignition Utils 1.X to 2.X

* The `ignition` namespace is deprecated and will be removed in future versions.
Use `gz` instead.

## Ignition Utils 1.2 to 1.3

Recommended migration:
Expand Down
4 changes: 2 additions & 2 deletions include/ignition/utils/Environment.hh
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@

#include <string>

namespace ignition
namespace gz
{
namespace utils
{
Expand Down Expand Up @@ -68,7 +68,7 @@ bool IGNITION_UTILS_VISIBLE unsetenv(const std::string &_name);

}
} // namespace utils
} // namespace ignition
} // namespace gz

#endif // IGNITION_UTILS_ENVIRONMENT_HH_

11 changes: 7 additions & 4 deletions include/ignition/utils/ImplPtr.hh
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,16 @@
#include <memory>
#include <utility>

#include <ignition/utils/config.hh>
#include <ignition/utils/detail/DefaultOps.hh>
#include <ignition/utils/SuppressWarning.hh>
#include <ignition/utils/Export.hh>

namespace ignition
namespace gz
{
namespace utils
{
inline namespace IGNITION_UTILS_VERSION_NAMESPACE {
//////////////////////////////////////////////////
/// \brief The ImplPtr class provides a convenient away to achieve the
/// <a href="http://en.cppreference.com/w/cpp/language/rule_of_three">
Expand Down Expand Up @@ -225,21 +227,22 @@ namespace ignition
/// created object into it.
template <class T, typename... Args>
UniqueImplPtr<T> MakeUniqueImpl(Args &&..._args);
}
} // namespace utils
} // namespace ignition
} // namespace gz

/// \brief Add a private ImplPtr to a class as dataPtr.
/// This variant takes a forward-declared ImplementationClass as the impl.
#define IGN_UTILS_IMPL_PTR_FWD(ImplementationClass, memberName) \
IGN_UTILS_WARN_IGNORE__DLL_INTERFACE_MISSING \
private: ::ignition::utils::ImplPtr<ImplementationClass> memberName; \
private: ::gz::utils::ImplPtr<ImplementationClass> memberName; \
IGN_UTILS_WARN_RESUME__DLL_INTERFACE_MISSING

/// \brief Add a private UniqueImplPtr to a class as dataPtr.
/// This variant takes a forward-declared ImplementationClass as the impl.
#define IGN_UTILS_UNIQUE_IMPL_PTR_FWD(ImplementationClass, memberName) \
IGN_UTILS_WARN_IGNORE__DLL_INTERFACE_MISSING \
private: ::ignition::utils::UniqueImplPtr<ImplementationClass> memberName; \
private: ::gz::utils::UniqueImplPtr<ImplementationClass> memberName; \
IGN_UTILS_WARN_RESUME__DLL_INTERFACE_MISSING

/// \brief Add a private ImplPtr to a class as dataPtr.
Expand Down
18 changes: 10 additions & 8 deletions include/ignition/utils/NeverDestroyed.hh
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,13 @@
#include <type_traits>
#include <utility>

namespace ignition
#include <ignition/utils/config.hh>

namespace gz
{
namespace utils
{

inline namespace IGNITION_UTILS_VERSION_NAMESPACE {
/// Originally copied from https://github.com/RobotLocomotion/drake/blob/v0.36.0/common/never_destroyed.h
/// Originally licensed BSD 3-Clause (https://github.com/RobotLocomotion/drake/blob/v0.36.0/LICENSE.TXT)
/// Re-licensed Apache-2.0 with permission from:
Expand Down Expand Up @@ -62,11 +64,11 @@ namespace utils
///
/// static Singleton& getInstance()
/// {
/// static ignition::utils::NeverDestroyed<Singleton> instance;
/// static gz::utils::NeverDestroyed<Singleton> instance;
/// return instance.access();
/// }
/// private:
/// friend ignition::utils::NeverDestroyed<Singleton>;
/// friend gz::utils::NeverDestroyed<Singleton>;
/// Singleton() = default;
/// };
/// @endcode
Expand All @@ -78,7 +80,7 @@ namespace utils
/// Foo ParseFoo(const std::string& foo_string)
/// {
/// using Dict = std::unordered_map<std::string, Foo>;
/// static const ignition::utils::NeverDestroyed<Dict> string_to_enum
/// static const gz::utils::NeverDestroyed<Dict> string_to_enum
/// {
/// std::initializer_list<Dict::value_type>
/// {
Expand All @@ -95,7 +97,7 @@ namespace utils
/// @code
/// const std::vector<double>& GetConstantMagicNumbers()
/// {
/// static const ignition::utils::NeverDestroyed<std::vector<double>> result
/// static const gz::utils::NeverDestroyed<std::vector<double>> result
/// {
/// []()
/// {
Expand Down Expand Up @@ -155,8 +157,8 @@ class NeverDestroyed

private: typename std::aligned_storage<sizeof(T), alignof(T)>::type storage;
};

}
} // namespace utils
} // namespace ignition
} // namespace gz

#endif // IGNITION_UTILS_NEVERDESTROYED_HH_
29 changes: 28 additions & 1 deletion include/ignition/utils/config.hh.in
Original file line number Diff line number Diff line change
@@ -1,4 +1,24 @@
/* Config.hh. Generated by CMake for @PROJECT_NAME_NO_VERSION@. */
/* config.hh. Generated by CMake for @PROJECT_NAME_NO_VERSION@. */

/*
* Copyright (C) 2020 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 IGNITION_UTILS__CONFIG_HH_
#define IGNITION_UTILS__CONFIG_HH_

/* Version number */
#define IGNITION_UTILS_MAJOR_VERSION ${PROJECT_VERSION_MAJOR}
Expand All @@ -15,3 +35,10 @@
#cmakedefine IGNITION_UTILS_BUILD_TYPE_PROFILE 1
#cmakedefine IGNITION_UTILS_BUILD_TYPE_DEBUG 1
#cmakedefine IGNITION_UTILS_BUILD_TYPE_RELEASE 1

namespace [[deprecated("Use gz namespace.")]] ignition
{
using namespace gz;
}

#endif
6 changes: 4 additions & 2 deletions include/ignition/utils/detail/DefaultOps.hh
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,11 @@

#include <type_traits>

namespace ignition
namespace gz
{
namespace utils
{
inline namespace IGNITION_UTILS_VERSION_NAMESPACE {
namespace detail
{
//////////////////////////////////////////////////
Expand Down Expand Up @@ -76,9 +77,10 @@ namespace ignition
public: CopyConstruct construct;
public: CopyAssign assign;
};
}
} // namespace detail
} // namespace utils
} // namespace ignition
} // namespace gz

#endif // IGNITION_UTILS__DETAIL__DEFAULTOPS_HH_

6 changes: 4 additions & 2 deletions include/ignition/utils/detail/ImplPtr.hh
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,11 @@

#include <utility>

namespace ignition
namespace gz
{
namespace utils
{
inline namespace IGNITION_UTILS_VERSION_NAMESPACE {
namespace detail
{
//////////////////////////////////////////////////
Expand Down Expand Up @@ -145,7 +146,8 @@ namespace ignition
new T{std::forward<Args>(args)...},
&detail::DefaultDelete<T>);
}
}
} // namespace utils
} // namespace ignition
} // namespace gz

#endif // IGNITION_UTILS__DETAIL__IMPLPTR_HH_
2 changes: 1 addition & 1 deletion src/Environment.cc
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
#include <iostream>


namespace ignition
namespace gz
{
namespace utils
{
Expand Down
2 changes: 1 addition & 1 deletion src/Environment_TEST.cc
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@

#include <ignition/utils/Environment.hh>

using namespace ignition;
using namespace gz;

/////////////////////////////////////////////////
TEST(Environment, emptyENV)
Expand Down
10 changes: 5 additions & 5 deletions src/NeverDestroyed_TEST.cc
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ GTEST_TEST(NeverDestroyed, NoBoomTest)
try
{
{
ignition::utils::NeverDestroyed<DtorGoesBoom> foo;
gz::utils::NeverDestroyed<DtorGoesBoom> foo;
}
ASSERT_TRUE(true);
}
Expand All @@ -83,11 +83,11 @@ class Singleton
public: void operator=(Singleton &&) = delete;
public: static Singleton &getInstance()
{
static ignition::utils::NeverDestroyed<Singleton> instance;
static gz::utils::NeverDestroyed<Singleton> instance;
return instance.Access();
}

private: friend ignition::utils::NeverDestroyed<Singleton>;
private: friend gz::utils::NeverDestroyed<Singleton>;
private: Singleton() = default;
};

Expand All @@ -108,7 +108,7 @@ enum class Foo
Foo ParseFoo(const std::string &foo_string)
{
using Dict = std::unordered_map<std::string, Foo>;
static const ignition::utils::NeverDestroyed<Dict> string_to_enum{
static const gz::utils::NeverDestroyed<Dict> string_to_enum{
std::initializer_list<Dict::value_type>{
{"bar", Foo::kBar},
{"baz", Foo::kBaz},
Expand All @@ -127,7 +127,7 @@ GTEST_TEST(NeverDestroyedExample, ParseFoo)
using Result = std::vector<std::uint_fast32_t>;
const Result &GetConstantMagicNumbers()
{
static const ignition::utils::NeverDestroyed<Result> result{
static const gz::utils::NeverDestroyed<Result> result{
[]()
{
Result prototype;
Expand Down
4 changes: 2 additions & 2 deletions test/integration/all_symbols_have_version.bash.in
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ VERSIONED_NS=v@PROJECT_VERSION_MAJOR@
IGN_PROJECT=@IGN_DESIGNATION@

# Sanity check - there should be at least one symbol
NUM_SYMBOLS=$(nm $LIBPATH | grep -e "ignition.*$IGN_PROJECT" | wc -l)
NUM_SYMBOLS=$(nm $LIBPATH | grep -e "gz.*$IGN_PROJECT" | wc -l)

if [ $NUM_SYMBOLS -eq 0 ]
then
Expand All @@ -14,7 +14,7 @@ then
fi

# There must be no unversioned symbols
UNVERSIONED_SYMBOLS=$(nm $LIBPATH | grep -e "ignition.*$IGN_PROJECT" | grep -e "$VERSIONED_NS" -v)
UNVERSIONED_SYMBOLS=$(nm $LIBPATH | grep -e "gz.*$IGN_PROJECT" | grep -e "$VERSIONED_NS" -v)
UNVERSIONED_SYMBOL_CHARS=$(printf "$UNVERSIONED_SYMBOLS" | wc -m)

if [ $UNVERSIONED_SYMBOL_CHARS -ne 0 ]
Expand Down
34 changes: 34 additions & 0 deletions test/integration/deprecated_TEST.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
/*
* Copyright (C) 2022 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.
*
*/

#include <gtest/gtest.h>

#include <ignition/utils/ImplPtr.hh>
#include <ignition/utils/NeverDestroyed.hh>
#include <ignition/utils/SuppressWarning.hh>

IGN_UTILS_WARN_IGNORE__DEPRECATED_DECLARATION

/////////////////////////////////////////////////
// Make sure the ignition namespace still works
TEST(Deprecated, IgnitionNamespace)
{
auto impl = ignition::utils::MakeImpl<int>();
ignition::utils::NeverDestroyed<int> neverDestroyed;
}

IGN_UTILS_WARN_RESUME__DEPRECATED_DECLARATION
2 changes: 1 addition & 1 deletion test/integration/implptr/ImplPtr_TEST.cc
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
#include <ignition/utils/ImplPtr.hh>
#include "implptr_test_classes.hh"

using namespace ignition::implptr_test_classes;
using namespace gz::implptr_test_classes;

/////////////////////////////////////////////////
TEST(ImplPtr, CopyConstruct)
Expand Down
6 changes: 3 additions & 3 deletions test/integration/implptr/implptr_test_classes.cc
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,10 @@
#include <string>
#include <thread>

using namespace ignition;
using namespace ignition::implptr_test_classes;
using namespace gz;
using namespace gz::implptr_test_classes;

class ignition::implptr_test_classes::ObjectPrivate
class gz::implptr_test_classes::ObjectPrivate
{
public: void TestFunc()
{
Expand Down
10 changes: 5 additions & 5 deletions test/integration/implptr/implptr_test_classes.hh
Original file line number Diff line number Diff line change
Expand Up @@ -15,16 +15,16 @@
*
*/

#ifndef IGNITION_UTILS_TEST_IMPLPTR_TEST_CLASSES_HH_
#define IGNITION_UTILS_TEST_IMPLPTR_TEST_CLASSES_HH_
#ifndef GZ_UTILS_TEST_IMPLPTR_TEST_CLASSES_HH_
#define GZ_UTILS_TEST_IMPLPTR_TEST_CLASSES_HH_

#include <ignition/utils/ImplPtr.hh>
#include <ignition/utils/Export.hh>

#include <functional>
#include <string>

namespace ignition
namespace gz
{
namespace implptr_test_classes
{
Expand Down Expand Up @@ -117,6 +117,6 @@ namespace ignition
};

} // namespace implptr_test_classes
} // namespace ignition
} // namespace gz

#endif // IGNITION_UTILS_TEST_IMPLPTR_TEST_CLASSES_HH_
#endif // GZ_UTILS_TEST_IMPLPTR_TEST_CLASSES_HH_