Skip to content

Commit

Permalink
Renamed Types.hpp to Utilities.hpp and moved TypeTraits and ForwardDe…
Browse files Browse the repository at this point in the history
…clarations into their own file.
  • Loading branch information
playmer committed Mar 22, 2017
1 parent 67e94ab commit 609e4ba
Show file tree
Hide file tree
Showing 9 changed files with 115 additions and 98 deletions.
3 changes: 2 additions & 1 deletion Reflection/Any.hpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#pragma once

#include "Types.hpp"
#include "ForwardDeclarations.hpp"
#include "Utilities.hpp"
#include "Type.hpp"


Expand Down
1 change: 1 addition & 0 deletions Reflection/Field.hpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#pragma once

#include "Property.hpp"
#include "TypeTraits.hpp"

class Field : public Property
{
Expand Down
7 changes: 7 additions & 0 deletions Reflection/ForwardDeclarations.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#pragma once

class DocumentedObject;
class Field;
class Function;
class Property;
class Type;
2 changes: 1 addition & 1 deletion Reflection/Property.hpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#pragma once

#include "Types.hpp"
#include "Utilities.hpp"
#include "Function.hpp"

// TODO: Have some requirements on the types of setters and getters.
Expand Down
4 changes: 3 additions & 1 deletion Reflection/Reflection.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -129,13 +129,15 @@
<ClInclude Include="CacheOrderedMultiMap.hpp" />
<ClInclude Include="ConstexprString.hpp" />
<ClInclude Include="Field.hpp" />
<ClInclude Include="ForwardDeclarations.hpp" />
<ClInclude Include="Function.hpp" />
<ClInclude Include="Iterator.hpp" />
<ClInclude Include="Property.hpp" />
<ClInclude Include="Range.hpp" />
<ClInclude Include="Reflection.hpp" />
<ClInclude Include="Type.hpp" />
<ClInclude Include="Types.hpp" />
<ClInclude Include="Utilities.hpp" />
<ClInclude Include="TypeTraits.hpp" />
</ItemGroup>
<ItemGroup>
<ClCompile Include="Attribute.cpp" />
Expand Down
12 changes: 9 additions & 3 deletions Reflection/Reflection.vcxproj.filters
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,6 @@
<ClInclude Include="Reflection.hpp">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="Types.hpp">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="Any.hpp">
<Filter>Header Files</Filter>
</ClInclude>
Expand Down Expand Up @@ -54,6 +51,15 @@
<ClInclude Include="CacheOrderedMultiMap.hpp">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="TypeTraits.hpp">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="Utilities.hpp">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="ForwardDeclarations.hpp">
<Filter>Header Files</Filter>
</ClInclude>
</ItemGroup>
<ItemGroup>
<ClCompile Include="main.cpp">
Expand Down
3 changes: 2 additions & 1 deletion Reflection/Type.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@
#include <vector>

#include "CacheOrderedMultiMap.hpp"
#include "Types.hpp"
#include "ForwardDeclarations.hpp"
#include "Utilities.hpp"
#include "Reflection.hpp"

class Type;
Expand Down
95 changes: 4 additions & 91 deletions Reflection/Types.hpp → Reflection/TypeTraits.hpp
Original file line number Diff line number Diff line change
@@ -1,52 +1,6 @@
//////////////////////////////////////////////
// Author: Joshua T. Fisher
//////////////////////////////////////////////
#pragma once

#ifndef Types_hpp
#define Types_hpp

#include <cstdint>

#include <memory>
#include <string>
#include <unordered_map>

using byte = std::uint8_t;

using s8 = signed char;
using s16 = signed short;
using s32 = signed int;
using s64 = signed long long;

using i8 = char;
using i16 = std::int16_t;
using i32 = std::int32_t;
using i64 = std::int64_t;

using u8 = std::uint8_t;
using u16 = std::uint16_t;
using u32 = std::uint32_t;
using u64 = std::uint64_t;

class Function;
class Property;
class Field;

inline void runtime_assert(bool aValue, const char *aMessage = "")
{
if (false == aValue)
{
printf("ASSERT: %s\n", aMessage);

// Intentionally crashing the program.
int *base = nullptr;
*base = 1;
}
}

// We want to be able to use the string literals, this is the only way.
using namespace std::string_literals;
#include "Utilities.hpp"

template<typename T>
inline size_t SizeOf()
Expand Down Expand Up @@ -152,9 +106,9 @@ struct Identity


template<typename T>
struct remove_all_pointers : std::conditional_t<std::is_pointer_v<T>,
remove_all_pointers<std::remove_pointer_t<T>>,
Identity<T>>
struct remove_all_pointers : std::conditional_t<std::is_pointer_v<T>,
remove_all_pointers<std::remove_pointer_t<T>>,
Identity<T>>
{
};

Expand Down Expand Up @@ -197,44 +151,3 @@ inline void GenericDoNothing(byte *aMemory)
{
}


enum class StringComparison
{
String1Null, // (We check this first)
LesserInString1, // The first character that does not match has a lower value in ptr1 than in ptr2
Equal,
GreaterInString1,// The first character that does not match has a greater value in ptr1 than in ptr2
String2Null, // (We check this Second)
};

inline StringComparison StringCompare(const char *aLeft, const char *aRight)
{
if (nullptr == aLeft)
{
return StringComparison::String1Null;
}

if (nullptr == aRight)
{
return StringComparison::String2Null;
}

auto comparison = std::strcmp(aLeft, aRight);

if (0 == comparison)
{
return StringComparison::Equal;
}

if (comparison < 0)
{
return StringComparison::LesserInString1;
}

// else if (comparison < 0) This is by definition of the domain, no need to check
{
return StringComparison::GreaterInString1;
}
}

#endif
86 changes: 86 additions & 0 deletions Reflection/Utilities.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
//////////////////////////////////////////////
// Author: Joshua T. Fisher
//////////////////////////////////////////////
#pragma once

#ifndef Utilities_hpp
#define Utilities_hpp

#include <cstdint>

#include <memory>
#include <string>
#include <unordered_map>

using byte = std::uint8_t;

using s8 = signed char;
using s16 = signed short;
using s32 = signed int;
using s64 = signed long long;

using i8 = char;
using i16 = std::int16_t;
using i32 = std::int32_t;
using i64 = std::int64_t;

using u8 = std::uint8_t;
using u16 = std::uint16_t;
using u32 = std::uint32_t;
using u64 = std::uint64_t;

inline void runtime_assert(bool aValue, const char *aMessage = "")
{
if (false == aValue)
{
printf("ASSERT: %s\n", aMessage);

// Intentionally crashing the program.
int *base = nullptr;
*base = 1;
}
}

// We want to be able to use the string literals, this is the only way.
using namespace std::string_literals;

enum class StringComparison
{
String1Null, // (We check this first)
LesserInString1, // The first character that does not match has a lower value in ptr1 than in ptr2
Equal,
GreaterInString1,// The first character that does not match has a greater value in ptr1 than in ptr2
String2Null, // (We check this Second)
};

inline StringComparison StringCompare(const char *aLeft, const char *aRight)
{
if (nullptr == aLeft)
{
return StringComparison::String1Null;
}

if (nullptr == aRight)
{
return StringComparison::String2Null;
}

auto comparison = std::strcmp(aLeft, aRight);

if (0 == comparison)
{
return StringComparison::Equal;
}

if (comparison < 0)
{
return StringComparison::LesserInString1;
}

// else if (comparison < 0) This is by definition of the domain, no need to check
{
return StringComparison::GreaterInString1;
}
}

#endif

0 comments on commit 609e4ba

Please sign in to comment.