Skip to content

Commit 130c6d8

Browse files
committed
Changed file extension for all header files to hpp
1 parent b2a8441 commit 130c6d8

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

46 files changed

+1665
-0
lines changed

stringify/container_traits.hpp

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
#ifndef CONTAINER_TRAITS_H_INCLUDED
2+
#define CONTAINER_TRAITS_H_INCLUDED
3+
4+
// and iterator traits :D
5+
6+
#include <iterator>
7+
#include <type_traits>
8+
9+
template <typename T, template <typename, class = std::allocator <T> > class ContainerT>
10+
struct has_random_access_iterator : std::is_same <
11+
typename std::iterator_traits<typename ContainerT<T>::iterator>::iterator_category
12+
, std::random_access_iterator_tag>
13+
{};
14+
15+
template <typename T, template <typename, class = std::allocator <T> > class ContainerT>
16+
struct has_bidirectional_iterator : std::is_same <
17+
typename std::iterator_traits<typename ContainerT<T>::iterator>::iterator_category
18+
, std::bidirectional_iterator_tag>
19+
{};
20+
21+
template <typename T, template <typename, class = std::allocator <T> > class ContainerT>
22+
struct has_forward_iterator : std::is_same <
23+
typename std::iterator_traits<typename ContainerT<T>::iterator>::iterator_category
24+
, std::forward_iterator_tag>
25+
{};
26+
27+
#endif // CONTAINER_TRAITS_H_INCLUDED

stringify/integer_of_size.hpp

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
#ifndef INTEGER_OF_SIZE_H_INCLUDED
2+
#define INTEGER_OF_SIZE_H_INCLUDED
3+
4+
#include <cstdint>
5+
6+
template <unsigned s>
7+
struct int_of_size
8+
{
9+
typedef int type;
10+
};
11+
12+
template <unsigned s>
13+
struct uint_of_size
14+
{
15+
typedef int type;
16+
};
17+
18+
#define __I_OF_SIZE(SIZE, TYPE) \
19+
template <> \
20+
struct int_of_size<(SIZE)> \
21+
{ \
22+
typedef TYPE type; \
23+
}; \
24+
\
25+
template <> \
26+
struct uint_of_size<(SIZE)> \
27+
{ \
28+
typedef u##TYPE type; \
29+
};
30+
// END OF MAKRO
31+
32+
33+
__I_OF_SIZE(sizeof(int8_t), int8_t)
34+
__I_OF_SIZE(sizeof(int16_t), int16_t)
35+
__I_OF_SIZE(sizeof(int32_t), int32_t)
36+
__I_OF_SIZE(sizeof(int64_t), int64_t)
37+
38+
#endif // INTEGER_OF_SIZE_H_INCLUDED

stringify/iterator_traits.hpp

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
#ifndef JSS_ITERATOR_TRAITS_H_INCLUDED
2+
#define JSS_ITERATOR_TRAITS_H_INCLUDED
3+
4+
#include <iterator>
5+
#include <type_traits>
6+
7+
template <typename T>
8+
struct is_random_access_iterator : std::is_same <
9+
typename std::iterator_traits<T>::iterator_category
10+
, std::random_access_iterator_tag>
11+
{};
12+
13+
template <typename T>
14+
struct is_bidirectional_iterator : std::is_same <
15+
typename std::iterator_traits<T>::iterator_category
16+
, std::bidirectional_iterator_tag>
17+
{};
18+
19+
template <typename T>
20+
struct is_forward_iterator : std::is_same <
21+
typename std::iterator_traits<T>::iterator_category
22+
, std::forward_iterator_tag>
23+
{};
24+
25+
26+
#endif // ITERATOR_TRAITS_H_INCLUDED

stringify/jss.hpp

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
#ifndef JSS_H_INCLUDED
2+
#define JSS_H_INCLUDED
3+
4+
// Do not include this file! include only those headers that you need
5+
// + jss_undefine
6+
7+
#include "jss_core.hpp"
8+
#include "jss_fundamental.hpp"
9+
#include "jss_string.hpp"
10+
#include "jss_list.hpp"
11+
#include "jss_vector.hpp"
12+
#include "jss_deque.hpp"
13+
#include "jss_forward_list.hpp"
14+
#include "jss_iterator.hpp"
15+
#include "jss_array.hpp"
16+
#include "jss_tuple.hpp"
17+
#include "jss_object.hpp"
18+
#include "jss_convenience.hpp"
19+
#include "jss_queue.hpp"
20+
#include "jss_stack.hpp"
21+
#include "jss_bitset.hpp"
22+
#include "jss_pointer.hpp"
23+
#include "jss_pair.hpp"
24+
#include "jss_valarray.hpp"
25+
#include "jss_map.hpp"
26+
#include "jss_unordered_map.hpp"
27+
#include "jss_set.hpp"
28+
#include "jss_atomic.hpp"
29+
#include "jss_unique_ptr.hpp"
30+
#include "jss_shared_ptr.hpp"
31+
#include "jss_weak_ptr.hpp"
32+
#include "jss_check.hpp"
33+
#include "jss_optional.hpp"
34+
#include "jss_renamed.hpp"
35+
36+
// #include "jss_undefine.hpp"
37+
38+
#endif // JSS_H_INCLUDED

