Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

Reflection #6

Merged
merged 3 commits into from
Oct 28, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions include/mif/common/creator.h
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
//-------------------------------------------------------------------
// MetaInfo Framework (MIF)
// https://github.com/tdv/mif
// Created: 09.2016
// Copyright (C) 2016 tdv
//-------------------------------------------------------------------

#ifndef __MIF_COMMON_CREATOR_H__
#define __MIF_COMMON_CREATOR_H__

Expand Down
7 changes: 7 additions & 0 deletions include/mif/common/detail/hierarchy.h
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
//-------------------------------------------------------------------
// MetaInfo Framework (MIF)
// https://github.com/tdv/mif
// Created: 09.2016
// Copyright (C) 2016 tdv
//-------------------------------------------------------------------

#ifndef __MIF_COMMON_HIERARCHY_H__
#define __MIF_COMMON_HIERARCHY_H__

Expand Down
7 changes: 7 additions & 0 deletions include/mif/common/detail/method.h
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
//-------------------------------------------------------------------
// MetaInfo Framework (MIF)
// https://github.com/tdv/mif
// Created: 09.2016
// Copyright (C) 2016 tdv
//-------------------------------------------------------------------

#ifndef __MIF_COMMON_DETAIL_METHOD_H__
#define __MIF_COMMON_DETAIL_METHOD_H__

Expand Down
7 changes: 7 additions & 0 deletions include/mif/common/index_sequence.h
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
//-------------------------------------------------------------------
// MetaInfo Framework (MIF)
// https://github.com/tdv/mif
// Created: 09.2016
// Copyright (C) 2016 tdv
//-------------------------------------------------------------------

#ifndef __MIF_COMMON_INDEX_SEQUENCE_H__
#define __MIF_COMMON_INDEX_SEQUENCE_H__

Expand Down
61 changes: 61 additions & 0 deletions include/mif/common/static_string.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
//-------------------------------------------------------------------
// MetaInfo Framework (MIF)
// https://github.com/tdv/mif
// Created: 10.2016
// Copyright (C) 2016 tdv
//-------------------------------------------------------------------

#ifndef __MIF_COMMON_STATIC_STRING_H__
#define __MIF_COMMON_STATIC_STRING_H__

// STD
#include <cstdint>
#include <string>

// MIF
#include "mif/common/index_sequence.h"

#define MIF_DECLARE_SRTING_PROVIDER(name_, value_) \
struct name_ \
{ \
static constexpr char const* GetString() \
{ \
return value_; \
} \
static constexpr char GetSize() \
{ \
return sizeof(value_); \
} \
};

namespace Mif
{
namespace Common
{

template <char ... Str>
struct StaticString
{
static std::string const GetString()
{
return { Str ... };
}
};

namespace Detail
{

template <typename TStringProvider, std::size_t ... Indexes>
constexpr StaticString<TStringProvider::GetString()[Indexes] ... > MakeStaticString(IndexSequence<Indexes ... > const *);

} // namespace Detail

template <typename TStringProvider>
using MakeStaticString = decltype(Detail::MakeStaticString<TStringProvider>(
static_cast<MakeIndexSequence<TStringProvider::GetSize()> const *>(nullptr)));

} // namespace Common
} // namespace Mif


#endif // !__MIF_COMMON_STATIC_STRING_H__
7 changes: 7 additions & 0 deletions include/mif/common/thread_pool.h
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
//-------------------------------------------------------------------
// MetaInfo Framework (MIF)
// https://github.com/tdv/mif
// Created: 09.2016
// Copyright (C) 2016 tdv
//-------------------------------------------------------------------

#ifndef __MIF_COMMON_THREAD_POOL_H__
#define __MIF_COMMON_THREAD_POOL_H__

Expand Down
7 changes: 7 additions & 0 deletions include/mif/common/types.h
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
//-------------------------------------------------------------------
// MetaInfo Framework (MIF)
// https://github.com/tdv/mif
// Created: 09.2016
// Copyright (C) 2016 tdv
//-------------------------------------------------------------------

#ifndef __MIF_COMMON_TYPES_H__
#define __MIF_COMMON_TYPES_H__

Expand Down
7 changes: 7 additions & 0 deletions include/mif/common/uuid_generator.h
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
//-------------------------------------------------------------------
// MetaInfo Framework (MIF)
// https://github.com/tdv/mif
// Created: 09.2016
// Copyright (C) 2016 tdv
//-------------------------------------------------------------------

#ifndef __MIF_COMMON_UUID_GENERATOR_H__
#define __MIF_COMMON_UUID_GENERATOR_H__

