You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@mesos.apache.org by ka...@apache.org on 2016/05/11 22:25:01 UTC
[39/50] [abbrv] mesos git commit: Moved stout from
libprocess/3rdparty/ to 3rdparty/.
http://git-wip-us.apache.org/repos/asf/mesos/blob/c235f7c1/3rdparty/libprocess/3rdparty/stout/include/stout/internal/windows/symlink.hpp
----------------------------------------------------------------------
diff --git a/3rdparty/libprocess/3rdparty/stout/include/stout/internal/windows/symlink.hpp b/3rdparty/libprocess/3rdparty/stout/include/stout/internal/windows/symlink.hpp
deleted file mode 100644
index 5dc022b..0000000
--- a/3rdparty/libprocess/3rdparty/stout/include/stout/internal/windows/symlink.hpp
+++ /dev/null
@@ -1,87 +0,0 @@
-// 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 __STOUT_INTERNAL_WINDOWS_SYMLINK_HPP__
-#define __STOUT_INTERNAL_WINDOWS_SYMLINK_HPP__
-
-#include <string>
-
-#include <stout/try.hpp>
-#include <stout/windows.hpp>
-
-#include <stout/internal/windows/reparsepoint.hpp>
-
-#include <stout/os/realpath.hpp>
-
-
-namespace internal {
-namespace windows {
-
-// Gets symlink data for a given path, if it exists.
-//
-// This turns out to be a very complicated task on Windows. The gist of it is
-// that we know that symlinks on Windows are implemented with the Reparse Point
-// API, and so the process is a matter of:
-//
-// 1. Checking whether the attributes for the file/folder specified by the
-// path have the reparse point bit set; all symlinks are implemented with
-// reparse points, so this bit should be on all symlinks.
-// 2. Opening a file/folder handle for that path, instructing it specifically
-// to open a handle for the symlink (if the path points at a symlink) and
-// *not* the file the symlink points at (as is the default). Note that
-// file and folder handles are different, so we have a function that
-// chooses appropriately.
-// 3. Using `DeviceIoControl` to obtain information about the handle for this
-// reparse point, which we can then query to figure out if it's a reparse
-// point that is owned by the symlink filesystem filter driver.
-// 4. If it is, then we report that this path does point at a symlink.
-//
-// NOTE: it may be helpful to consult the documentation for each of these
-// functions, as they give you sources that justify the arguments to the
-// obscure APIs we call to get this all working.
-inline Try<SymbolicLink> query_symbolic_link_data(const std::string& path)
-{
- // Convert to absolute path because Windows APIs expect it.
- const Result<std::string> absolute_path = os::realpath(path);
- if (!absolute_path.isSome()) {
- return Error(absolute_path.error());
- }
-
- // Windows has no built-in way to tell whether a path points at a symbolic
- // link; but, we know that symbolic links are implemented with reparse
- // points, so we begin by checking that.
- Try<bool> is_reparse_point =
- reparse_point_attribute_set(absolute_path.get());
-
- if (is_reparse_point.isError()) {
- return Error(is_reparse_point.error());
- } else if (!is_reparse_point.get()) {
- return Error(
- "Reparse point attribute is not set for path '" + absolute_path.get() +
- "', and therefore it is not a symbolic link");
- }
-
- const Try<SharedHandle> symlink_handle =
- get_handle_no_follow(absolute_path.get());
-
- if (symlink_handle.isError()) {
- return Error(symlink_handle.error());
- }
-
- // Finally, retrieve symlink data for the handle, if any.
- return get_symbolic_link_data(symlink_handle.get().get_handle());
-}
-
-} // namespace windows {
-} // namespace internal {
-
-#endif // __STOUT_INTERNAL_WINDOWS_SYMLINK_HPP__
http://git-wip-us.apache.org/repos/asf/mesos/blob/c235f7c1/3rdparty/libprocess/3rdparty/stout/include/stout/interval.hpp
----------------------------------------------------------------------
diff --git a/3rdparty/libprocess/3rdparty/stout/include/stout/interval.hpp b/3rdparty/libprocess/3rdparty/stout/include/stout/interval.hpp
deleted file mode 100644
index e6deeac..0000000
--- a/3rdparty/libprocess/3rdparty/stout/include/stout/interval.hpp
+++ /dev/null
@@ -1,391 +0,0 @@
-// 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.
-// limitations under the License.
-
-#ifndef __STOUT_INTERVAL_HPP__
-#define __STOUT_INTERVAL_HPP__
-
-#include <functional> // For std::less.
-#include <iostream>
-
-#include <boost/icl/interval.hpp>
-#include <boost/icl/interval_set.hpp>
-
-
-// Forward declarations.
-template <typename T>
-class Interval;
-
-
-template <typename T>
-class IntervalSet;
-
-
-// Represents a bound (left or right) for an interval. A bound can
-// either be open or closed.
-template <typename T>
-class Bound
-{
-public:
- // Creates an open bound.
- static Bound<T> open(const T& value)
- {
- return Bound<T>(OPEN, value);
- }
-
- // Creates an closed bound.
- static Bound<T> closed(const T& value)
- {
- return Bound<T>(CLOSED, value);
- }
-
- // Intervals can be created using the comma operator. For example:
- // (2, 6): (Bound<int>::open(2), Bound<int>::open(6))
- // (3, 4]: (Bound<int>::open(3), Bound<int>::closed(4))
- // [0, 5): (Bound<int>::closed(0), Bound<int>::open(5))
- // [1, 2]: (Bound<int>::closed(1), Bound<int>::closed(2))
- Interval<T> operator , (const Bound<T>& right) const;
-
-private:
- enum Type
- {
- OPEN,
- CLOSED,
- };
-
- Bound(const Type _type, const T& _value)
- : type(_type), value(_value) {}
-
- const Type type;
- const T value;
-};
-
-
-// Represents an interval.
-template <typename T>
-class Interval
-{
-public:
- // We must provide a public default constructor as the boost
- // interval set expects that.
- Interval() {}
-
- // Returns the inclusive lower bound of this interval.
- T lower() const { return data.lower(); }
-
- // Returns the exclusive upper bound of this interval.
- T upper() const { return data.upper(); }
-
- // Checks if this interval intersects with another interval.
- bool intersects(const Interval<T>& interval) const;
-
- // Checks if this interval intersects with an interval set.
- bool intersects(const IntervalSet<T>& set) const;
-
- bool operator==(const Interval<T>& that) const
- {
- return data == that.data;
- }
-
- bool operator!=(const Interval<T>& that) const
- {
- return !(*this == that);
- }
-
-private:
- friend class Bound<T>;
-
- template <typename X>
- friend std::ostream& operator<<(
- std::ostream& stream,
- const Interval<X>& interval);
-
- Interval(const boost::icl::right_open_interval<T, std::less>& _data)
- : data(_data) {}
-
- // We store the interval in right open format: [lower, upper).
- // Notice that we use composition here instead of inheritance to
- // prevent Interval from being passed to bare boost icl containers.
- boost::icl::right_open_interval<T, std::less> data;
-};
-
-
-template <typename T>
-std::ostream& operator<<(std::ostream& stream, const Interval<T>& interval)
-{
- return stream << interval.data;
-}
-
-
-template <typename T>
-Interval<T> Bound<T>::operator , (const Bound<T>& right) const
-{
- if (type == OPEN) {
- if (right.type == OPEN) {
- // For example: (1, 3).
- return boost::icl::static_interval<
- boost::icl::right_open_interval<T, std::less>, // Target.
- boost::icl::is_discrete<T>::value,
- boost::icl::interval_bounds::static_open, // Input bounds.
- boost::icl::interval_bounds::static_right_open // Output bounds.
- >::construct(value, right.value);
- } else {
- // For example: (1, 3].
- return boost::icl::static_interval<
- boost::icl::right_open_interval<T, std::less>, // Target.
- boost::icl::is_discrete<T>::value,
- boost::icl::interval_bounds::static_left_open, // Input bounds.
- boost::icl::interval_bounds::static_right_open // Output bounds.
- >::construct(value, right.value);
- }
- } else {
- if (right.type == OPEN) {
- // For example: [1, 3).
- return boost::icl::static_interval<
- boost::icl::right_open_interval<T, std::less>, // Target.
- boost::icl::is_discrete<T>::value,
- boost::icl::interval_bounds::static_right_open, // Input bounds.
- boost::icl::interval_bounds::static_right_open // Output bounds.
- >::construct(value, right.value);
- } else {
- // For example: [1, 3].
- return boost::icl::static_interval<
- boost::icl::right_open_interval<T, std::less>, // Target.
- boost::icl::is_discrete<T>::value,
- boost::icl::interval_bounds::static_closed, // Input bounds.
- boost::icl::interval_bounds::static_right_open // Output bounds.
- >::construct(value, right.value);
- }
- }
-}
-
-
-// Modeled after boost interval_set. Provides a compact representation
-// of a set by merging adjacent elements into intervals.
-template <typename T>
-class IntervalSet : public boost::icl::interval_set<T, std::less, Interval<T> >
-{
-public:
- IntervalSet() {}
-
- explicit IntervalSet(const T& value)
- {
- Base::add(value);
- }
-
- explicit IntervalSet(const Interval<T>& interval)
- {
- Base::add(interval);
- }
-
- IntervalSet(const Bound<T>& lower, const Bound<T>& upper)
- {
- Base::add((lower, upper));
- }
-
- // Checks if an element is in this set.
- bool contains(const T& value) const
- {
- return boost::icl::contains(static_cast<const Base&>(*this), value);
- }
-
- // Checks if an interval is in this set.
- bool contains(const Interval<T>& interval) const
- {
- // TODO(jieyu): Boost has an issue regarding unqualified lookup in
- // template (http://clang.llvm.org/compatibility.html#dep_lookup),
- // and gcc-4.8 complains about it. We use a workaround here by
- // delegating this call to the IntervalSet version below.
- return contains(IntervalSet<T>(interval));
- }
-
- // Checks if an interval set is a subset of this set.
- bool contains(const IntervalSet<T>& set) const
- {
- return boost::icl::contains(
- static_cast<const Base&>(*this),
- static_cast<const Base&>(set));
- }
-
- // Checks if this set intersects with an interval.
- bool intersects(const Interval<T>& interval) const
- {
- return boost::icl::intersects(static_cast<const Base&>(*this), interval);
- }
-
- // Checks if this set intersects with another interval set.
- bool intersects(const IntervalSet<T>& set) const
- {
- return boost::icl::intersects(
- static_cast<const Base&>(*this),
- static_cast<const Base&>(set));
- }
-
- // Returns the number of intervals in this set.
- size_t intervalCount() const
- {
- return boost::icl::interval_count(static_cast<const Base&>(*this));
- }
-
- // Overloaded operators.
- bool operator==(const IntervalSet<T>& that) const
- {
- return static_cast<const Base&>(*this) == static_cast<const Base&>(that);
- }
-
- bool operator!=(const IntervalSet<T>& that) const
- {
- return !(*this == that);
- }
-
- IntervalSet<T>& operator+=(const T& value)
- {
- static_cast<Base&>(*this) += value;
- return *this;
- }
-
- IntervalSet<T>& operator+=(const Interval<T>& interval)
- {
- static_cast<Base&>(*this) += interval;
- return *this;
- }
-
- IntervalSet<T>& operator+=(const IntervalSet<T>& set)
- {
- static_cast<Base&>(*this) += static_cast<const Base&>(set);
- return *this;
- }
-
- IntervalSet<T>& operator-=(const T& value)
- {
- static_cast<Base&>(*this) -= value;
- return *this;
- }
-
- IntervalSet<T>& operator-=(const Interval<T>& interval)
- {
- static_cast<Base&>(*this) -= interval;
- return *this;
- }
-
- IntervalSet<T>& operator-=(const IntervalSet<T>& set)
- {
- static_cast<Base&>(*this) -= static_cast<const Base&>(set);
- return *this;
- }
-
- IntervalSet<T>& operator&=(const T& value)
- {
- static_cast<Base&>(*this) &= value;
- return *this;
- }
-
- IntervalSet<T>& operator&=(const Interval<T>& interval)
- {
- static_cast<Base&>(*this) &= interval;
- return *this;
- }
-
- IntervalSet<T>& operator&=(const IntervalSet<T>& set)
- {
- static_cast<Base&>(*this) &= static_cast<const Base&>(set);
- return *this;
- }
-
-private:
- template <typename X>
- friend std::ostream& operator<<(
- std::ostream& stream,
- const IntervalSet<X>& set);
-
- // We use typedef here to make the code less verbose.
- typedef boost::icl::interval_set<T, std::less, Interval<T> > Base;
-};
-
-
-template <typename T>
-std::ostream& operator<<(std::ostream& stream, const IntervalSet<T>& set)
-{
- return stream << static_cast<const typename IntervalSet<T>::Base&>(set);
-}
-
-
-template <typename T>
-bool Interval<T>::intersects(const Interval<T>& interval) const
-{
- return IntervalSet<T>(*this).intersects(interval);
-}
-
-
-template <typename T>
-bool Interval<T>::intersects(const IntervalSet<T>& set) const
-{
- return set.intersects(*this);
-}
-
-
-template <typename T, typename X>
-IntervalSet<T> operator+(const IntervalSet<T>& set, const X& x)
-{
- IntervalSet<T> result(set);
- result += x;
- return result;
-}
-
-
-template <typename T, typename X>
-IntervalSet<T> operator-(const IntervalSet<T>& set, const X& x)
-{
- IntervalSet<T> result(set);
- result -= x;
- return result;
-}
-
-
-// Defines type traits for the custom Interval above. These type
-// traits are required by the boost interval set.
-namespace boost {
-namespace icl {
-
-template <typename T>
-struct interval_traits<Interval<T> >
-{
- typedef interval_traits type;
- typedef T domain_type;
- typedef std::less<T> domain_compare;
-
- static Interval<T> construct(const T& lower, const T& upper)
- {
- return (Bound<T>::closed(lower), Bound<T>::open(upper));
- }
-
- static T lower(const Interval<T>& interval)
- {
- return interval.lower();
- }
-
- static T upper(const Interval<T>& interval)
- {
- return interval.upper();
- }
-};
-
-
-template <typename T>
-struct interval_bound_type<Interval<T> >
- : public interval_bound_type<right_open_interval<T, std::less> >
-{
- typedef interval_bound_type type;
-};
-
-} // namespace icl {
-} // namespace boost {
-
-#endif // __STOUT_INTERVAL_HPP__
http://git-wip-us.apache.org/repos/asf/mesos/blob/c235f7c1/3rdparty/libprocess/3rdparty/stout/include/stout/ip.hpp
----------------------------------------------------------------------
diff --git a/3rdparty/libprocess/3rdparty/stout/include/stout/ip.hpp b/3rdparty/libprocess/3rdparty/stout/include/stout/ip.hpp
deleted file mode 100644
index ffeb2d7..0000000
--- a/3rdparty/libprocess/3rdparty/stout/include/stout/ip.hpp
+++ /dev/null
@@ -1,528 +0,0 @@
-// 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 __STOUT_IP_HPP__
-#define __STOUT_IP_HPP__
-
-// For 'sockaddr'.
-#ifndef __WINDOWS__
-#include <arpa/inet.h>
-#endif // __WINDOWS__
-
-#if defined(__linux__) || defined(__APPLE__) || defined(__FreeBSD__)
-#include <ifaddrs.h>
-#endif // __linux__ || __APPLE__ || __FreeBSD__
-#include <stdint.h>
-#include <stdio.h>
-#include <string.h>
-
-#ifdef __APPLE__
-#include <net/if.h>
-#include <net/if_dl.h>
-#include <net/if_types.h>
-#endif // __APPLE__
-
-// Note: Header grouping and ordering is considered before
-// inclusion/exclusion by platform.
-// For 'inet_pton', 'inet_ntop'.
-#ifdef __WINDOWS__
-#include <Ws2tcpip.h>
-#else
-#include <netinet/in.h>
-#include <sys/socket.h>
-#endif // __WINDOWS__
-
-#include <sys/types.h>
-
-#include <iostream>
-#include <string>
-#include <vector>
-
-#include <boost/functional/hash.hpp>
-
-#include <stout/abort.hpp>
-#include <stout/bits.hpp>
-#include <stout/error.hpp>
-#include <stout/none.hpp>
-#include <stout/numify.hpp>
-#include <stout/option.hpp>
-#include <stout/os/strerror.hpp>
-#include <stout/result.hpp>
-#include <stout/stringify.hpp>
-#include <stout/strings.hpp>
-#include <stout/try.hpp>
-#include <stout/unreachable.hpp>
-
-#ifdef __WINDOWS__
-#include <stout/windows.hpp>
-#endif // __WINDOWS__
-
-
-namespace net {
-
-// Represents an IP.
-class IP
-{
-public:
- // Creates an IP from the given string that has the dot-decimal
- // format. For example:
- // 10.0.0.1
- // 192.168.1.100
- // 172.158.1.23
- static Try<IP> parse(const std::string& value, int family);
-
- // Creates an IP from a struct sockaddr_storage.
- static Try<IP> create(const struct sockaddr_storage& _storage);
-
- // Creates an IP from a struct sockaddr.
- static Try<IP> create(const struct sockaddr& _storage);
-
- // Creates an IP from struct in_addr. Note that by standard, struct
- // in_addr stores the IP address in network order.
- explicit IP(const struct in_addr& _storage)
- : family_(AF_INET)
- {
- clear();
- storage_.in_ = _storage;
- }
-
- // Creates an IP from a 32 bit unsigned integer. Note that the
- // integer stores the IP address in host order.
- explicit IP(uint32_t _storage)
- : family_(AF_INET)
- {
- clear();
- storage_.in_.s_addr = htonl(_storage);
- }
-
- // Returns the family type.
- int family() const
- {
- return family_;
- }
-
- // Returns the struct in_addr storage.
- Try<struct in_addr> in() const
- {
- if (family_ == AF_INET) {
- return storage_.in_;
- } else {
- return Error("Unsupported family type: " + stringify(family_));
- }
- }
-
- // Checks if this IP is for loopback (e.g., INADDR_LOOPBACK).
- bool isLoopback() const
- {
- switch (family_) {
- case AF_INET:
- return storage_.in_.s_addr == htonl(INADDR_LOOPBACK);
- default:
- UNREACHABLE();
- }
- }
-
- // Checks if this IP is for any incoming address (e.g., INADDR_ANY).
- bool isAny() const
- {
- switch (family_) {
- case AF_INET:
- return storage_.in_.s_addr == htonl(INADDR_ANY);
- default:
- UNREACHABLE();
- }
- }
-
- bool operator==(const IP& that) const
- {
- if (family_ != that.family_) {
- return false;
- } else {
- return memcmp(&storage_, &that.storage_, sizeof(storage_)) == 0;
- }
- }
-
- bool operator!=(const IP& that) const
- {
- return !(*this == that);
- }
-
- bool operator<(const IP& that) const
- {
- if (family_ != that.family_) {
- return family_ < that.family_;
- } else {
- return memcmp(&storage_, &that.storage_, sizeof(storage_)) < 0;
- }
- }
-
- bool operator>(const IP& that) const
- {
- if (family_ != that.family_) {
- return family_ > that.family_;
- } else {
- return memcmp(&storage_, &that.storage_, sizeof(storage_)) > 0;
- }
- }
-
-private:
- // NOTE: We need to clear the union when creating an IP because the
- // equality check uses memcmp.
- void clear()
- {
- memset(&storage_, 0, sizeof(storage_));
- }
-
- union Storage
- {
- struct in_addr in_;
- };
-
- int family_;
- Storage storage_;
-};
-
-
-inline Try<IP> IP::parse(const std::string& value, int family)
-{
- Storage storage;
- switch (family) {
- case AF_INET: {
- if (inet_pton(AF_INET, value.c_str(), &storage.in_) == 0) {
- return Error("Failed to parse the IP");
- }
- return IP(storage.in_);
- }
- default: {
- return Error("Unsupported family type: " + stringify(family));
- }
- }
-}
-
-
-inline Try<IP> IP::create(const struct sockaddr_storage& _storage)
-{
- // According to POSIX: (IEEE Std 1003.1, 2004)
- //
- // (1) `sockaddr_storage` is "aligned at an appropriate boundary so that
- // pointers to it can be cast as pointers to protocol-specific address
- // structures and used to access the fields of those structures without
- // alignment problems."
- //
- // (2) "When a `sockaddr_storage` structure is cast as a `sockaddr`
- // structure, the `ss_family` field of the `sockaddr_storage` structure
- // shall map onto the `sa_family` field of the `sockaddr` structure."
- //
- // Therefore, casting from `const sockaddr_storage*` to `const sockaddr*`
- // (then subsequently dereferencing the `const sockaddr*`) should be safe.
- // Note that casting in the reverse direction (`const sockaddr*` to
- // `const sockaddr_storage*`) would NOT be safe, since the former might
- // not be aligned appropriately.
- const auto* addr = reinterpret_cast<const struct sockaddr*>(&_storage);
- return create(*addr);
-}
-
-
-inline Try<IP> IP::create(const struct sockaddr& _storage)
-{
- switch (_storage.sa_family) {
- case AF_INET: {
- const auto* addr = reinterpret_cast<const struct sockaddr_in*>(&_storage);
- return IP(addr->sin_addr);
- }
- default: {
- return Error("Unsupported family type: " + stringify(_storage.sa_family));
- }
- }
-}
-
-
-// Returns the string representation of the given IP using the
-// canonical dot-decimal form. For example: "10.0.0.1".
-inline std::ostream& operator<<(std::ostream& stream, const IP& ip)
-{
- switch (ip.family()) {
- case AF_INET: {
- char buffer[INET_ADDRSTRLEN];
- struct in_addr in = ip.in().get();
- if (inet_ntop(AF_INET, &in, buffer, sizeof(buffer)) == NULL) {
- // We do not expect inet_ntop to fail because all parameters
- // passed in are valid.
- ABORT("Failed to get human-readable IP for " +
- stringify(ntohl(in.s_addr)) + ": " + os::strerror(errno));
- }
-
- stream << buffer;
- return stream;
- }
- default: {
- UNREACHABLE();
- }
- }
-}
-
-
-// Represents an IP network. We store the IP address and the IP
-// netmask which defines the subnet.
-class IPNetwork
-{
-public:
- // Returns the IPv4 network for loopback (i.e., 127.0.0.1/8).
- static IPNetwork LOOPBACK_V4();
-
- // Creates an IP network from the given string that has the
- // dot-decimal format with subnet prefix).
- // For example:
- // 10.0.0.1/8
- // 192.168.1.100/24
- // 172.158.1.23
- static Try<IPNetwork> parse(const std::string& value, int family);
-
- // Creates an IP network from the given IP address and netmask.
- // Returns error if the netmask is not valid (e.g., not contiguous).
- static Try<IPNetwork> create(const IP& address, const IP& netmask);
-
- // Creates an IP network from an IP address and a subnet prefix.
- // Returns error if the prefix is not valid.
- static Try<IPNetwork> create(const IP& address, int prefix);
-
- // Returns the first available IP network of a given link device.
- // The link device is specified using its name (e.g., eth0). Returns
- // error if the link device is not found. Returns none if the link
- // device is found, but does not have an IP network.
- // TODO(jieyu): It is uncommon, but likely that a link device has
- // multiple IP networks. In that case, consider returning the
- // primary IP network instead of the first one.
- static Result<IPNetwork> fromLinkDevice(const std::string& name, int family);
-
- IP address() const { return address_; }
-
- IP netmask() const { return netmask_; }
-
- // Returns the prefix of the subnet defined by the IP netmask.
- int prefix() const
- {
- switch (netmask_.family()) {
- case AF_INET: {
- return bits::countSetBits(ntohl(netmask_.in().get().s_addr));
- }
- default: {
- UNREACHABLE();
- }
- }
- }
-
- bool operator==(const IPNetwork& that) const
- {
- return address_ == that.address_ && netmask_ == that.netmask_;
- }
-
- bool operator!=(const IPNetwork& that) const
- {
- return !(*this == that);
- }
-
-private:
- IPNetwork(const IP& _address, const IP& _netmask)
- : address_(_address), netmask_(_netmask) {}
-
- IP address_;
- IP netmask_;
-};
-
-
-inline Try<IPNetwork> IPNetwork::parse(const std::string& value, int family)
-{
- std::vector<std::string> tokens = strings::split(value, "/");
-
- if (tokens.size() != 2) {
- return Error(
- "Unexpected number of '/' detected: " +
- stringify(tokens.size()));
- }
-
- // Parse the IP address.
- Try<IP> address = IP::parse(tokens[0], family);
- if (address.isError()) {
- return Error("Failed to parse the IP address: " + address.error());
- }
-
- // Parse the subnet prefix.
- Try<int> prefix = numify<int>(tokens[1]);
- if (prefix.isError()) {
- return Error("Subnet prefix is not a number");
- }
-
- return create(address.get(), prefix.get());
-}
-
-
-inline IPNetwork IPNetwork::LOOPBACK_V4()
-{
- return parse("127.0.0.1/8", AF_INET).get();
-}
-
-
-inline Try<IPNetwork> IPNetwork::create(const IP& address, const IP& netmask)
-{
- if (address.family() != netmask.family()) {
- return Error(
- "The network families of the IP address '" +
- stringify(address.family()) + "' and the IP netmask '" +
- stringify(netmask.family()) + "' do not match");
- }
-
- switch (address.family()) {
- case AF_INET: {
- uint32_t mask = ntohl(netmask.in().get().s_addr);
- if (((~mask + 1) & (~mask)) != 0) {
- return Error("Netmask is not valid");
- }
-
- return IPNetwork(address, netmask);
- }
- default: {
- UNREACHABLE();
- }
- }
-}
-
-
-inline Try<IPNetwork> IPNetwork::create(const IP& address, int prefix)
-{
- if (prefix < 0) {
- return Error("Subnet prefix is negative");
- }
-
- switch (address.family()) {
- case AF_INET: {
- if (prefix > 32) {
- return Error("Subnet prefix is larger than 32");
- }
-
- // Avoid left-shifting by 32 bits when prefix is 0.
- uint32_t mask = 0;
- if (prefix > 0) {
- mask = 0xffffffff << (32 - prefix);
- }
- return IPNetwork(address, IP(mask));
- }
- default: {
- UNREACHABLE();
- }
- }
-}
-
-
-inline Result<IPNetwork> IPNetwork::fromLinkDevice(
- const std::string& name,
- int family)
-{
-#if !defined(__linux__) && !defined(__APPLE__) && !defined(__FreeBSD__)
- return Error("Not implemented");
-#else
- if (family != AF_INET) {
- return Error("Unsupported family type: " + stringify(family));
- }
-
- struct ifaddrs* ifaddr = NULL;
- if (getifaddrs(&ifaddr) == -1) {
- return ErrnoError();
- }
-
- // Indicates whether the link device is found or not.
- bool found = false;
-
- for (struct ifaddrs* ifa = ifaddr; ifa != NULL; ifa = ifa->ifa_next) {
- if (ifa->ifa_name != NULL && !strcmp(ifa->ifa_name, name.c_str())) {
- found = true;
-
- if (ifa->ifa_addr != NULL && ifa->ifa_addr->sa_family == family) {
- IP address = IP::create(*ifa->ifa_addr).get();
-
- if (ifa->ifa_netmask != NULL &&
- ifa->ifa_netmask->sa_family == family) {
- IP netmask = IP::create(*ifa->ifa_netmask).get();
-
- freeifaddrs(ifaddr);
-
- Try<IPNetwork> network = IPNetwork::create(address, netmask);
- if (network.isError()) {
- return Error(network.error());
- }
-
- return network.get();
- }
-
- freeifaddrs(ifaddr);
-
- // Note that this is the case where netmask is not specified.
- // We've seen such cases when VPN is used. In that case, a
- // default /32 prefix is used.
- Try<IPNetwork> network = IPNetwork::create(address, 32);
- if (network.isError()) {
- return Error(network.error());
- }
-
- return network.get();
- }
- }
- }
-
- freeifaddrs(ifaddr);
-
- if (!found) {
- return Error("Cannot find the link device");
- }
-
- return None();
-#endif
-}
-
-
-// Returns the string representation of the given IP network using the
-// canonical dot-decimal form with prefix. For example: "10.0.0.1/8".
-inline std::ostream& operator<<(std::ostream& stream, const IPNetwork& network)
-{
- stream << network.address() << "/" << network.prefix();
-
- return stream;
-}
-
-} // namespace net {
-
-namespace std {
-
-template <>
-struct hash<net::IP>
-{
- typedef size_t result_type;
-
- typedef net::IP argument_type;
-
- result_type operator()(const argument_type& ip) const
- {
- size_t seed = 0;
-
- switch (ip.family()) {
- case AF_INET:
- boost::hash_combine(seed, htonl(ip.in().get().s_addr));
- return seed;
- default:
- UNREACHABLE();
- }
- }
-};
-
-} // namespace std {
-
-#endif // __STOUT_IP_HPP__
http://git-wip-us.apache.org/repos/asf/mesos/blob/c235f7c1/3rdparty/libprocess/3rdparty/stout/include/stout/json.hpp
----------------------------------------------------------------------
diff --git a/3rdparty/libprocess/3rdparty/stout/include/stout/json.hpp b/3rdparty/libprocess/3rdparty/stout/include/stout/json.hpp
deleted file mode 100644
index a1740a9..0000000
--- a/3rdparty/libprocess/3rdparty/stout/include/stout/json.hpp
+++ /dev/null
@@ -1,820 +0,0 @@
-// 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 __STOUT_JSON__
-#define __STOUT_JSON__
-
-// NOTE: This undef is necessary because we cannot reliably re-order the
-// include statements in all cases. We define this flag globally since
-// PicoJson requires it before importing <inttypes.h>. However, other
-// libraries may import <inttypes.h> before we import <picojson.h>.
-// Hence, we undefine the flag here to prevent the redefinition error.
-#undef __STDC_FORMAT_MACROS
-#include <picojson.h>
-#define __STDC_FORMAT_MACROS
-
-#include <iomanip>
-#include <iostream>
-#include <limits>
-#include <map>
-#include <string>
-#include <type_traits>
-#include <vector>
-
-#include <boost/type_traits/is_arithmetic.hpp>
-#include <boost/utility/enable_if.hpp>
-#include <boost/variant.hpp>
-
-#include <stout/check.hpp>
-#include <stout/foreach.hpp>
-#include <stout/numify.hpp>
-#include <stout/result.hpp>
-#include <stout/strings.hpp>
-#include <stout/try.hpp>
-#include <stout/unreachable.hpp>
-
-namespace JSON {
-
-// Implementation of the JavaScript Object Notation (JSON) grammar
-// using boost::variant. We explicitly define each "type" of the
-// grammar, including 'true' (json::True), 'false' (json::False), and
-// 'null' (json::Null), for clarity and also because boost::variant
-// "picks" the wrong type when we try and use std::string, long (or
-// int), double (or float), and bool all in the same variant (while it
-// does work with explicit casts, it seemed bad style to force people
-// to put those casts in place). We could have avoided using
-// json::String or json::Number and just used std::string and double
-// respectively, but we choose to include them for completeness
-// (although, this does pay a 2x cost when compiling thanks to all the
-// extra template instantiations).
-
-// Note that all of these forward declarations are not necessary
-// but it serves to document the set of types which are available.
-struct String;
-struct Number;
-struct Object;
-struct Array;
-struct True;
-struct False;
-struct Boolean;
-struct Null;
-struct Value;
-
-
-struct String
-{
- String() {}
- String(const char* _value) : value(_value) {}
- String(const std::string& _value) : value(_value) {}
- std::string value;
-};
-
-
-// NOTE: Due to how PicoJson parses unsigned integers, a roundtrip from Number
-// to JSON and back to Number will result in:
-// - a signed integer, if the value is less than or equal to INT64_MAX;
-// - or a double, if the value is greater than INT64_MAX.
-// See: https://github.com/kazuho/picojson/blob/rel/v1.3.0/picojson.h#L777-L781
-struct Number
-{
- Number() : value(0) {}
-
- template <typename T>
- Number(
- T _value,
- typename std::enable_if<std::is_floating_point<T>::value, int>::type = 0)
- : type(FLOATING), value(_value) {}
-
- template <typename T>
- Number(
- T _value,
- typename std::enable_if<
- std::is_integral<T>::value && std::is_signed<T>::value,
- int>::type = 0)
- : type(SIGNED_INTEGER), signed_integer(_value) {}
-
- template <typename T>
- Number(
- T _value,
- typename std::enable_if<
- std::is_integral<T>::value && std::is_unsigned<T>::value,
- int>::type = 0)
- : type(UNSIGNED_INTEGER), unsigned_integer(_value) {}
-
- template <typename T>
- T as() const
- {
- switch (type) {
- case FLOATING:
- return static_cast<T>(value);
- case SIGNED_INTEGER:
- return static_cast<T>(signed_integer);
- case UNSIGNED_INTEGER:
- return static_cast<T>(unsigned_integer);
-
- // NOTE: By not setting a default we leverage the compiler
- // errors when the enumeration is augmented to find all
- // the cases we need to provide.
- }
-
- UNREACHABLE();
- }
-
- enum Type
- {
- FLOATING,
- SIGNED_INTEGER,
- UNSIGNED_INTEGER,
- } type;
-
-private:
- friend struct Value;
- friend struct Comparator;
- friend std::ostream& operator<<(std::ostream& stream, const Number& number);
-
- union {
- double value;
- int64_t signed_integer;
- uint64_t unsigned_integer;
- };
-};
-
-
-struct Object
-{
- // Returns the JSON value (specified by the type) given a "path"
- // into the structure, for example:
- //
- // Result<JSON::Array> array = object.find<JSON::Array>("nested.array[0]");
- //
- // Will return 'None' if no field could be found called 'array'
- // within a field called 'nested' of 'object' (where 'nested' must
- // also be a JSON object).
- //
- // Returns an error if a JSON value of the wrong type is found, or
- // an intermediate JSON value is not an object that we can do a
- // recursive find on.
- template <typename T>
- Result<T> find(const std::string& path) const;
-
- // Returns the JSON value by indexing this object with the key. Unlike
- // find(), the key is not a path into the JSON structure, it is just
- // a JSON object key name.
- //
- // Returns 'None' if there key doesn't exist, or an error if a JSON
- // value of the wrong type is found.
- template <typename T>
- Result<T> at(const std::string& key) const;
-
- std::map<std::string, Value> values;
-};
-
-
-struct Array
-{
- std::vector<Value> values;
-};
-
-
-struct Boolean
-{
- Boolean() : value(false) {}
- Boolean(bool _value) : value(_value) {}
- bool value;
-};
-
-
-// This is a helper so you can say JSON::True() instead of
-// JSON::Boolean(true).
-struct True : Boolean
-{
- True() : Boolean(true) {}
-};
-
-
-// This is a helper so you can say JSON::False() instead of
-// JSON::Boolean(false).
-struct False : Boolean
-{
- False() : Boolean(false) {}
-};
-
-
-struct Null {};
-
-
-namespace internal {
-
-// Only Object and Array require recursive_wrapper, not sure
-// if there is a reason to wrap the others or not.
-// Null needs to be first so that it is the default value.
-typedef boost::variant<boost::recursive_wrapper<Null>,
- boost::recursive_wrapper<String>,
- boost::recursive_wrapper<Number>,
- boost::recursive_wrapper<Object>,
- boost::recursive_wrapper<Array>,
- boost::recursive_wrapper<Boolean> > Variant;
-
-} // namespace internal {
-
-
-struct Value : internal::Variant
-{
- // Empty constructor gets the variant default.
- Value() {}
-
- Value(bool value) : internal::Variant(JSON::Boolean(value)) {}
-
- Value(char* value) : internal::Variant(JSON::String(value)) {}
- Value(const char* value) : internal::Variant(JSON::String(value)) {}
-
- // Arithmetic types are specifically routed through Number because
- // there would be ambiguity between JSON::Bool and JSON::Number
- // otherwise.
- template <typename T>
- Value(
- const T& value,
- typename boost::enable_if<boost::is_arithmetic<T>, int>::type = 0)
- : internal::Variant(Number(value)) {}
-
- // Non-arithmetic types are passed to the default constructor of
- // Variant.
- template <typename T>
- Value(
- const T& value,
- typename boost::disable_if<boost::is_arithmetic<T>, int>::type = 0)
- : internal::Variant(value) {}
-
- template <typename T>
- bool is() const;
-
- template <typename T>
- const T& as() const;
-
- // Returns true if and only if 'other' is contained by 'this'.
- // 'Other' is contained by 'this' if the following conditions are
- // fulfilled:
- // 1. If 'other' is a JSON object, then 'this' is also a JSON
- // object, all keys of 'other' are also present in 'this' and
- // the value for each key in 'this' also contain the value for
- // the same key in 'other', i.e. for all keys 'k' in 'other',
- // 'this[k].contains(other[k])' is true.
- // 2. If 'other' is a JSON array, 'this' is also a JSON array, the
- // length of both arrays is the same and each element in 'this'
- // also contains the element in 'other' at the same position,
- // i.e. it holds that this.length() == other.length() and
- // for each i, 0 <= i < this.length,
- // 'this[i].contains(other[i])'.
- // 3. For all other types, 'this' is of the same type as 'other' and
- // 'this == other'.
- // NOTE: For a given key 'k', if 'this[k] == null' then
- // 'this.contains(other)' holds if either 'k' is not present in
- // 'other.keys()' or 'other[k] == null'.
- // Similarly, if 'other[k] == null', 'this.contains(other)' only if
- // 'this[k] == null'. This is a consequence of the containment
- // definition.
- bool contains(const Value& other) const;
-
-private:
- friend struct Comparator;
-
- // A class which follows the visitor pattern and implements the
- // containment rules described in the documentation of 'contains'.
- // See 'bool Value::contains(const Value& other) const'.
- struct ContainmentComparator : public boost::static_visitor<bool>
- {
- explicit ContainmentComparator(const Value& _self)
- : self(_self) {}
-
- bool operator()(const Object& other) const;
- bool operator()(const Array& other) const;
- bool operator()(const String& other) const;
- bool operator()(const Number& other) const;
- bool operator()(const Boolean& other) const;
- bool operator()(const Null&) const;
-
- private:
- const Value& self;
- };
-};
-
-
-template <typename T>
-bool Value::is() const
-{
- const T* t = boost::get<T>(this);
- return t != NULL;
-}
-
-
-template <>
-inline bool Value::is<Value>() const
-{
- return true;
-}
-
-
-template <typename T>
-const T& Value::as() const
-{
- return *CHECK_NOTNULL(boost::get<T>(this));
-}
-
-
-template <>
-inline const Value& Value::as<Value>() const
-{
- return *this;
-}
-
-
-template <typename T>
-Result<T> Object::find(const std::string& path) const
-{
- const std::vector<std::string> names = strings::split(path, ".", 2);
-
- if (names.empty()) {
- return None();
- }
-
- std::string name = names[0];
-
- // Determine if we have an array subscript. If so, save it but
- // remove it from the name for doing the lookup.
- Option<size_t> subscript = None();
- size_t index = name.find('[');
- if (index != std::string::npos) {
- // Check for the closing bracket.
- if (name.at(name.length() - 1) != ']') {
- return Error("Malformed array subscript, expecting ']'");
- }
-
- // Now remove the closing bracket (last character) and everything
- // before and including the opening bracket.
- std::string s = name.substr(index + 1, name.length() - index - 2);
-
- // Now numify the subscript.
- Try<int> i = numify<int>(s);
-
- if (i.isError()) {
- return Error("Failed to numify array subscript '" + s + "'");
- } else if (i.get() < 0) {
- return Error("Array subscript '" + s + "' must be >= 0");
- }
-
- subscript = i.get();
-
- // And finally remove the array subscript from the name.
- name = name.substr(0, index);
- }
-
- std::map<std::string, Value>::const_iterator entry = values.find(name);
-
- if (entry == values.end()) {
- return None();
- }
-
- Value value = entry->second;
-
- if (value.is<Array>() && subscript.isSome()) {
- Array array = value.as<Array>();
- if (subscript.get() >= array.values.size()) {
- return None();
- }
- value = array.values[subscript.get()];
- }
-
- if (names.size() == 1) {
- if (!value.is<T>()) {
- // TODO(benh): Use a visitor to print out the type found.
- return Error("Found JSON value of wrong type");
- }
- return value.as<T>();
- } else if (!value.is<Object>()) {
- // TODO(benh): Use a visitor to print out the intermediate type.
- return Error("Intermediate JSON value not an object");
- }
-
- return value.as<Object>().find<T>(names[1]);
-}
-
-
-template <typename T>
-Result<T> Object::at(const std::string& key) const
-{
- if (key.empty()) {
- return None();
- }
-
- std::map<std::string, Value>::const_iterator entry = values.find(key);
-
- if (entry == values.end()) {
- return None();
- }
-
- Value value = entry->second;
-
- if (!value.is<T>()) {
- // TODO(benh): Use a visitor to print out the type found.
- return Error("Found JSON value of wrong type");
- }
-
- return value.as<T>();
-}
-
-
-inline bool Value::contains(const Value& other) const
-{
- return boost::apply_visitor(Value::ContainmentComparator(*this), other);
-}
-
-
-inline bool Value::ContainmentComparator::operator()(const Object& other) const
-{
- if (!self.is<Object>()) {
- return false;
- }
-
- // The empty set is contained in every set.
- if (other.values.empty()) {
- return true;
- }
-
- const Object& _self = self.as<Object>();
-
- // All entries in 'other' should exists in 'self', which implies
- // there should be at most as many entries in other as in self.
- if (other.values.size() > _self.values.size()) {
- return false;
- }
-
- foreachpair (const std::string& key, const Value& value, other.values) {
- auto _selfIterator = _self.values.find(key);
-
- if (_selfIterator == _self.values.end()) {
- return false;
- }
-
- if (!_selfIterator->second.contains(value)) {
- return false;
- }
- }
-
- return true;
-}
-
-
-inline bool Value::ContainmentComparator::operator()(const String& other) const
-{
- if (!self.is<String>()) {
- return false;
- }
- return self.as<String>().value == other.value;
-}
-
-
-inline bool Value::ContainmentComparator::operator()(const Number& other) const
-{
- if (!self.is<Number>()) {
- return false;
- }
-
- // NOTE: For the following switch statements, we do not set a default
- // case in order to leverage the compiler errors when the enumeration
- // is augmented to find all the cases we need to provide.
-
- // NOTE: Using '==' is unsafe for unsigned-signed integer comparisons.
- // The compiler will automatically cast the signed integer to an
- // unsigned integer. i.e. If the signed integer was negative, it
- // might be converted to a large positive number.
- // Using the '==' operator *is* safe for double-integer comparisons.
-
- const Number& number = self.as<Number>();
- switch (number.type) {
- case Number::FLOATING:
- switch (other.type) {
- case Number::FLOATING:
- return number.value == other.value;
- case Number::SIGNED_INTEGER:
- return number.value == other.signed_integer;
- case Number::UNSIGNED_INTEGER:
- return number.value == other.unsigned_integer;
- }
-
- case Number::SIGNED_INTEGER:
- switch (other.type) {
- case Number::FLOATING:
- return number.signed_integer == other.value;
- case Number::SIGNED_INTEGER:
- return number.signed_integer == other.signed_integer;
- case Number::UNSIGNED_INTEGER:
- // See note above for why this is not a simple '==' expression.
- return number.signed_integer >= 0 &&
- number.as<uint64_t>() == other.unsigned_integer;
- }
-
- case Number::UNSIGNED_INTEGER:
- switch (other.type) {
- case Number::FLOATING:
- return number.unsigned_integer == other.value;
- case Number::SIGNED_INTEGER:
- // See note above for why this is not a simple '==' expression.
- return other.signed_integer >= 0 &&
- number.unsigned_integer == other.as<uint64_t>();
- case Number::UNSIGNED_INTEGER:
- return number.unsigned_integer == other.unsigned_integer;
- }
- }
-
- UNREACHABLE();
-}
-
-
-inline bool Value::ContainmentComparator::operator()(const Array& other) const
-{
- if (!self.is<Array>()) {
- return false;
- }
-
- const Array& _self = self.as<Array>();
-
- if (_self.values.size() != other.values.size()) {
- return false;
- }
-
- for (unsigned i = 0; i < other.values.size(); ++i) {
- if (!_self.values[i].contains(other.values[i])) {
- return false;
- }
- }
-
- return true;
-}
-
-
-inline bool Value::ContainmentComparator::operator()(const Boolean& other) const
-{
- if (!self.is<Boolean>()) {
- return false;
- }
- return self.as<Boolean>().value == other.value;
-}
-
-
-inline bool Value::ContainmentComparator::operator()(const Null&) const
-{
- return self.is<Null>();
-}
-
-
-struct Comparator : boost::static_visitor<bool>
-{
- Comparator(const Value& _value)
- : value(_value) {}
-
- bool operator()(const Object& object) const
- {
- if (value.is<Object>()) {
- return value.as<Object>().values == object.values;
- }
- return false;
- }
-
- bool operator()(const String& string) const
- {
- if (value.is<String>()) {
- return value.as<String>().value == string.value;
- }
- return false;
- }
-
- bool operator()(const Number& other) const
- {
- // Delegate to the containment comparator.
- // See Value::ContainmentComparator::operator(Number).
- return Value::ContainmentComparator(value)(other);
- }
-
- bool operator()(const Array& array) const
- {
- if (value.is<Array>()) {
- return value.as<Array>().values == array.values;
- }
- return false;
- }
-
- bool operator()(const Boolean& boolean) const
- {
- if (value.is<Boolean>()) {
- return value.as<Boolean>().value == boolean.value;
- }
- return false;
- }
-
- bool operator()(const Null&) const
- {
- return value.is<Null>();
- }
-
-private:
- const Value& value;
-};
-
-
-inline bool operator==(const Value& lhs, const Value& rhs)
-{
- return boost::apply_visitor(Comparator(lhs), rhs);
-}
-
-
-inline bool operator!=(const Value& lhs, const Value& rhs)
-{
- return !(lhs == rhs);
-}
-
-
-inline std::ostream& operator<<(std::ostream& out, const String& string)
-{
- // TODO(benh): This escaping DOES NOT handle unicode, it encodes as ASCII.
- // See RFC4627 for the JSON string specificiation.
- return out << picojson::value(string.value).serialize();
-}
-
-
-inline std::ostream& operator<<(std::ostream& out, const Number& number)
-{
- switch (number.type) {
- case Number::FLOATING: {
- // Prints a floating point value, with the specified precision, see:
- // http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2006/n2005.pdf
- // Additionally ensures that a decimal point is in the output.
- char buffer[50] {}; // More than long enough for the specified precision.
- snprintf(
- buffer,
- sizeof(buffer),
- "%#.*g",
- std::numeric_limits<double>::digits10,
- number.value);
-
- // Get rid of excess trailing zeroes before outputting.
- // Otherwise, printing 1.0 would result in "1.00000000000000".
- // NOTE: valid JSON numbers cannot end with a '.'.
- std::string trimmed = strings::trim(buffer, strings::SUFFIX, "0");
- return out << trimmed << (trimmed.back() == '.' ? "0" : "");
- }
- case Number::SIGNED_INTEGER:
- return out << number.signed_integer;
- case Number::UNSIGNED_INTEGER:
- return out << number.unsigned_integer;
-
- // NOTE: By not setting a default we leverage the compiler
- // errors when the enumeration is augmented to find all
- // the cases we need to provide.
- }
-
- UNREACHABLE();
-}
-
-
-inline std::ostream& operator<<(std::ostream& out, const Object& object)
-{
- out << "{";
- std::map<std::string, Value>::const_iterator iterator;
- iterator = object.values.begin();
- while (iterator != object.values.end()) {
- out << String((*iterator).first) << ":" << (*iterator).second;
- if (++iterator != object.values.end()) {
- out << ",";
- }
- }
- out << "}";
- return out;
-}
-
-
-inline std::ostream& operator<<(std::ostream& out, const Array& array)
-{
- out << "[";
- std::vector<Value>::const_iterator iterator;
- iterator = array.values.begin();
- while (iterator != array.values.end()) {
- out << *iterator;
- if (++iterator != array.values.end()) {
- out << ",";
- }
- }
- out << "]";
- return out;
-}
-
-
-inline std::ostream& operator<<(std::ostream& out, const Boolean& boolean)
-{
- return out << (boolean.value ? "true" : "false");
-}
-
-
-inline std::ostream& operator<<(std::ostream& out, const Null&)
-{
- return out << "null";
-}
-
-namespace internal {
-
-inline Value convert(const picojson::value& value)
-{
- if (value.is<picojson::null>()) {
- return Null();
- } else if (value.is<bool>()) {
- return Boolean(value.get<bool>());
- } else if (value.is<picojson::value::object>()) {
- Object object;
- foreachpair (const std::string& name,
- const picojson::value& v,
- value.get<picojson::value::object>()) {
- object.values[name] = convert(v);
- }
- return object;
- } else if (value.is<picojson::value::array>()) {
- Array array;
- foreach (const picojson::value& v, value.get<picojson::value::array>()) {
- array.values.push_back(convert(v));
- }
- return array;
- } else if (value.is<int64_t>()) {
- return Number(value.get<int64_t>());
- } else if (value.is<double>()) {
- return Number(value.get<double>());
- } else if (value.is<std::string>()) {
- return String(value.get<std::string>());
- }
- return Null();
-}
-
-} // namespace internal {
-
-
-inline Try<Value> parse(const std::string& s)
-{
- const char* parseBegin = s.c_str();
- picojson::value value;
- std::string error;
-
- // Because PicoJson supports repeated parsing of multiple objects/arrays in a
- // stream, it will quietly ignore trailing non-whitespace characters. We would
- // rather throw an error, however, so use `last_char` to check for this.
- const char* lastVisibleChar =
- parseBegin + s.find_last_not_of(strings::WHITESPACE);
-
- // Parse the string, returning a pointer to the character
- // immediately following the last one parsed.
- const char* parseEnd =
- picojson::parse(value, parseBegin, parseBegin + s.size(), &error);
-
- if (!error.empty()) {
- return Error(error);
- } else if (parseEnd != lastVisibleChar + 1) {
- return Error(
- "Parsed JSON included non-whitespace trailing characters: "
- + s.substr(parseEnd - parseBegin, lastVisibleChar + 1 - parseEnd));
- }
-
- return internal::convert(value);
-}
-
-
-template <typename T>
-Try<T> parse(const std::string& s)
-{
- Try<Value> value = parse(s);
-
- if (value.isError()) {
- return Error(value.error());
- }
-
- if (!value.get().is<T>()) {
- return Error("Unexpected JSON type parsed");
- }
-
- return value.get().as<T>();
-}
-
-
-template <>
-inline Try<Value> parse(const std::string& s)
-{
- return parse(s);
-}
-
-} // namespace JSON {
-
-#endif // __STOUT_JSON__
http://git-wip-us.apache.org/repos/asf/mesos/blob/c235f7c1/3rdparty/libprocess/3rdparty/stout/include/stout/jsonify.hpp
----------------------------------------------------------------------
diff --git a/3rdparty/libprocess/3rdparty/stout/include/stout/jsonify.hpp b/3rdparty/libprocess/3rdparty/stout/include/stout/jsonify.hpp
deleted file mode 100644
index 8220d00..0000000
--- a/3rdparty/libprocess/3rdparty/stout/include/stout/jsonify.hpp
+++ /dev/null
@@ -1,678 +0,0 @@
-// 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 __STOUT_JSONIFY__
-#define __STOUT_JSONIFY__
-
-#include <cstddef>
-#include <functional>
-#include <ostream>
-#include <sstream>
-#include <string>
-#include <type_traits>
-#include <utility>
-
-#include <stout/result_of.hpp>
-#include <stout/strings.hpp>
-
-// `jsonify` takes an instance of a C++ object and returns a light-weight proxy
-// object that can either be implicitly converted to a `std::string`, or
-// directly inserted into an output stream.
-//
-// `jsonify(const T&)` is implemented by calling the function `json`.
-// We perform unqualified function call so that it can detect overloads via
-// argument dependent lookup. That is, we will search for, and use a free
-// function named `json` in the same namespace as `T`.
-//
-// IMPORTANT: The output stream must not be exception-enabled. This is because
-// the writer definitions below insert into the output stream in their
-// destructors.
-//
-// NOTE: This relationship is similar to `boost::hash` and `hash_value`.
-
-
-// Forward declaration of `JSON::Proxy`.
-namespace JSON { class Proxy; }
-
-// Forward declaration of `jsonify`.
-template <typename T>
-JSON::Proxy jsonify(const T&);
-
-namespace JSON {
-
-// The result of `jsonify`. This is a light-weight proxy object that can either
-// be implicitly converted to a `std::string`, or directly inserted into an
-// output stream.
-//
-// In order to make this object light-weight, variables are captured by
-// reference. This gives rise to similar semantics as `std::forward_as_tuple`.
-// If the arguments are temporaries, `JSON::Proxy` does not extend their
-// lifetime; they have to be used before the end of the full expression.
-class Proxy
-{
-public:
- operator std::string() &&
- {
- std::ostringstream stream;
- stream << std::move(*this);
- return stream.str();
- }
-
-private:
- Proxy(std::function<void(std::ostream*)> write) : write_(std::move(write)) {}
-
- // We declare copy/move constructors `private` to prevent statements that try
- // to "save" an instance of `Proxy` such as:
- //
- // ```
- // std::string F();
- // Proxy proxy = jsonify(F());
- // ```
- //
- // Since `proxy` in the above example would be holding onto a reference to a
- // temporary string returned by `F()`.
- Proxy(const Proxy&) = default;
- Proxy(Proxy&&) = default;
-
- std::function<void(std::ostream*)> write_;
-
- template <typename T>
- friend Proxy (::jsonify)(const T&);
-
- friend std::ostream& operator<<(std::ostream& stream, Proxy&& that);
-};
-
-
-inline std::ostream& operator<<(std::ostream& stream, Proxy&& that)
-{
- that.write_(&stream);
- return stream;
-}
-
-
-// The boolean writer. If `set` is not called at all, `false` is printed.
-// If `set` is called more than once, only the last value is printed out.
-class BooleanWriter
-{
-public:
- BooleanWriter(std::ostream* stream) : stream_(stream), value_(false) {}
-
- BooleanWriter(const BooleanWriter&) = delete;
- BooleanWriter(BooleanWriter&&) = delete;
-
- ~BooleanWriter() { *stream_ << (value_ ? "true" : "false"); }
-
- BooleanWriter& operator=(const BooleanWriter&) = delete;
- BooleanWriter& operator=(BooleanWriter&&) = delete;
-
- void set(bool value) { value_ = value; }
-
-private:
- std::ostream* stream_;
- bool value_;
-};
-
-
-// The number writer. If `set` is not called at all, `0` is printed.
-// If `set` is called more than once, only the last value is printed.
-class NumberWriter
-{
-public:
- NumberWriter(std::ostream* stream)
- : stream_(stream), type_(INT), int_(0) {}
-
- NumberWriter(const NumberWriter&) = delete;
- NumberWriter(NumberWriter&&) = delete;
-
- ~NumberWriter()
- {
- switch (type_) {
- case INT: {
- *stream_ << int_;
- break;
- }
- case UINT: {
- *stream_ << uint_;
- break;
- }
- case DOUBLE: {
- // Prints a floating point value, with the specified precision, see:
- // http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2006/n2005.pdf
- // Additionally ensures that a decimal point is in the output.
- char buffer[50]; // More than enough for the specified precision.
- const int size = snprintf(
- buffer,
- sizeof(buffer),
- "%#.*g",
- std::numeric_limits<double>::digits10,
- double_);
-
- // Get rid of excess trailing zeroes before outputting.
- // Otherwise, printing 1.0 would result in "1.00000000000000".
- //
- // NOTE: We intentionally do not use `strings::trim` here in order to
- // avoid construction of temporary strings.
- int back = size - 1;
- for (; back > 0; --back) {
- if (buffer[back] != '0') {
- break;
- }
- buffer[back] = '\0';
- }
-
- // NOTE: valid JSON numbers cannot end with a '.'.
- *stream_ << buffer << (buffer[back] == '.' ? "0" : "");
- break;
- }
- }
- }
-
- NumberWriter& operator=(const NumberWriter&) = delete;
- NumberWriter& operator=(NumberWriter&&) = delete;
-
- // NOTE 1: We enumerate overloads for all of the integral types here to avoid
- // ambiguities between signed and unsigned conversions. If we were to only
- // overload for `long long int` and `unsigned long long int`, passing an
- // argument of `0` would be ambiguous since `0` has type `int`, and cost of
- // conversion to `long long int` or `unsigned long long int` is equivalent.
-
- // NOTE 2: We use the various modifiers on `int` as opposed to fixed size
- // types such as `int32_t` and `int64_t` because these types do not cover all
- // of the integral types. For example, `uint32_t` may map to `unsigned int`,
- // and `uint64_t` to `unsigned long long int`. If `size_t` maps to `unsigned
- // long int`, it is ambiguous to pass an instance of `size_t`. defining an
- // overload for `size_t` would solve the problem on a specific platform, but
- // we can run into issues again on another platform if `size_t` maps to
- // `unsigned long long int`, since we would get a redefinition error.
-
- void set(short int value) { set(static_cast<long long int>(value)); }
-
- void set(int value) { set(static_cast<long long int>(value)); }
-
- void set(long int value) { set(static_cast<long long int>(value)); }
-
- void set(long long int value)
- {
- type_ = INT;
- int_ = value;
- }
-
- void set(unsigned short int value)
- {
- set(static_cast<unsigned long long int>(value));
- }
-
- void set(unsigned int value)
- {
- set(static_cast<unsigned long long int>(value));
- }
-
- void set(unsigned long int value)
- {
- set(static_cast<unsigned long long int>(value));
- }
-
- void set(unsigned long long int value)
- {
- type_ = UINT;
- uint_ = value;
- }
-
- void set(float value) { set(static_cast<double>(value)); }
-
- void set(double value)
- {
- type_ = DOUBLE;
- double_ = value;
- }
-
-private:
- std::ostream* stream_;
-
- enum { INT, UINT, DOUBLE } type_;
-
- union
- {
- long long int int_;
- unsigned long long int uint_;
- double double_;
- };
-};
-
-
-// The string writer. `append` is used to append a character or a string.
-// If `append` is not called at all, `""` is printed.
-class StringWriter
-{
-public:
- StringWriter(std::ostream* stream) : stream_(stream) { *stream_ << '"'; }
-
- StringWriter(const StringWriter&) = delete;
- StringWriter(StringWriter&&) = delete;
-
- ~StringWriter() { *stream_ << '"'; }
-
- StringWriter& operator=(const StringWriter&) = delete;
- StringWriter& operator=(StringWriter&&) = delete;
-
- void append(char c)
- {
- switch (c) {
- case '"' : *stream_ << "\\\""; break;
- case '\\': *stream_ << "\\\\"; break;
- case '/' : *stream_ << "\\/"; break;
- case '\b': *stream_ << "\\b"; break;
- case '\f': *stream_ << "\\f"; break;
- case '\n': *stream_ << "\\n"; break;
- case '\r': *stream_ << "\\r"; break;
- case '\t': *stream_ << "\\t"; break;
- default: {
- if (static_cast<unsigned char>(c) < 0x20 || c == 0x7f) {
- char buffer[7];
- snprintf(buffer, sizeof(buffer), "\\u%04x", c & 0xff);
- stream_->write(buffer, sizeof(buffer) - 1);
- } else {
- *stream_ << c;
- }
- break;
- }
- }
- }
-
- template <std::size_t N>
- void append(const char (&value)[N]) { append(value, N - 1); }
- void append(const std::string& value) { append(value.data(), value.size()); }
-
-private:
- void append(const char* value, std::size_t size)
- {
- for (std::size_t i = 0; i < size; ++i) {
- append(value[i]);
- }
- }
-
- std::ostream* stream_;
-};
-
-
-// The array writer. `element(value)` is used to write a new element.
-// If `element` is not called at all, `[]` is printed.
-class ArrayWriter
-{
-public:
- ArrayWriter(std::ostream* stream) : stream_(stream), count_(0)
- {
- *stream_ << '[';
- }
-
- ArrayWriter(const ArrayWriter&) = delete;
- ArrayWriter(ArrayWriter&&) = delete;
-
- ~ArrayWriter() { *stream_ << ']'; }
-
- ArrayWriter& operator=(const ArrayWriter&) = delete;
- ArrayWriter& operator=(ArrayWriter&&) = delete;
-
- template <typename T>
- void element(const T& value)
- {
- if (count_ > 0) {
- *stream_ << ',';
- }
- *stream_ << jsonify(value);
- ++count_;
- }
-
-private:
- std::ostream* stream_;
- std::size_t count_;
-};
-
-
-// The object writer. `field(key, value)` is used to write a new field.
-// If `field` is not called at all, `{}` is printed.
-class ObjectWriter
-{
-public:
- ObjectWriter(std::ostream* stream) : stream_(stream), count_(0)
- {
- *stream_ << '{';
- }
-
- ObjectWriter(const ObjectWriter&) = delete;
- ObjectWriter(ObjectWriter&&) = delete;
-
- ~ObjectWriter() { *stream_ << '}'; }
-
- ObjectWriter& operator=(const ObjectWriter&) = delete;
- ObjectWriter& operator=(ObjectWriter&&) = delete;
-
- template <typename T>
- void field(const std::string& key, const T& value)
- {
- if (count_ > 0) {
- *stream_ << ',';
- }
- *stream_ << jsonify(key) << ':' << jsonify(value);
- ++count_;
- }
-
-private:
- std::ostream* stream_;
- std::size_t count_;
-};
-
-
-// `json` function for boolean.
-inline void json(BooleanWriter* writer, bool value) { writer->set(value); }
-
-
-// `json` functions for numbers.
-inline void json(NumberWriter* writer, short int value) { writer->set(value); }
-inline void json(NumberWriter* writer, int value) { writer->set(value); }
-inline void json(NumberWriter* writer, long int value) { writer->set(value); }
-
-
-inline void json(NumberWriter* writer, long long int value)
-{
- writer->set(value);
-}
-
-
-inline void json(NumberWriter* writer, unsigned short int value)
-{
- writer->set(value);
-}
-
-
-inline void json(NumberWriter* writer, unsigned int value)
-{
- writer->set(value);
-}
-
-
-inline void json(NumberWriter* writer, unsigned long int value)
-{
- writer->set(value);
-}
-
-
-inline void json(NumberWriter* writer, unsigned long long int value)
-{
- writer->set(value);
-}
-
-
-inline void json(NumberWriter* writer, float value) { writer->set(value); }
-inline void json(NumberWriter* writer, double value) { writer->set(value); }
-
-
-// `json` functions for strings.
-
-template <std::size_t N>
-void json(StringWriter* writer, const char (&value)[N])
-{
- writer->append(value);
-}
-
-
-inline void json(StringWriter* writer, const std::string& value)
-{
- writer->append(value);
-}
-
-namespace internal {
-
-// TODO(mpark): Pull this out to something like <stout/meta.hpp>.
-// This pattern already exists in `<process/future.hpp>`.
-struct LessPrefer {};
-struct Prefer : LessPrefer {};
-
-// The member `value` is `true` if `T` is a sequence, and `false` otherwise.
-template <typename T>
-struct IsSequence
-{
-private:
- // This overload only participates in overload resolution if the following
- // expressions are valid.
- // (1) begin(t) != end(t)
- // (2) auto iter = begin(t); ++iter
- // (3) *begin(t)
- //
- // The expressions are only used for SFINAE purposes, and comma operators are
- // used to ignore the results of the expressions. That is, the return type of
- // this function is `decltype(expr0, expr1, expr2, std::true_type{})` which is
- // `std::true_type`.
- template <typename U>
- static auto test(Prefer) -> decltype(
- // Cast to `void` to suppress `-Wunused-comparison` warnings.
- void(std::begin(std::declval<U&>()) != std::end(std::declval<U&>())),
- ++std::declval<decltype(std::begin(std::declval<U&>()))&>(),
- *std::begin(std::declval<U&>()),
- std::true_type{});
-
- // This overload is chosen if the preferred version is SFINAE'd out.
- template <typename U>
- static std::false_type test(LessPrefer);
-
-public:
- static constexpr bool value = decltype(test<T>(Prefer()))::value;
-};
-
-
-// The member `value` is `true` if `T` has a member typedef `mapped_type`, and
-// `false` otherwise. We take the existence of `mapped_type` as the indication
-// of an associative container (e.g., std::map).
-template <typename T>
-struct HasMappedType
-{
-private:
- template <typename U, typename = typename U::mapped_type>
- static std::true_type test(Prefer);
-
- template <typename U>
- static std::false_type test(LessPrefer);
-
-public:
- static constexpr bool value = decltype(test<T>(Prefer()))::value;
-};
-
-} // namespace internal {
-
-// `json` function for iterables (e.g., std::vector).
-// This function is only enabled if `Iterable` is iterable, is not a
-// `const char (&)[N]` (in order to avoid ambiguity with the string literal
-// overload), and does not have a member typedef `mapped_type` (we take the
-// existence of `mapped_type` as the indication of an associative container).
-template <
- typename Iterable,
- typename std::enable_if<
- internal::IsSequence<Iterable>::value &&
- !(std::is_array<Iterable>::value &&
- std::rank<Iterable>::value == 1 &&
- std::is_same<
- char, typename std::remove_extent<Iterable>::type>::value) &&
- !internal::HasMappedType<Iterable>::value, int>::type = 0>
-void json(ArrayWriter* writer, const Iterable& iterable)
-{
- foreach (const auto& value, iterable) {
- writer->element(value);
- }
-}
-
-
-// `json` function for dictionaries (e.g., std::map).
-// This function is only enabled if `Dictionary` is iterable, and has a member
-// typedef `mapped_type` (we take the existence of `mapped_type` as the
-// indication of an associative container).
-template <
- typename Dictionary,
- typename std::enable_if<
- internal::IsSequence<Dictionary>::value &&
- internal::HasMappedType<Dictionary>::value, int>::type = 0>
-void json(ObjectWriter* writer, const Dictionary& dictionary)
-{
- foreachpair (const auto& key, const auto& value, dictionary) {
- // TODO(mpark): Consider passing `stringify(key)`.
- writer->field(key, value);
- }
-}
-
-
-// An object that can be converted to a pointer to any of the JSON writers.
-// This is used to resolve the following scenario:
-//
-// ```
-// void json(JSON::ObjectWriter*, const Resources&);
-//
-// void json(
-// JSON::ArrayWriter*,
-// const google::protobuf::RepeatedPtrField<Resource>&);
-//
-// Resources resources;
-// std::cout << jsonify(resources); // We want to use the first overload!
-// ```
-//
-// The goal is to perform overload resolution based on the second parameter.
-// Since `WriterProxy` is convertible to any of the writers equivalently, we
-// force overload resolution of `json(WriterProxy(stream), value)` to depend
-// only on the second parameter.
-class WriterProxy
-{
-public:
- WriterProxy(std::ostream* stream) : stream_(stream) {}
-
- ~WriterProxy()
- {
- switch (type_) {
- case BOOLEAN_WRITER: {
- writer_.boolean_writer.~BooleanWriter();
- break;
- }
- case NUMBER_WRITER: {
- writer_.number_writer.~NumberWriter();
- break;
- }
- case STRING_WRITER: {
- writer_.string_writer.~StringWriter();
- break;
- }
- case ARRAY_WRITER: {
- writer_.array_writer.~ArrayWriter();
- break;
- }
- case OBJECT_WRITER: {
- writer_.object_writer.~ObjectWriter();
- break;
- }
- }
- }
-
- operator BooleanWriter*() &&
- {
- new (&writer_.boolean_writer) BooleanWriter(stream_);
- type_ = BOOLEAN_WRITER;
- return &writer_.boolean_writer;
- }
-
- operator NumberWriter*() &&
- {
- new (&writer_.number_writer) NumberWriter(stream_);
- type_ = NUMBER_WRITER;
- return &writer_.number_writer;
- }
-
- operator StringWriter*() &&
- {
- new (&writer_.string_writer) StringWriter(stream_);
- type_ = STRING_WRITER;
- return &writer_.string_writer;
- }
-
- operator ArrayWriter*() &&
- {
- new (&writer_.array_writer) ArrayWriter(stream_);
- type_ = ARRAY_WRITER;
- return &writer_.array_writer;
- }
-
- operator ObjectWriter*() &&
- {
- new (&writer_.object_writer) ObjectWriter(stream_);
- type_ = OBJECT_WRITER;
- return &writer_.object_writer;
- }
-
-private:
- enum Type
- {
- BOOLEAN_WRITER,
- NUMBER_WRITER,
- STRING_WRITER,
- ARRAY_WRITER,
- OBJECT_WRITER
- };
-
- union Writer
- {
- Writer() {}
- ~Writer() {}
- BooleanWriter boolean_writer;
- NumberWriter number_writer;
- StringWriter string_writer;
- ArrayWriter array_writer;
- ObjectWriter object_writer;
- };
-
- std::ostream* stream_;
- Type type_;
- Writer writer_;
-};
-
-namespace internal {
-
-// NOTE: The following overloads of `internal::jsonify` return a `std::function`
-// rather than a `JSON::Proxy` since `JSON::Proxy`'s copy/move constructors are
-// declared `private`. We could also declare `internal::jsonify` as friend of
-// `JSON::Proxy` but chose to minimize friendship and construct a
-// `std::function` instead.
-
-// Given an `F` which is a "write" function, we simply use it directly.
-template <typename F, typename = typename result_of<F(WriterProxy)>::type>
-std::function<void(std::ostream*)> jsonify(const F& write, Prefer)
-{
- return [&write](std::ostream* stream) { write(WriterProxy(stream)); };
-}
-
-// Given a `T` which is not a "write" function itself, the default "write"
-// function is to perform an unqualified function call to `json`, which enables
-// argument-dependent lookup. This considers the `json` overloads in the `JSON`
-// namespace as well, since `WriterProxy` is intentionally defined in the
-// `JSON` namespace.
-template <typename T>
-std::function<void(std::ostream*)> jsonify(const T& value, LessPrefer)
-{
- return [&value](std::ostream* stream) {
- json(WriterProxy(stream), value);
- };
-}
-
-} // namespace internal {
-} // namespace JSON {
-
-template <typename T>
-JSON::Proxy jsonify(const T& t)
-{
- return JSON::internal::jsonify(t, JSON::internal::Prefer());
-}
-
-#endif // __STOUT_JSONIFY__
http://git-wip-us.apache.org/repos/asf/mesos/blob/c235f7c1/3rdparty/libprocess/3rdparty/stout/include/stout/lambda.hpp
----------------------------------------------------------------------
diff --git a/3rdparty/libprocess/3rdparty/stout/include/stout/lambda.hpp b/3rdparty/libprocess/3rdparty/stout/include/stout/lambda.hpp
deleted file mode 100644
index e67acf5..0000000
--- a/3rdparty/libprocess/3rdparty/stout/include/stout/lambda.hpp
+++ /dev/null
@@ -1,29 +0,0 @@
-// 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 __STOUT_LAMBDA_HPP__
-#define __STOUT_LAMBDA_HPP__
-
-#include <functional>
-
-namespace lambda {
-
-using std::bind;
-using std::cref;
-using std::function;
-using std::ref;
-
-using namespace std::placeholders;
-
-} // namespace lambda {
-
-#endif // __STOUT_LAMBDA_HPP__
http://git-wip-us.apache.org/repos/asf/mesos/blob/c235f7c1/3rdparty/libprocess/3rdparty/stout/include/stout/linkedhashmap.hpp
----------------------------------------------------------------------
diff --git a/3rdparty/libprocess/3rdparty/stout/include/stout/linkedhashmap.hpp b/3rdparty/libprocess/3rdparty/stout/include/stout/linkedhashmap.hpp
deleted file mode 100644
index 6e06260..0000000
--- a/3rdparty/libprocess/3rdparty/stout/include/stout/linkedhashmap.hpp
+++ /dev/null
@@ -1,104 +0,0 @@
-// 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 __STOUT_LINKEDHASHMAP_HPP__
-#define __STOUT_LINKEDHASHMAP_HPP__
-
-#include <list>
-#include <utility>
-
-#include <stout/hashmap.hpp>
-#include <stout/option.hpp>
-
-// Implementation of a hashmap that maintains the insertion order
-// of the keys. Note that re-insertion of a key (i.e., update)
-// doesn't update its insertion order.
-// TODO(vinod/bmahler): Consider extending from stout::hashmap and/or
-// having a compatible API with stout::hashmap.
-template <typename Key, typename Value>
-class LinkedHashMap
-{
-public:
- typedef std::list<Key> list;
- typedef hashmap<Key, std::pair<Value, typename list::iterator> > map;
-
- Value& operator[] (const Key& key)
- {
- if (!values_.contains(key)) {
- // Insert into the list and get the "pointer" into the list.
- typename list::iterator i = keys_.insert(keys_.end(), key);
- values_[key] = std::make_pair(Value(), i); // Store default value.
- }
- return values_[key].first;
- }
-
- Option<Value> get(const Key& key) const
- {
- if (values_.contains(key)) {
- return values_.at(key).first;
- }
- return None();
- }
-
- bool contains(const Key& key) const
- {
- return values_.contains(key);
- }
-
- size_t erase(const Key& key)
- {
- if (values_.contains(key)) {
- // Get the "pointer" into the list.
- typename list::iterator i = values_[key].second;
- keys_.erase(i);
- return values_.erase(key);
- }
- return 0;
- }
-
- std::list<Key> keys() const
- {
- return keys_;
- }
-
- std::list<Value> values() const
- {
- std::list<Value> result;
- foreach (const Key& key, keys_) {
- result.push_back(values_.at(key).first);
- }
- return result;
- }
-
- size_t size() const
- {
- return keys_.size();
- }
-
- bool empty() const
- {
- return keys_.empty();
- }
-
- void clear()
- {
- values_.clear();
- keys_.clear();
- }
-
-private:
- list keys_; // Keys ordered by the insertion order.
- map values_; // Map of values and "pointers" to the linked list.
-};
-
-
-#endif // __STOUT_LINKEDHASHMAP_HPP__
http://git-wip-us.apache.org/repos/asf/mesos/blob/c235f7c1/3rdparty/libprocess/3rdparty/stout/include/stout/mac.hpp
----------------------------------------------------------------------
diff --git a/3rdparty/libprocess/3rdparty/stout/include/stout/mac.hpp b/3rdparty/libprocess/3rdparty/stout/include/stout/mac.hpp
deleted file mode 100644
index 09c0d49..0000000
--- a/3rdparty/libprocess/3rdparty/stout/include/stout/mac.hpp
+++ /dev/null
@@ -1,202 +0,0 @@
-// 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 __STOUT_MAC_HPP__
-#define __STOUT_MAC_HPP__
-
-#if defined(__linux__) || defined(__APPLE__) || defined(__FreeBSD__)
-#include <ifaddrs.h>
-#endif
-#include <stdint.h>
-#include <stdio.h>
-#include <string.h>
-
-#include <arpa/inet.h>
-
-#ifdef __linux__
-#include <linux/if.h>
-#include <linux/if_packet.h>
-#endif
-
-#include <net/ethernet.h>
-
-#ifdef __APPLE__
-#include <net/if.h>
-#include <net/if_dl.h>
-#include <net/if_types.h>
-#endif
-
-#include <sys/socket.h>
-#include <sys/types.h>
-
-#include <iostream>
-#include <string>
-
-#include "abort.hpp"
-#include "error.hpp"
-#include "none.hpp"
-#include "result.hpp"
-#include "stringify.hpp"
-#include "try.hpp"
-
-
-// Network utilities.
-namespace net {
-
-// Represents a MAC address. A MAC address is a 48-bit unique
-// identifier assigned to a network interface for communications on
-// the physical network segment. We use a byte array (in transmission
-// order) to represent a MAC address. For example, for a MAC address
-// 01:23:34:67:89:ab, the format is shown as follows:
-//
-// MSB LSB
-// | |
-// v v
-// +--------+--------+--------+--------+--------+--------+
-// |bytes[0]|bytes[1]|bytes[2]|bytes[3]|bytes[4]|bytes[5]|
-// +--------+--------+--------+--------+--------+--------+
-//
-// 01 : 23 : 45 : 67 : 89 : ab
-// NOLINT(readability/ending_punctuation)
-class MAC
-{
-public:
- // Constructs a MAC address from a byte array.
- explicit MAC(const uint8_t (&_bytes)[6])
- {
- for (size_t i = 0; i < 6; i++) {
- bytes[i] = _bytes[i];
- }
- }
-
- // Returns the byte at the given index. For example, for a MAC
- // address 01:23:45:67:89:ab, mac[0] = 01, mac[1] = 23 and etc.
- uint8_t operator[](size_t index) const
- {
- if (index >= 6) {
- ABORT("Invalid index specified in MAC::operator[]\n");
- }
-
- return bytes[index];
- }
-
- bool operator==(const MAC& that) const
- {
- for (size_t i = 0; i < 6; i++) {
- if (bytes[i] != that.bytes[i]) {
- return false;
- }
- }
- return true;
- }
-
- bool operator!=(const MAC& that) const
- {
- return !(*this == that);
- }
-
-private:
- // Byte array of this MAC address (in transmission order).
- uint8_t bytes[6];
-};
-
-
-// Returns the standard string format (IEEE 802) of the given MAC
-// address, which contains six groups of two hexadecimal digits,
-// separated by colons, in transmission order (e.g.,
-// 01:23:45:67:89:ab).
-inline std::ostream& operator<<(std::ostream& stream, const MAC& mac)
-{
- char buffer[18];
-
- sprintf(
- buffer,
- "%02hhx:%02hhx:%02hhx:%02hhx:%02hhx:%02hhx",
- mac[0],
- mac[1],
- mac[2],
- mac[3],
- mac[4],
- mac[5]);
-
- return stream << buffer;
-}
-
-
-// Returns the MAC address of a given link device. The link device is
-// specified using its name (e.g., eth0). Returns error if the link
-// device is not found. Returns none if the link device is found, but
-// does not have a MAC address (e.g., loopback).
-inline Result<MAC> mac(const std::string& name)
-{
-#if !defined(__linux__) && !defined(__APPLE__) && !defined(__FreeBSD__)
- return Error("Not implemented");
-#else
- struct ifaddrs* ifaddr = NULL;
- if (getifaddrs(&ifaddr) == -1) {
- return ErrnoError();
- }
-
- // Indicates whether the link device is found or not.
- bool found = false;
-
- for (struct ifaddrs* ifa = ifaddr; ifa != NULL; ifa = ifa->ifa_next) {
- if (ifa->ifa_name != NULL && !strcmp(ifa->ifa_name, name.c_str())) {
- found = true;
-
-# if defined(__linux__)
- if (ifa->ifa_addr != NULL && ifa->ifa_addr->sa_family == AF_PACKET) {
- struct sockaddr_ll* link = (struct sockaddr_ll*) ifa->ifa_addr;
-
- if (link->sll_halen == 6) {
- struct ether_addr* addr = (struct ether_addr*) link->sll_addr;
- MAC mac(addr->ether_addr_octet);
-
- // Ignore if the address is 0 so that the results are
- // consistent on both OSX and Linux.
- if (stringify(mac) == "00:00:00:00:00:00") {
- continue;
- }
-
- freeifaddrs(ifaddr);
- return mac;
- }
- }
-# elif defined(__APPLE__)
- if (ifa->ifa_addr != NULL && ifa->ifa_addr->sa_family == AF_LINK) {
- struct sockaddr_dl* link = (struct sockaddr_dl*) ifa->ifa_addr;
-
- if (link->sdl_type == IFT_ETHER && link->sdl_alen == 6) {
- struct ether_addr* addr = (struct ether_addr*) LLADDR(link);
- MAC mac(addr->octet);
-
- freeifaddrs(ifaddr);
- return mac;
- }
- }
-# endif
- }
- }
-
- freeifaddrs(ifaddr);
-
- if (!found) {
- return Error("Cannot find the link device");
- }
-
- return None();
-#endif
-}
-
-} // namespace net {
-
-#endif // __STOUT_MAC_HPP__
http://git-wip-us.apache.org/repos/asf/mesos/blob/c235f7c1/3rdparty/libprocess/3rdparty/stout/include/stout/multihashmap.hpp
----------------------------------------------------------------------
diff --git a/3rdparty/libprocess/3rdparty/stout/include/stout/multihashmap.hpp b/3rdparty/libprocess/3rdparty/stout/include/stout/multihashmap.hpp
deleted file mode 100644
index bf11d66..0000000
--- a/3rdparty/libprocess/3rdparty/stout/include/stout/multihashmap.hpp
+++ /dev/null
@@ -1,159 +0,0 @@
-// 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 __STOUT_MULTIHASHMAP_HPP__
-#define __STOUT_MULTIHASHMAP_HPP__
-
-#include <algorithm> // For find.
-#include <list>
-#include <map>
-#include <set>
-#include <unordered_map>
-#include <utility>
-
-#include <stout/foreach.hpp>
-
-// Implementation of a hash multimap via 'std::unordered_multimap'
-// but with a better interface. The rationale for creating this is
-// that the std::unordered_multimap interface is painful to use
-// (requires lots of iterator garbage, as well as the use of
-// 'equal_range' which makes for cluttered code).
-template <typename Key,
- typename Value,
- typename Hash = std::hash<Key>,
- typename Equal = std::equal_to<Key>>
-class multihashmap : public std::unordered_multimap<Key, Value, Hash, Equal>
-{
-public:
- multihashmap() {}
- multihashmap(const std::multimap<Key, Value>& multimap);
- multihashmap(std::multimap<Key, Value>&& multimap);
- multihashmap(std::initializer_list<std::pair<const Key, Value>> list);
-
- void put(const Key& key, const Value& value);
- std::list<Value> get(const Key& key) const;
- std::set<Key> keys() const;
- bool remove(const Key& key);
- bool remove(const Key& key, const Value& value);
- bool contains(const Key& key) const;
- bool contains(const Key& key, const Value& value) const;
-};
-
-
-template <typename Key, typename Value, typename Hash, typename Equal>
-multihashmap<Key, Value, Hash, Equal>::multihashmap(
- const std::multimap<Key, Value>& multimap)
-{
- std::unordered_multimap<Key, Value, Hash, Equal>::reserve(multimap.size());
-
- foreachpair (const Key& key, const Value& value, multimap) {
- std::unordered_multimap<Key, Value, Hash, Equal>::emplace(key, value);
- }
-}
-
-
-template <typename Key, typename Value, typename Hash, typename Equal>
-multihashmap<Key, Value, Hash, Equal>::multihashmap(
- std::multimap<Key, Value>&& multimap)
-{
- std::unordered_multimap<Key, Value, Hash, Equal>::insert(
- std::make_move_iterator(multimap.begin()),
- std::make_move_iterator(multimap.end()));
-}
-
-
-template <typename Key, typename Value, typename Hash, typename Equal>
-multihashmap<Key, Value, Hash, Equal>::multihashmap(
- std::initializer_list<std::pair<const Key, Value>> list)
- : std::unordered_multimap<Key, Value, Hash, Equal>(list) {}
-
-
-template <typename Key, typename Value, typename Hash, typename Equal>
-void multihashmap<Key, Value, Hash, Equal>::put(
- const Key& key,
- const Value& value)
-{
- std::unordered_multimap<Key, Value, Hash, Equal>::insert({key, value});
-}
-
-
-template <typename Key, typename Value, typename Hash, typename Equal>
-std::list<Value> multihashmap<Key, Value, Hash, Equal>::get(
- const Key& key) const
-{
- std::list<Value> values; // Values to return.
-
- auto range =
- std::unordered_multimap<Key, Value, Hash, Equal>::equal_range(key);
-
- for (auto i = range.first; i != range.second; ++i) {
- values.push_back(i->second);
- }
-
- return values;
-}
-
-
-template <typename Key, typename Value, typename Hash, typename Equal>
-std::set<Key> multihashmap<Key, Value, Hash, Equal>::keys() const
-{
- std::set<Key> keys;
- foreachkey (const Key& key, *this) {
- keys.insert(key);
- }
- return keys;
-}
-
-
-template <typename Key, typename Value, typename Hash, typename Equal>
-bool multihashmap<Key, Value, Hash, Equal>::remove(const Key& key)
-{
- return std::unordered_multimap<Key, Value, Hash, Equal>::erase(key) > 0;
-}
-
-
-template <typename Key, typename Value, typename Hash, typename Equal>
-bool multihashmap<Key, Value, Hash, Equal>::remove(
- const Key& key,
- const Value& value)
-{
- auto range =
- std::unordered_multimap<Key, Value, Hash, Equal>::equal_range(key);
-
- for (auto i = range.first; i != range.second; ++i) {
- if (i->second == value) {
- std::unordered_multimap<Key, Value, Hash, Equal>::erase(i);
- return true;
- }
- }
-
- return false;
-}
-
-
-template <typename Key, typename Value, typename Hash, typename Equal>
-bool multihashmap<Key, Value, Hash, Equal>::contains(const Key& key) const
-{
- return multihashmap<Key, Value, Hash, Equal>::count(key) > 0;
-}
-
-
-template <typename Key, typename Value, typename Hash, typename Equal>
-bool multihashmap<Key, Value, Hash, Equal>::contains(
- const Key& key,
- const Value& value) const
-{
- const std::list<Value> values = get(key);
- return std::find(values.begin(), values.end(), value) != values.end();
-}
-
-#endif // __STOUT_MULTIHASHMAP_HPP__