stringify/jss_array.hpp

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
#ifndef JSS_ARRAY_H_INCLUDED
2+
#define JSS_ARRAY_H_INCLUDED
3+
4+
#include "jss_core.hpp"
5+
#include "jss_iterator.hpp"
6+
#include "jss_optional.hpp"
7+
#include <array>
8+
9+
namespace JSON
10+
{
11+
template <typename T, std::size_t N,
12+
typename = typename std::enable_if <Internal::can_stringify<T>::value>::type >
13+
std::ostream& stringify(std::ostream& stream, std::string const& name, std::array<T, N> const& values, StringificationOptions options = DEFAULT_OPTIONS)
14+
{
15+
WRITE_ARRAY_START(stream);
16+
options.ignore_name = true;
17+
bool first = true;
18+
for (auto const& i : values)
19+
{
20+
if (Internal::is_optional_set(i))
21+
{
22+
if (!first)
23+
stream << options.delimiter;
24+
stringify(stream, {}, i, options);
25+
first = false;
26+
}
27+
}
28+
WRITE_ARRAY_END(stream);
29+
return stream;
30+
}
31+
}
32+
33+
#endif // JSS_ARRAY_H_INCLUDED

stringify/jss_atomic.hpp

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
#ifndef JSS_ATOMIC_H_INCLUDED
2+
#define JSS_ATOMIC_H_INCLUDED
3+
4+
#include "jss_core.hpp"
5+
#include <atomic>
6+
7+
namespace JSON
8+
{
9+
template <typename T,
10+
typename = typename std::enable_if <Internal::can_stringify<T>::value>::type >
11+
std::ostream& stringify (std::ostream& stream, const std::string& name, std::atomic<T> const& value, StringificationOptions const& options)
12+
{
13+
stringify(stream, name, value.load(), options);
14+
return stream;
15+
}
16+
}
17+
18+
#endif // JSS_ATOMIC_H_INCLUDED

stringify/jss_bidirectional.hpp

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
#ifndef JSS_BIDIRECTIONAL_H_INCLUDED
2+
#define JSS_BIDIRECTIONAL_H_INCLUDED
3+
4+
#include "jss_core.hpp"
5+
#include "container_traits.hpp"
6+
#include "jss_object.hpp"
7+
#include "jss_container.hpp"
8+
9+
namespace JSON
10+
{
11+
template <typename T, template <typename, class = std::allocator <T> > class ContainerT,
12+
class = typename std::enable_if<Internal::can_stringify<typename ContainerT<T>::value_type>::value>::type >
13+
std::ostream& stringify (std::ostream& stream, std::string const& name, ContainerT <T> values, StringificationOptions const& options = DEFAULT_OPTIONS,
14+
typename std::enable_if<has_bidirectional_iterator<T, ContainerT>::value>::type* = nullptr)
15+
{
16+
Internal::stringify_i(stream, name, values, options);
17+
return stream;
18+
}
19+
}
20+
21+
#endif // JSS_BIDIRECTIONAL_H_INCLUDED

stringify/jss_bitset.hpp

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
#ifndef JSS_BITSET_H_INCLUDED
2+
#define JSS_BITSET_H_INCLUDED
3+
4+
#include "jss_core.hpp"
5+
#include <bitset>
6+
#include <iostream>
7+
8+
namespace JSON
9+
{
10+
template <size_t Size, size_t TemplateRecursionMax = TemplateRecursionMaximum>
11+
std::ostream& stringify (std::ostream& stream, std::string const& name, std::bitset<Size> const& values, StringificationOptions const& options = DEFAULT_OPTIONS)
12+
{
13+
WRITE_ARRAY_START(stream);
14+
for (unsigned i = 0; i < Size - 1; ++i)
15+
{
16+
stream << values[i];
17+
stream << options.delimiter;
18+
}
19+
stream << values[Size - 1];
20+
WRITE_ARRAY_END(stream);
21+
return stream;
22+
}
23+
24+
template <size_t Size>
25+
std::ostream& stringify (std::ostream& stream, std::string const& name, std::bitset<Size> const& values, StringificationOptions const& options = DEFAULT_OPTIONS,
26+
typename std::enable_if <Size==0>::type* = nullptr)
27+
{
28+
WRITE_ARRAY_START(stream);
29+
WRITE_ARRAY_END(stream);
30+
return stream;
31+
}
32+
}
33+
34+
#endif // JSS_BITSET_H_INCLUDED

