Split basic_types.h into separate independent headers

This commit is contained in:
baldurk
2019-12-16 17:05:11 +00:00
parent 61660ad37a
commit 8e21b28785
14 changed files with 225 additions and 212 deletions
+3
View File
@@ -85,6 +85,9 @@ class QMenu;
// we depend on the internal RenderDoc API, but the bindings for that are imported entirely
#include "renderdoc_replay.h"
typedef rdcpair<rdcstr, rdcstr> rdcstrpair;
typedef rdcarray<rdcstrpair> rdcstrpairs;
struct ICaptureContext;
#include "Analytics.h"
@@ -122,7 +122,6 @@ SIMPLE_TYPEMAPS_VARIANT(SimpleType, SimpleType &)
DECLARE_STRINGISE_TYPE(float);
DECLARE_STRINGISE_TYPE(double);
DECLARE_STRINGISE_TYPE(rdcstr);
DECLARE_STRINGISE_TYPE(rdcstrpair);
%}
+2
View File
@@ -69,6 +69,8 @@ TEMPLATE_ARRAY_DECLARE(rdcarray);
#ifndef slots
#define slots
#endif
DECLARE_STRINGISE_TYPE(rdcstrpair);
%}
%include <stdint.i>
+5 -6
View File
@@ -79,8 +79,11 @@
%typemap(in) xcb_connection_t* = HWND;
%typemap(in) wl_surface* = HWND;
// completely ignore rdcdatetime, we custom convert to/from a native python datetime
// completely ignore types that we custom convert to/from a native python type
%ignore rdcdatetime;
%ignore rdcstr;
%ignore rdcliteral;
%ignore rdcpair;
// special handling for RENDERDOC_GetDefaultCaptureOptions to transform output parameter to a return value
%typemap(in, numinputs=0) CaptureOptions *defaultOpts { $1 = new CaptureOptions; }
@@ -153,10 +156,6 @@
%ignore rdcarray::removeOne;
%ignore rdcarray::operator=;
%ignore rdcarray::operator[];
%ignore rdcstr::operator=;
%ignore rdcstr::operator std::string;
%ignore rdcpair::operator=;
%ignore rdcpair::swap;
// simple typemap to delete old byte arrays in a buffer list before assigning the new one
%typemap(memberin) StructuredBufferList {
@@ -211,7 +210,7 @@ TEMPLATE_ARRAY_DECLARE(rdcarray);
%include <stdint.i>
%include "renderdoc_replay.h"
%include "basic_types.h"
%include "rdcarray.h"
%include "stringise.h"
%include "structured_data.h"
%include "capture_options.h"
+1 -1
View File
@@ -29,7 +29,7 @@
#define CATCH_CONFIG_FORCE_FALLBACK_STRINGIFIER
#define CATCH_CONFIG_INLINE_DEBUG_BREAK
#include "api/replay/basic_types.h"
#include "api/replay/rdcstr.h"
#include "api/replay/stringise.h"
#include "official/catch.hpp"
+4 -1
View File
@@ -95,7 +95,10 @@ endif()
set(sources
api/app/renderdoc_app.h
api/replay/basic_types.h
api/replay/rdcarray.h
api/replay/rdcdatetime.h
api/replay/rdcstr.h
api/replay/rdcpair.h
api/replay/stringise.h
api/replay/structured_data.h
api/replay/capture_options.h
@@ -25,170 +25,17 @@
#pragma once
#include <stdint.h>
#include <stdlib.h>
#include <string.h>
#include <string>
#include <stdint.h> // for standard types
#include <string.h> // for memcpy, etc
#include <initializer_list>
#include <type_traits>
#include <vector>
typedef uint8_t byte;
#ifndef DOCUMENT
#define DOCUMENT(text)
#ifdef RENDERDOC_EXPORTS
#include <stdlib.h> // for malloc/free
void RENDERDOC_OutOfMemory(uint64_t sz);
#endif
#ifndef DOCUMENT2
#define DOCUMENT2(text1, text2)
#endif
#ifndef DOCUMENT3
#define DOCUMENT3(text1, text2, text3)
#endif
#ifndef DOCUMENT4
#define DOCUMENT4(text1, text2, text3, text4)
#endif
// primarily here just to remove a dependency on QDateTime in the Qt UI, so we don't have to bind
// against Qt at all in the interface.
DOCUMENT("");
struct rdcdatetime
{
DOCUMENT("");
int32_t year = 0;
int32_t month = 0;
int32_t day = 0;
int32_t hour = 0;
int32_t minute = 0;
int32_t second = 0;
int32_t microsecond = 0;
rdcdatetime() = default;
rdcdatetime(int y, int mn, int d, int h = 0, int m = 0, int s = 0, int us = 0)
: year(y), month(mn), day(d), hour(h), minute(m), second(s), microsecond(us)
{
}
bool operator==(const rdcdatetime &o) const
{
return year == o.year && month == o.month && day == o.day && hour == o.hour &&
minute == o.minute && second == o.second && microsecond == o.microsecond;
}
bool operator!=(const rdcdatetime &o) const { return !(*this == o); }
bool operator<(const rdcdatetime &o) const
{
if(year != o.year)
return year < o.year;
if(month != o.month)
return month < o.month;
if(day != o.day)
return day < o.day;
if(hour != o.hour)
return hour < o.hour;
if(minute != o.minute)
return minute < o.minute;
if(second != o.second)
return second < o.second;
if(microsecond != o.microsecond)
return microsecond < o.microsecond;
return false;
}
#if defined(RENDERDOC_QT_COMPAT)
rdcdatetime(const QDateTime &in)
{
year = in.date().year();
month = in.date().month();
day = in.date().day();
hour = in.time().hour();
minute = in.time().minute();
second = in.time().second();
microsecond = in.time().msec() * 1000;
}
operator QDateTime() const
{
return QDateTime(QDate(year, month, day), QTime(hour, minute, second, microsecond / 1000));
}
operator QVariant() const { return QVariant(QDateTime(*this)); }
#endif
};
// here we define our own data structures that are ABI compatible between modules, as STL is not
// safe to pass a module boundary.
template <typename A, typename B>
struct rdcpair
{
A first;
B second;
rdcpair(const A &a, const B &b) : first(a), second(b) {}
rdcpair() = default;
rdcpair(const rdcpair<A, B> &o) = default;
rdcpair(rdcpair<A, B> &&o) = default;
~rdcpair() = default;
inline void swap(rdcpair<A, B> &o)
{
std::swap(first, o.first);
std::swap(second, o.second);
}
template <typename A_, typename B_>
rdcpair<A, B> &operator=(const rdcpair<A_, B_> &o)
{
first = o.first;
second = o.second;
return *this;
}
rdcpair<A, B> &operator=(const rdcpair<A, B> &o)
{
first = o.first;
second = o.second;
return *this;
}
bool operator==(const rdcpair<A, B> &o) const { return first == o.first && second == o.second; }
bool operator<(const rdcpair<A, B> &o) const
{
if(first != o.first)
return first < o.first;
return second < o.second;
}
};
template <typename A, typename B>
rdcpair<A, B> make_rdcpair(const A &a, const B &b)
{
return rdcpair<A, B>(a, b);
}
template <typename A, typename B>
rdcpair<A &, B &> rdctie(A &a, B &b)
{
return rdcpair<A &, B &>(a, b);
}
// utility class that adds a NULL terminator to array operations only if T == char
template <typename T>
struct null_terminator
{
// adds 1 to every allocation to ensure we have space. Happens invisibly so even capacity()
// doesn't know about it
inline static size_t allocCount(size_t c) { return c; }
// adds the NULL terminator after a resize operation
inline static void fixup(T *elems, size_t count) {}
};
template <>
struct null_terminator<char>
{
inline static size_t allocCount(size_t c) { return c + 1; }
// indexing 'off the end' of elems is safe because we over-allocated above
inline static void fixup(char *elems, size_t count) { elems[count] = 0; }
};
template <typename T, bool isStd = std::is_trivial<T>::value>
struct ItemHelper
{
@@ -267,10 +114,6 @@ struct ItemDestroyHelper<T, true>
static void destroyRange(T *first, size_t itemCount) {}
};
#ifdef RENDERDOC_EXPORTS
void RENDERDOC_OutOfMemory(uint64_t sz);
#endif
template <typename T>
struct rdcarray
{
@@ -302,12 +145,7 @@ protected:
#endif
}
inline void setUsedCount(size_t newCount)
{
usedCount = newCount;
null_terminator<T>::fixup(elems, usedCount);
}
inline void setUsedCount(size_t newCount) { usedCount = newCount; }
public:
typedef T value_type;
@@ -360,14 +198,6 @@ public:
void reserve(size_t s)
{
// if we're empty then normally reserving s==0 would do nothing, but if we need to append a null
// terminator then we do actually need to allocate
if(s == 0 && capacity() == 0 && elems == NULL && null_terminator<T>::allocCount(0) > 0)
{
elems = allocate(null_terminator<T>::allocCount(0));
return;
}
// nothing to do if we already have this much space. We only size up
if(s <= capacity())
return;
@@ -377,7 +207,7 @@ public:
if(size_t(allocatedCount) * 2 > s)
s = size_t(allocatedCount) * 2;
T *newElems = allocate(null_terminator<T>::allocCount(s));
T *newElems = allocate(s);
// when elems is NULL, usedCount should also be 0, but add an extra check in here just to
// satisfy coverity's static analysis which can't figure that out from the copy constructor
@@ -686,8 +516,6 @@ public:
// copy construct the new elems
ItemCopyHelper<T>::copyRange(elems, in.data(), usedCount);
null_terminator<T>::fixup(elems, usedCount);
return *this;
}
@@ -709,8 +537,6 @@ public:
i++;
}
null_terminator<T>::fixup(elems, usedCount);
return *this;
}
@@ -731,8 +557,6 @@ public:
// copy construct the new elems
ItemCopyHelper<T>::copyRange(elems, in.data(), usedCount);
null_terminator<T>::fixup(elems, usedCount);
return *this;
}
@@ -802,9 +626,8 @@ public:
#endif
};
#include "rdcstr.h"
typedef uint8_t byte;
DOCUMENT("");
struct bytebuf : public rdcarray<byte>
{
bytebuf() : rdcarray<byte>() {}
@@ -821,6 +644,3 @@ struct bytebuf : public rdcarray<byte>
}
#endif
};
typedef rdcpair<rdcstr, rdcstr> rdcstrpair;
typedef rdcarray<rdcstrpair> rdcstrpairs;
+91
View File
@@ -0,0 +1,91 @@
/******************************************************************************
* The MIT License (MIT)
*
* Copyright (c) 2015-2019 Baldur Karlsson
* Copyright (c) 2014 Crytek
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
******************************************************************************/
#pragma once
#include <stdint.h>
// primarily here just to remove a dependency on QDateTime in the Qt UI, so we don't have to bind
// against Qt at all in the interface.
struct rdcdatetime
{
int32_t year = 0;
int32_t month = 0;
int32_t day = 0;
int32_t hour = 0;
int32_t minute = 0;
int32_t second = 0;
int32_t microsecond = 0;
rdcdatetime() = default;
rdcdatetime(int y, int mn, int d, int h = 0, int m = 0, int s = 0, int us = 0)
: year(y), month(mn), day(d), hour(h), minute(m), second(s), microsecond(us)
{
}
bool operator==(const rdcdatetime &o) const
{
return year == o.year && month == o.month && day == o.day && hour == o.hour &&
minute == o.minute && second == o.second && microsecond == o.microsecond;
}
bool operator!=(const rdcdatetime &o) const { return !(*this == o); }
bool operator<(const rdcdatetime &o) const
{
if(year != o.year)
return year < o.year;
if(month != o.month)
return month < o.month;
if(day != o.day)
return day < o.day;
if(hour != o.hour)
return hour < o.hour;
if(minute != o.minute)
return minute < o.minute;
if(second != o.second)
return second < o.second;
if(microsecond != o.microsecond)
return microsecond < o.microsecond;
return false;
}
#if defined(RENDERDOC_QT_COMPAT)
rdcdatetime(const QDateTime &in)
{
year = in.date().year();
month = in.date().month();
day = in.date().day();
hour = in.time().hour();
minute = in.time().minute();
second = in.time().second();
microsecond = in.time().msec() * 1000;
}
operator QDateTime() const
{
return QDateTime(QDate(year, month, day), QTime(hour, minute, second, microsecond / 1000));
}
operator QVariant() const { return QVariant(QDateTime(*this)); }
#endif
};
+80
View File
@@ -0,0 +1,80 @@
/******************************************************************************
* The MIT License (MIT)
*
* Copyright (c) 2015-2019 Baldur Karlsson
* Copyright (c) 2014 Crytek
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
******************************************************************************/
#pragma once
template <typename A, typename B>
struct rdcpair
{
A first;
B second;
rdcpair(const A &a, const B &b) : first(a), second(b) {}
rdcpair() = default;
rdcpair(const rdcpair<A, B> &o) = default;
rdcpair(rdcpair<A, B> &&o) = default;
~rdcpair() = default;
inline void swap(rdcpair<A, B> &o)
{
rdcpair<A, B> tmp = *this;
*this = o;
o = tmp;
}
template <typename A_, typename B_>
rdcpair<A, B> &operator=(const rdcpair<A_, B_> &o)
{
first = o.first;
second = o.second;
return *this;
}
rdcpair<A, B> &operator=(const rdcpair<A, B> &o)
{
first = o.first;
second = o.second;
return *this;
}
bool operator==(const rdcpair<A, B> &o) const { return first == o.first && second == o.second; }
bool operator<(const rdcpair<A, B> &o) const
{
if(first != o.first)
return first < o.first;
return second < o.second;
}
};
template <typename A, typename B>
rdcpair<A, B> make_rdcpair(const A &a, const B &b)
{
return rdcpair<A, B>(a, b);
}
template <typename A, typename B>
rdcpair<A &, B &> rdctie(A &a, B &b)
{
return rdcpair<A &, B &>(a, b);
}
+7 -7
View File
@@ -24,10 +24,16 @@
#pragma once
#include <stdint.h> // for standard types
#include <string.h> // for memcpy, etc
#include <string>
#ifdef RENDERDOC_EXPORTS
#include <stdlib.h> // for malloc/free
void RENDERDOC_OutOfMemory(uint64_t sz);
#endif
// special type for storing literals. This allows functions to force callers to pass them literals
DOCUMENT("");
class rdcliteral
{
const char *str;
@@ -49,11 +55,6 @@ inline rdcliteral operator"" _lit(const char *str, size_t len)
return rdcliteral(str, len);
}
#ifdef RENDERDOC_EXPORTS
void RENDERDOC_OutOfMemory(uint64_t sz);
#endif
DOCUMENT("");
class rdcstr
{
private:
@@ -128,7 +129,6 @@ private:
/////////////////////////////////////////////////////////////////
// memory management, in a dll safe way
DOCUMENT("");
static char *allocate(size_t count)
{
char *ret = NULL;
+9 -2
View File
@@ -105,7 +105,7 @@
#define RENDERDOC_API RENDERDOC_IMPORT_API
#endif
// needs to be declared up here for reference in basic_types
// needs to be declared up here for reference in rdcarray/rdcstr
extern "C" RENDERDOC_API void RENDERDOC_CC RENDERDOC_FreeArrayMem(void *mem);
typedef void(RENDERDOC_CC *pRENDERDOC_FreeArrayMem)(void *mem);
@@ -302,7 +302,14 @@ private:
#endif
};
#include "basic_types.h"
DOCUMENT("");
typedef uint8_t byte;
#include "rdcdatetime.h"
#include "rdcpair.h"
#include "rdcarray.h"
#include "rdcstr.h"
#include "stringise.h"
#include "structured_data.h"
+2 -1
View File
@@ -26,7 +26,8 @@
#pragma once
#include <stdint.h>
#include "basic_types.h"
#include "rdcarray.h"
#include "rdcstr.h"
#include "replay_enums.h"
DOCUMENT("A ``float`` 4 component vector.")
+3 -1
View File
@@ -157,7 +157,7 @@
<ClInclude Include="android\android_utils.h" />
<ClInclude Include="android\jdwp.h" />
<ClInclude Include="api\app\renderdoc_app.h" />
<ClInclude Include="api\replay\basic_types.h" />
<ClInclude Include="api\replay\rdcdatetime.h" />
<ClInclude Include="api\replay\capture_options.h" />
<ClInclude Include="api\replay\common_pipestate.h" />
<ClInclude Include="api\replay\control_types.h" />
@@ -166,6 +166,8 @@
<ClInclude Include="api\replay\data_types.h" />
<ClInclude Include="api\replay\gl_pipestate.h" />
<ClInclude Include="api\replay\pipestate.h" />
<ClInclude Include="api\replay\rdcarray.h" />
<ClInclude Include="api\replay\rdcpair.h" />
<ClInclude Include="api\replay\rdcstr.h" />
<ClInclude Include="api\replay\renderdoc_replay.h" />
<ClInclude Include="api\replay\replay_enums.h" />
+9 -3
View File
@@ -204,9 +204,6 @@
<ClInclude Include="maths\half_convert.h">
<Filter>Common\Maths</Filter>
</ClInclude>
<ClInclude Include="api\replay\basic_types.h">
<Filter>API\Replay</Filter>
</ClInclude>
<ClInclude Include="api\replay\control_types.h">
<Filter>API\Replay</Filter>
</ClInclude>
@@ -489,6 +486,15 @@
<ClInclude Include="core\remote_server.h">
<Filter>Core\networking</Filter>
</ClInclude>
<ClInclude Include="api\replay\rdcarray.h">
<Filter>API\Replay</Filter>
</ClInclude>
<ClInclude Include="api\replay\rdcpair.h">
<Filter>API\Replay</Filter>
</ClInclude>
<ClInclude Include="api\replay\rdcdatetime.h">
<Filter>API\Replay</Filter>
</ClInclude>
</ItemGroup>
<ItemGroup>
<ClCompile Include="maths\camera.cpp">