Expand Down
7 changes: 7 additions & 0 deletions include/mif/net/client.h
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
//-------------------------------------------------------------------
// MetaInfo Framework (MIF)
// https://github.com/tdv/mif
// Created: 09.2016
// Copyright (C) 2016 tdv
//-------------------------------------------------------------------

#ifndef __MIF_NET_CLIENT_H__
#define __MIF_NET_CLIENT_H__

Expand Down
7 changes: 7 additions & 0 deletions include/mif/net/client_factory.h
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
//-------------------------------------------------------------------
// MetaInfo Framework (MIF)
// https://github.com/tdv/mif
// Created: 09.2016
// Copyright (C) 2016 tdv
//-------------------------------------------------------------------

#ifndef __MIF_NET_CLIENT_FACTORY_H__
#define __MIF_NET_CLIENT_FACTORY_H__

Expand Down
7 changes: 7 additions & 0 deletions include/mif/net/clients/frame_reader.h
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
//-------------------------------------------------------------------
// MetaInfo Framework (MIF)
// https://github.com/tdv/mif
// Created: 09.2016
// Copyright (C) 2016 tdv
//-------------------------------------------------------------------

#ifndef __MIF_NET_CLIENTS_FRAME_READER_H__
#define __MIF_NET_CLIENTS_FRAME_READER_H__

Expand Down
7 changes: 7 additions & 0 deletions include/mif/net/clients/frame_writer.h
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
//-------------------------------------------------------------------
// MetaInfo Framework (MIF)
// https://github.com/tdv/mif
// Created: 09.2016
// Copyright (C) 2016 tdv
//-------------------------------------------------------------------

#ifndef __MIF_NET_CLIENTS_FRAME_WRITER_H__
#define __MIF_NET_CLIENTS_FRAME_WRITER_H__

Expand Down
7 changes: 7 additions & 0 deletions include/mif/net/clients/gzip_compressor.h
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
//-------------------------------------------------------------------
// MetaInfo Framework (MIF)
// https://github.com/tdv/mif
// Created: 09.2016
// Copyright (C) 2016 tdv
//-------------------------------------------------------------------

#ifndef __MIF_NET_CLIENTS_GZIP_COMPRESSOR_H__
#define __MIF_NET_CLIENTS_GZIP_COMPRESSOR_H__

Expand Down
7 changes: 7 additions & 0 deletions include/mif/net/clients/gzip_decompressor.h
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
//-------------------------------------------------------------------
// MetaInfo Framework (MIF)
// https://github.com/tdv/mif
// Created: 09.2016
// Copyright (C) 2016 tdv
//-------------------------------------------------------------------

#ifndef __MIF_NET_CLIENTS_GZIP_DECOMPRESSOR_H__
#define __MIF_NET_CLIENTS_GZIP_DECOMPRESSOR_H__

Expand Down
7 changes: 7 additions & 0 deletions include/mif/net/clients_chain.h
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
//-------------------------------------------------------------------
// MetaInfo Framework (MIF)
// https://github.com/tdv/mif
// Created: 09.2016
// Copyright (C) 2016 tdv
//-------------------------------------------------------------------

#ifndef __MIF_NET_CLIENTS_CHAIN_H__
#define __MIF_NET_CLIENTS_CHAIN_H__

Expand Down
7 changes: 7 additions & 0 deletions include/mif/net/iclient_factory.h
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
//-------------------------------------------------------------------
// MetaInfo Framework (MIF)
// https://github.com/tdv/mif
// Created: 09.2016
// Copyright (C) 2016 tdv
//-------------------------------------------------------------------

#ifndef __MIF_NET_ICLIENT_FACTORY_H__
#define __MIF_NET_ICLIENT_FACTORY_H__

Expand Down
7 changes: 7 additions & 0 deletions include/mif/net/icontrol.h
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
//-------------------------------------------------------------------
// MetaInfo Framework (MIF)
// https://github.com/tdv/mif
// Created: 09.2016
// Copyright (C) 2016 tdv
//-------------------------------------------------------------------

#ifndef __MIF_NET_ICONTROL_H__
#define __MIF_NET_ICONTROL_H__

Expand Down
7 changes: 7 additions & 0 deletions include/mif/net/ihandler.h
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
//-------------------------------------------------------------------
// MetaInfo Framework (MIF)
// https://github.com/tdv/mif
// Created: 09.2016
// Copyright (C) 2016 tdv
//-------------------------------------------------------------------

#ifndef __MIF_NET_IHANDLER_H__
#define __MIF_NET_IHANDLER_H__