stringify/jss_check.hpp

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
#ifndef JSS_CHECK_H_INCLUDED
2+
#define JSS_CHECK_H_INCLUDED
3+
4+
#include "jss_core.hpp"
5+
#include <sstream>
6+
#include <utility>
7+
8+
namespace JSON { namespace Internal {
9+
10+
class StreamMock : public std::ostream {};
11+
static StreamMock _smock;
12+
13+
template <typename T>
14+
class can_stringify_1
15+
{
16+
template<typename U>
17+
static char check(...);
18+
template<typename U>
19+
static char (&check(decltype(stringify(std::declval<std::ostream&>(), std::declval<std::string const>(), std::declval<U>(), std::declval<StringificationOptions const>()))))[2];
20+
public:
21+
static const bool value = sizeof(check<T> (_smock)) == 2;
22+
};
23+
24+
template <typename T>
25+
class can_stringify_2
26+
{
27+
template<typename U>
28+
static char check(...);
29+
template<typename U>
30+
static char (&check(decltype(stringify(std::declval<std::ostream&>(), std::declval<std::string const>(), std::declval<U>(), std::declval<StringificationOptions>()))))[2];
31+
public:
32+
static const bool value = sizeof(check<T> (_smock)) == 2;
33+
};
34+
35+
template <typename T>
36+
struct can_stringify
37+
{
38+
static const bool value = can_stringify_1<T>::value || can_stringify_2<T>::value;
39+
};
40+
41+
}
42+
}
43+
44+
#endif // JSS_CHECK_H_INCLUDED

stringify/jss_container.hpp

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
#ifndef JSS_CONTAINER_H_INCLUDED
2+
#define JSS_CONTAINER_H_INCLUDED
3+
4+
#include "jss_core.hpp"
5+
#include "jss_object.hpp"
6+
#include "jss_check.hpp"
7+
#include "jss_optional.hpp"
8+
#include <functional>
9+
10+
namespace JSON { namespace Internal
11+
{
12+
template <typename T, template <typename, class = std::allocator <T> > class ContainerT,
13+
typename FuncT = std::function <typename ContainerT<T>::const_iterator(ContainerT<T> const&)>,
14+
class = typename std::enable_if<Internal::can_stringify<typename ContainerT<T>::value_type>::value>::type >
15+
inline std::ostream& stringify_i(std::ostream& stream, std::string const& name, ContainerT <T> const& values, StringificationOptions const& options = DEFAULT_OPTIONS)
16+
{
17+
using namespace Internal;
18+
19+
WRITE_ARRAY_START(stream);
20+
auto noNameOption = options;
21+
noNameOption.ignore_name = true;
22+
23+
bool first = true;
24+
for (auto const& i : values)
25+
{
26+
if (Internal::is_optional_set(i))
27+
{
28+
if (!first)
29+
stream << options.delimiter;
30+
stringify(stream, {}, i, noNameOption);
31+
first = false;
32+
}
33+
}
34+
WRITE_ARRAY_END(stream);
35+
return stream;
36+
}
37+
} // Internal
38+
} // JSON
39+
40+
#endif // JSS_CONTAINER_H_INCLUDED

stringify/jss_convenience.hpp

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
#ifndef JSS_CONVENIENCE_H_INCLUDED
2+
#define JSS_CONVENIENCE_H_INCLUDED
3+
4+
#include "jss_core.hpp"
5+
#include "jss_check.hpp"
6+
7+
8+
namespace JSON
9+
{
10+
template <typename T>
11+
std::ostream& try_stringify(std::ostream& stream, std::string const& name, T const& obj, StringificationOptions const& options = DEFAULT_OPTIONS,
12+
typename std::enable_if <Internal::can_stringify<T>::value, void>::type* = nullptr)
13+
{
14+
stringify(stream, name, obj, options);
15+
return stream;
16+
}
17+
18+
template <typename T>
19+
std::ostream& try_stringify(std::ostream& stream, std::string const&, T const&, StringificationOptions const& = DEFAULT_OPTIONS,
20+
typename std::enable_if <!Internal::can_stringify<T>::value, int>::type* = nullptr)
21+
{
22+
static_assert (Internal::can_stringify<T>::value, "the object you try to convert is not convertible to JSON");
23+
return stream;
24+
}
25+
}
26+
27+
#define json_serialize(NAME, STREAM) JSON::try_stringify(STREAM, #NAME, NAME)
28+
#define json_serialize_opt(NAME, STREAM, OPTIONS) JSON::try_stringify(STREAM, #NAME, NAME, OPTIONS)
29+
30+
#endif // JSS_CONVENIENCE_H_INCLUDED

0 commit comments

Comments
 (0)