Expand Down
7 changes: 7 additions & 0 deletions include/mif/net/ipublisher.h
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
//-------------------------------------------------------------------
// MetaInfo Framework (MIF)
// https://github.com/tdv/mif
// Created: 09.2016
// Copyright (C) 2016 tdv
//-------------------------------------------------------------------

#ifndef __MIF_NET_IPUBLISHER_H__
#define __MIF_NET_IPUBLISHER_H__

Expand Down
7 changes: 7 additions & 0 deletions include/mif/net/tcp_clients.h
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
//-------------------------------------------------------------------
// MetaInfo Framework (MIF)
// https://github.com/tdv/mif
// Created: 09.2016
// Copyright (C) 2016 tdv
//-------------------------------------------------------------------

#ifndef __MIF_NET_TCP_CLIENTS_H__
#define __MIF_NET_TCP_CLIENTS_H__

Expand Down
7 changes: 7 additions & 0 deletions include/mif/net/tcp_server.h
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
//-------------------------------------------------------------------
// MetaInfo Framework (MIF)
// https://github.com/tdv/mif
// Created: 09.2016
// Copyright (C) 2016 tdv
//-------------------------------------------------------------------

#ifndef __MIF_NET_TCP_SERVER_H__
#define __MIF_NET_TCP_SERVER_H__

Expand Down
103 changes: 103 additions & 0 deletions include/mif/reflection/reflect_type.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,103 @@
//-------------------------------------------------------------------
// MetaInfo Framework (MIF)
// https://github.com/tdv/mif
// Created: 10.2016
// Copyright (C) 2016 tdv
//-------------------------------------------------------------------

#ifndef __MIF_REFLECTION_REFLECT_TYPE_H__
#define __MIF_REFLECTION_REFLECT_TYPE_H__

// STD
#include <tuple>

// MIF
#include "mif/common/static_string.h"
#include "mif/common/detail/hierarchy.h"

namespace Mif
{
namespace Reflection
{
namespace Detail
{

template <typename>
struct Class;

namespace Registry
{

struct None;

template <typename Key>
struct Registry
{
using Type = None;
};

} // namespace Registry
} // namespace Detail
} // namespace Reflection
} // namespace Mif

#define MIF_REFLECT_BEGIN(type_, ... ) \
class type_ ## _MetaInfo final \
{ \
private: \
template <typename> \
friend class ::Mif::Reflection::Detail::Class; \
template <typename> \
friend class ::Mif::Reflection::Detail::FieldsList; \
MIF_DECLARE_SRTING_PROVIDER(TypeNameProvider, #type_) \
using ClassType = type_; \
using BaseTypes = std::tuple<__VA_ARGS__>; \
using FakeHierarchy = ::Mif::Common::Detail::MakeHierarchy<100>; \
static char (&GetNextCounter(void *))[1];

#define MIF_REFLECT_FIELD(field_) \
struct field_ ## _MetaInfo \
{ \
MIF_DECLARE_SRTING_PROVIDER(TypeNameProvider, #field_) \
using FieldType = decltype(ClassType::field_); \
static FieldType ClassType::* Access() \
{ \
return &ClassType :: field_ ; \
} \
}; \
enum { field_ ## _Index = sizeof(GetNextCounter(static_cast<FakeHierarchy *>(nullptr))) }; \
static char (&GetNextCounter(::Mif::Common::Detail::Hierarchy<field_ ## _Index> *))[field_ ## _Index + 1]; \
static field_ ## _MetaInfo GetFieldInfo(::Mif::Common::Detail::Hierarchy<field_ ## _Index - 1>);

#define MIF_REFLECT_END() \
enum { FieldsCount = sizeof(GetNextCounter(static_cast<FakeHierarchy *>(nullptr))) }; \
};

#ifndef MIF_BOOST_TYPE_SERIALIZER
#define MIF_BOOST_TYPE_SERIALIZER(type_)
#endif // !MIF_BOOST_TYPE_SERIALIZER

#define MIF_REGISTER_REFLECTED_TYPE(type_) \
namespace Mif \
{ \
namespace Reflection \
{ \
namespace Detail \
{ \
namespace Registry \
{ \
template <> \
struct Registry<type_> \
{ \
using Type = type_ ## _MetaInfo; \
using Key = type_; \
MIF_DECLARE_SRTING_PROVIDER(TypeFullNameProvider, #type_ ) \
}; \
} \
} \
} \
} \
MIF_BOOST_TYPE_SERIALIZER(type_)


#endif // !__MIF_REFLECTION_REFLECT_TYPE_H__
Loading