forked from KhronosGroup/Vulkan-Hpp
-
Notifications
You must be signed in to change notification settings - Fork 0
/
VulkanHppGenerator.cpp
4396 lines (3966 loc) · 154 KB
/
VulkanHppGenerator.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
// Copyright(c) 2015-2016, NVIDIA CORPORATION. All rights reserved.
//
// 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.
#include <cassert>
#include <algorithm>
#include <fstream>
#include <functional>
#include <iostream>
#include <iterator>
#include <list>
#include <map>
#include <set>
#include <sstream>
#include <string>
#include <vector>
#include <exception>
#include <regex>
#include <iterator>
#include <tinyxml2.h>
const std::string exceptionHeader = R"(
#if defined(_MSC_VER) && (_MSC_VER == 1800)
# define noexcept _NOEXCEPT
#endif
class ErrorCategoryImpl : public std::error_category
{
public:
virtual const char* name() const noexcept override { return "vk::Result"; }
virtual std::string message(int ev) const override { return to_string(static_cast<Result>(ev)); }
};
#if defined(_MSC_VER) && (_MSC_VER == 1800)
# undef noexcept
#endif
VULKAN_HPP_INLINE const std::error_category& errorCategory()
{
static ErrorCategoryImpl instance;
return instance;
}
VULKAN_HPP_INLINE std::error_code make_error_code(Result e)
{
return std::error_code(static_cast<int>(e), errorCategory());
}
VULKAN_HPP_INLINE std::error_condition make_error_condition(Result e)
{
return std::error_condition(static_cast<int>(e), errorCategory());
}
)";
const std::string exceptionClassesHeader = R"(
#if defined(_MSC_VER) && (_MSC_VER == 1800)
# define noexcept _NOEXCEPT
#endif
class Error
{
public:
virtual ~Error() = default;
virtual const char* what() const noexcept = 0;
};
class LogicError : public Error, public std::logic_error
{
public:
explicit LogicError( const std::string& what )
: Error(), std::logic_error(what) {}
explicit LogicError( char const * what )
: Error(), std::logic_error(what) {}
virtual ~LogicError() = default;
virtual const char* what() const noexcept { return std::logic_error::what(); }
};
class SystemError : public Error, public std::system_error
{
public:
SystemError( std::error_code ec )
: Error(), std::system_error(ec) {}
SystemError( std::error_code ec, std::string const& what )
: Error(), std::system_error(ec, what) {}
SystemError( std::error_code ec, char const * what )
: Error(), std::system_error(ec, what) {}
SystemError( int ev, std::error_category const& ecat )
: Error(), std::system_error(ev, ecat) {}
SystemError( int ev, std::error_category const& ecat, std::string const& what)
: Error(), std::system_error(ev, ecat, what) {}
SystemError( int ev, std::error_category const& ecat, char const * what)
: Error(), std::system_error(ev, ecat, what) {}
virtual ~SystemError() = default;
virtual const char* what() const noexcept { return std::system_error::what(); }
};
#if defined(_MSC_VER) && (_MSC_VER == 1800)
# undef noexcept
#endif
)";
const std::string flagsHeader = R"(
template <typename FlagBitsType> struct FlagTraits
{
enum { allFlags = 0 };
};
template <typename BitType, typename MaskType = VkFlags>
class Flags
{
public:
Flags()
: m_mask(0)
{
}
Flags(BitType bit)
: m_mask(static_cast<MaskType>(bit))
{
}
Flags(Flags<BitType> const& rhs)
: m_mask(rhs.m_mask)
{
}
Flags<BitType> & operator=(Flags<BitType> const& rhs)
{
m_mask = rhs.m_mask;
return *this;
}
Flags<BitType> & operator|=(Flags<BitType> const& rhs)
{
m_mask |= rhs.m_mask;
return *this;
}
Flags<BitType> & operator&=(Flags<BitType> const& rhs)
{
m_mask &= rhs.m_mask;
return *this;
}
Flags<BitType> & operator^=(Flags<BitType> const& rhs)
{
m_mask ^= rhs.m_mask;
return *this;
}
Flags<BitType> operator|(Flags<BitType> const& rhs) const
{
Flags<BitType> result(*this);
result |= rhs;
return result;
}
Flags<BitType> operator&(Flags<BitType> const& rhs) const
{
Flags<BitType> result(*this);
result &= rhs;
return result;
}
Flags<BitType> operator^(Flags<BitType> const& rhs) const
{
Flags<BitType> result(*this);
result ^= rhs;
return result;
}
bool operator!() const
{
return !m_mask;
}
Flags<BitType> operator~() const
{
Flags<BitType> result(*this);
result.m_mask ^= FlagTraits<BitType>::allFlags;
return result;
}
bool operator==(Flags<BitType> const& rhs) const
{
return m_mask == rhs.m_mask;
}
bool operator!=(Flags<BitType> const& rhs) const
{
return m_mask != rhs.m_mask;
}
explicit operator bool() const
{
return !!m_mask;
}
explicit operator MaskType() const
{
return m_mask;
}
private:
MaskType m_mask;
};
template <typename BitType>
Flags<BitType> operator|(BitType bit, Flags<BitType> const& flags)
{
return flags | bit;
}
template <typename BitType>
Flags<BitType> operator&(BitType bit, Flags<BitType> const& flags)
{
return flags & bit;
}
template <typename BitType>
Flags<BitType> operator^(BitType bit, Flags<BitType> const& flags)
{
return flags ^ bit;
}
)";
const std::string optionalClassHeader = R"(
template <typename RefType>
class Optional
{
public:
Optional(RefType & reference) { m_ptr = &reference; }
Optional(RefType * ptr) { m_ptr = ptr; }
Optional(std::nullptr_t) { m_ptr = nullptr; }
operator RefType*() const { return m_ptr; }
RefType const* operator->() const { return m_ptr; }
explicit operator bool() const { return !!m_ptr; }
private:
RefType *m_ptr;
};
)";
const std::string arrayProxyHeader = R"(
#ifndef VULKAN_HPP_DISABLE_ENHANCED_MODE
template <typename T>
class ArrayProxy
{
public:
ArrayProxy(std::nullptr_t)
: m_count(0)
, m_ptr(nullptr)
{}
ArrayProxy(T & ptr)
: m_count(1)
, m_ptr(&ptr)
{}
ArrayProxy(uint32_t count, T * ptr)
: m_count(count)
, m_ptr(ptr)
{}
template <size_t N>
ArrayProxy(std::array<typename std::remove_const<T>::type, N> & data)
: m_count(N)
, m_ptr(data.data())
{}
template <size_t N>
ArrayProxy(std::array<typename std::remove_const<T>::type, N> const& data)
: m_count(N)
, m_ptr(data.data())
{}
template <class Allocator = std::allocator<typename std::remove_const<T>::type>>
ArrayProxy(std::vector<typename std::remove_const<T>::type, Allocator> & data)
: m_count(static_cast<uint32_t>(data.size()))
, m_ptr(data.data())
{}
template <class Allocator = std::allocator<typename std::remove_const<T>::type>>
ArrayProxy(std::vector<typename std::remove_const<T>::type, Allocator> const& data)
: m_count(static_cast<uint32_t>(data.size()))
, m_ptr(data.data())
{}
ArrayProxy(std::initializer_list<T> const& data)
: m_count(static_cast<uint32_t>(data.end() - data.begin()))
, m_ptr(data.begin())
{}
const T * begin() const
{
return m_ptr;
}
const T * end() const
{
return m_ptr + m_count;
}
const T & front() const
{
assert(m_count && m_ptr);
return *m_ptr;
}
const T & back() const
{
assert(m_count && m_ptr);
return *(m_ptr + m_count - 1);
}
bool empty() const
{
return (m_count == 0);
}
uint32_t size() const
{
return m_count;
}
T * data() const
{
return m_ptr;
}
private:
uint32_t m_count;
T * m_ptr;
};
#endif
)";
const std::string structureChainHeader = R"(
template <typename X, typename Y> constexpr bool isStructureChainValid() { return false; }
template <class Element>
class StructureChainElement
{
public:
explicit operator Element&() { return value; }
explicit operator const Element&() const { return value; }
private:
Element value;
};
template<typename ...StructureElements>
class StructureChain : private StructureChainElement<StructureElements>...
{
public:
StructureChain()
{
link<StructureElements...>();
}
StructureChain(StructureChain const &rhs)
{
linkAndCopy<StructureElements...>(rhs);
}
StructureChain& operator=(StructureChain const &rhs)
{
linkAndCopy(rhs);
return this;
}
template<typename ClassType> ClassType& get() { return static_cast<ClassType&>(*this);}
private:
template<typename X>
void link()
{
}
template<typename X, typename Y, typename ...Z>
void link()
{
static_assert(isStructureChainValid<X,Y>(), "The structure chain is not valid!");
X& x = static_cast<X&>(*this);
Y& y = static_cast<Y&>(*this);
x.pNext = &y;
link<Y, Z...>();
}
template<typename X>
void linkAndCopy(StructureChain const &rhs)
{
static_cast<X&>(*this) = static_cast<X const &>(rhs);
}
template<typename X, typename Y, typename ...Z>
void linkAndCopy(StructureChain const &rhs)
{
static_assert(isStructureChainValid<X,Y>(), "The structure chain is not valid!");
X& x = static_cast<X&>(*this);
Y& y = static_cast<Y&>(*this);
x = static_cast<X const &>(rhs);
x.pNext = &y;
linkAndCopy<Y, Z...>(rhs);
}
};
)";
const std::string versionCheckHeader = R"(
#if !defined(VULKAN_HPP_HAS_UNRESTRICTED_UNIONS)
# if defined(__clang__)
# if __has_feature(cxx_unrestricted_unions)
# define VULKAN_HPP_HAS_UNRESTRICTED_UNIONS
# endif
# elif defined(__GNUC__)
# define GCC_VERSION (__GNUC__ * 10000 + __GNUC_MINOR__ * 100 + __GNUC_PATCHLEVEL__)
# if 40600 <= GCC_VERSION
# define VULKAN_HPP_HAS_UNRESTRICTED_UNIONS
# endif
# elif defined(_MSC_VER)
# if 1900 <= _MSC_VER
# define VULKAN_HPP_HAS_UNRESTRICTED_UNIONS
# endif
# endif
#endif
)";
const std::string inlineHeader = R"(
#if !defined(VULKAN_HPP_INLINE)
# if defined(__clang___)
# if __has_attribute(always_inline)
# define VULKAN_HPP_INLINE __attribute__((always_inline)) __inline__
# else
# define VULKAN_HPP_INLINE inline
# endif
# elif defined(__GNUC__)
# define VULKAN_HPP_INLINE __attribute__((always_inline)) __inline__
# elif defined(_MSC_VER)
# define VULKAN_HPP_INLINE __forceinline
# else
# define VULKAN_HPP_INLINE inline
# endif
#endif
)";
const std::string explicitHeader = R"(
#if defined(VULKAN_HPP_TYPESAFE_CONVERSION)
# define VULKAN_HPP_TYPESAFE_EXPLICIT
#else
# define VULKAN_HPP_TYPESAFE_EXPLICIT explicit
#endif
)";
const std::string resultValueHeader = R"(
template <typename T>
struct ResultValue
{
ResultValue( Result r, T & v )
: result( r )
, value( v )
{}
Result result;
T value;
operator std::tuple<Result&, T&>() { return std::tuple<Result&, T&>(result, value); }
};
template <typename T>
struct ResultValueType
{
#ifdef VULKAN_HPP_NO_EXCEPTIONS
typedef ResultValue<T> type;
#else
typedef T type;
#endif
};
template <>
struct ResultValueType<void>
{
#ifdef VULKAN_HPP_NO_EXCEPTIONS
typedef Result type;
#else
typedef void type;
#endif
};
)";
const std::string createResultValueHeader = R"(
VULKAN_HPP_INLINE ResultValueType<void>::type createResultValue( Result result, char const * message )
{
#ifdef VULKAN_HPP_NO_EXCEPTIONS
assert( result == Result::eSuccess );
return result;
#else
if ( result != Result::eSuccess )
{
throwResultException( result, message );
}
#endif
}
template <typename T>
VULKAN_HPP_INLINE typename ResultValueType<T>::type createResultValue( Result result, T & data, char const * message )
{
#ifdef VULKAN_HPP_NO_EXCEPTIONS
assert( result == Result::eSuccess );
return ResultValue<T>( result, data );
#else
if ( result != Result::eSuccess )
{
throwResultException( result, message );
}
return data;
#endif
}
VULKAN_HPP_INLINE Result createResultValue( Result result, char const * message, std::initializer_list<Result> successCodes )
{
#ifdef VULKAN_HPP_NO_EXCEPTIONS
assert( std::find( successCodes.begin(), successCodes.end(), result ) != successCodes.end() );
#else
if ( std::find( successCodes.begin(), successCodes.end(), result ) == successCodes.end() )
{
throwResultException( result, message );
}
#endif
return result;
}
template <typename T>
VULKAN_HPP_INLINE ResultValue<T> createResultValue( Result result, T & data, char const * message, std::initializer_list<Result> successCodes )
{
#ifdef VULKAN_HPP_NO_EXCEPTIONS
assert( std::find( successCodes.begin(), successCodes.end(), result ) != successCodes.end() );
#else
if ( std::find( successCodes.begin(), successCodes.end(), result ) == successCodes.end() )
{
throwResultException( result, message );
}
#endif
return ResultValue<T>( result, data );
}
)";
const std::string uniqueHandleHeader = R"(
#if defined(VULKAN_HPP_NO_EXCEPTIONS) && !defined(VULKAN_HPP_NO_SMART_HANDLE)
# define VULKAN_HPP_NO_SMART_HANDLE
#endif
#ifndef VULKAN_HPP_NO_SMART_HANDLE
template <typename Type, typename Deleter>
class UniqueHandle
{
public:
explicit UniqueHandle( Type const& value = Type(), Deleter const& deleter = Deleter() )
: m_value( value )
, m_deleter( deleter )
{}
UniqueHandle( UniqueHandle const& ) = delete;
UniqueHandle( UniqueHandle && other )
: m_value( other.release() )
, m_deleter( std::move( other.m_deleter ) )
{}
~UniqueHandle()
{
destroy();
}
UniqueHandle & operator=( UniqueHandle const& ) = delete;
UniqueHandle & operator=( UniqueHandle && other )
{
reset( other.release() );
m_deleter = std::move( other.m_deleter );
return *this;
}
explicit operator bool() const
{
return m_value.operator bool();
}
Type const* operator->() const
{
return &m_value;
}
Type const& operator*() const
{
return m_value;
}
Type get() const
{
return m_value;
}
Deleter & getDeleter()
{
return m_deleter;
}
Deleter const& getDeleter() const
{
return m_deleter;
}
void reset( Type const& value = Type() )
{
if ( m_value != value )
{
destroy();
m_value = value;
}
}
Type release()
{
Type value = m_value;
m_value = nullptr;
return value;
}
void swap( UniqueHandle<Type, Deleter> & rhs )
{
std::swap(m_value, rhs.m_value);
std::swap(m_deleter, rhs.m_deleter);
}
private:
void destroy()
{
if ( m_value )
{
m_deleter( m_value );
}
}
private:
Type m_value;
Deleter m_deleter;
};
template <typename Type, typename Deleter>
VULKAN_HPP_INLINE void swap( UniqueHandle<Type,Deleter> & lhs, UniqueHandle<Type,Deleter> & rhs )
{
lhs.swap( rhs );
}
#endif
)";
std::string replaceWithMap(std::string const &input, std::map<std::string, std::string> replacements)
{
// This will match ${someVariable} and contain someVariable in match group 1
std::regex re(R"(\$\{([^\}]+)\})");
auto it = std::sregex_iterator(input.begin(), input.end(), re);
auto end = std::sregex_iterator();
// No match, just return the original string
if (it == end)
{
return input;
}
std::string result = "";
while (it != end)
{
std::smatch match = *it;
auto itReplacement = replacements.find(match[1].str());
assert(itReplacement != replacements.end());
result += match.prefix().str() + ((itReplacement != replacements.end()) ? itReplacement->second : match[0].str());
++it;
// we've passed the last match. Append the rest of the orignal string
if (it == end)
{
result += match.suffix().str();
}
}
return result;
}
struct ParamData
{
std::string type;
std::string name;
std::string arraySize;
std::string pureType;
std::string len;
bool optional;
};
struct CommandData
{
CommandData(std::string const& t, std::string const& fn)
: returnType(t)
, fullName(fn)
, returnParam(~0)
, templateParam(~0)
, twoStep(false)
{}
std::string className;
std::string enhancedReturnType;
std::string fullName;
std::vector<ParamData> params;
std::string protect;
std::string reducedName;
size_t returnParam;
std::string returnType;
std::set<size_t> skippedParams;
std::vector<std::string> successCodes;
size_t templateParam;
bool twoStep;
std::map<size_t, size_t> vectorParams;
};
struct DependencyData
{
enum class Category
{
COMMAND,
ENUM,
FLAGS,
FUNC_POINTER,
HANDLE,
REQUIRED,
SCALAR,
STRUCT,
UNION
};
DependencyData(Category c, std::string const& n)
: category(c)
, name(n)
{}
Category category;
std::string name;
std::set<std::string> dependencies;
std::set<std::string> forwardDependencies;
};
struct NameValue
{
std::string name;
std::string value;
};
struct EnumData
{
EnumData(std::string const& n, bool b = false)
: name(n)
, bitmask(b)
{}
void addEnumMember(std::string const& name, std::string const& tag);
std::string name;
std::string prefix;
std::string postfix;
std::vector<NameValue> members;
std::string protect;
bool bitmask;
};
struct FlagData
{
std::string protect;
};
struct HandleData
{
std::vector<std::string> commands;
std::string protect;
};
struct ScalarData
{
std::string protect;
};
struct MemberData
{
std::string type;
std::string name;
std::string arraySize;
std::string pureType;
};
struct StructData
{
StructData()
: returnedOnly(false)
{}
bool returnedOnly;
bool isUnion;
std::vector<MemberData> members;
std::string protect;
std::vector<std::string> structExtends;
};
struct DeleterData
{
std::string pool;
std::string call;
};
struct VkData
{
std::map<std::string, CommandData> commands;
std::list<DependencyData> dependencies;
std::map<std::string, std::set<std::string>> deleterTypes; // map from parent type to set of child types
std::map<std::string, DeleterData> deleterData; // map from child types to corresponding deleter data
std::map<std::string, EnumData> enums;
std::map<std::string, FlagData> flags;
std::map<std::string, HandleData> handles;
std::map<std::string, ScalarData> scalars;
std::map<std::string, StructData> structs;
std::set<std::string> extendedStructs; // structs which are referenced by the structextends tag
std::set<std::string> tags;
std::string typesafeCheck;
std::string version;
std::set<std::string> vkTypes;
std::string vulkanLicenseHeader;
};
void createDefaults( VkData const& vkData, std::map<std::string,std::string> & defaultValues );
void determineEnhancedReturnType(CommandData & commandData);
void determineReducedName(CommandData & commandData);
void determineReturnParam(CommandData & commandData);
void determineSkippedParams(CommandData & commandData);
void determineTemplateParam(CommandData & commandData);
void determineVectorParams(CommandData & commandData);
void enterProtect(std::ostream &os, std::string const& protect);
std::string extractTag(std::string const& name);
std::string findTag(std::string const& name, std::set<std::string> const& tags);
std::string generateEnumNameForFlags(std::string const& name);
bool hasPointerParam(std::vector<ParamData> const& params);
void leaveProtect(std::ostream &os, std::string const& protect);
void linkCommandToHandle(VkData & vkData, CommandData & commandData);
std::string readArraySize(tinyxml2::XMLNode * node, std::string& name);
bool readCommandParam( tinyxml2::XMLElement * element, std::set<std::string> & dependencies, std::vector<ParamData> & params );
void readCommandParams(tinyxml2::XMLElement* element, std::set<std::string> & dependencies, CommandData & commandData);
tinyxml2::XMLNode* readCommandParamType(tinyxml2::XMLNode* node, ParamData& param);
CommandData& readCommandProto(tinyxml2::XMLElement * element, VkData & vkData);
void readCommands( tinyxml2::XMLElement * element, VkData & vkData );
void readCommandsCommand(tinyxml2::XMLElement * element, VkData & vkData);
std::vector<std::string> readCommandSuccessCodes(tinyxml2::XMLElement* element, std::set<std::string> const& tags);
void readComment(tinyxml2::XMLElement * element, std::string & header);
void readEnums( tinyxml2::XMLElement * element, VkData & vkData );
void readEnumsEnum( tinyxml2::XMLElement * element, EnumData & enumData );
void readDisabledExtensionRequire(tinyxml2::XMLElement * element, VkData & vkData);
void readExtensionCommand(tinyxml2::XMLElement * element, std::map<std::string, CommandData> & commands, std::string const& protect);
void readExtensionEnum(tinyxml2::XMLElement * element, std::map<std::string, EnumData> & enums, std::string const& tag);
void readExtensionRequire(tinyxml2::XMLElement * element, VkData & vkData, std::string const& protect, std::string const& tag);
void readExtensions( tinyxml2::XMLElement * element, VkData & vkData );
void readExtensionsExtension(tinyxml2::XMLElement * element, VkData & vkData);
void readExtensionType(tinyxml2::XMLElement * element, VkData & vkData, std::string const& protect);
tinyxml2::XMLNode* readType(tinyxml2::XMLNode* element, std::string & type, std::string & pureType);
void readTypeBasetype( tinyxml2::XMLElement * element, std::list<DependencyData> & dependencies );
void readTypeBitmask( tinyxml2::XMLElement * element, VkData & vkData);
void readTypeDefine( tinyxml2::XMLElement * element, VkData & vkData );
void readTypeFuncpointer( tinyxml2::XMLElement * element, std::list<DependencyData> & dependencies );
void readTypeHandle(tinyxml2::XMLElement * element, VkData & vkData);
void readTypeStruct( tinyxml2::XMLElement * element, VkData & vkData, bool isUnion );
void readTypeStructMember( tinyxml2::XMLElement * element, VkData & vkData, StructData & structData );
void readTags(tinyxml2::XMLElement * element, std::set<std::string> & tags);
void readTypes(tinyxml2::XMLElement * element, VkData & vkData);
std::string reduceName(std::string const& name, bool singular = false);
void registerDeleter(VkData & vkData, CommandData const& commandData);
std::string startLowerCase(std::string const& input);
std::string startUpperCase(std::string const& input);
void sortDependencies( std::list<DependencyData> & dependencies );
std::string strip(std::string const& value, std::string const& prefix, std::string const& postfix = std::string());
std::string stripPluralS(std::string const& name);
std::string toCamelCase(std::string const& value);
std::string toUpperCase(std::string const& name);
std::string trimEnd(std::string const& input);
void writeCall(std::ostream & os, CommandData const& commandData, std::set<std::string> const& vkTypes, bool firstCall, bool singular);
std::string generateCall(CommandData const& commandData, std::set<std::string> const& vkTypes, bool firstCall, bool singular);
void writeCallCountParameter(std::ostream & os, CommandData const& commandData, bool singular, std::map<size_t, size_t>::const_iterator it);
void writeCallParameter(std::ostream & os, ParamData const& paramData, std::set<std::string> const& vkTypes);
void writeCallPlainTypeParameter(std::ostream & os, ParamData const& paramData);
void writeCallVectorParameter(std::ostream & os, CommandData const& commandData, std::set<std::string> const& vkTypes, bool firstCall, bool singular, std::map<size_t, size_t>::const_iterator it);
void writeCallVulkanTypeParameter(std::ostream & os, ParamData const& paramData);
void writeDeleterClasses(std::ostream & os, std::pair<std::string, std::set<std::string>> const& deleterTypes, std::map<std::string, DeleterData> const& deleterData);
void writeDeleterForwardDeclarations(std::ostream &os, std::pair<std::string, std::set<std::string>> const& deleterTypes, std::map<std::string, DeleterData> const& deleterData);
void writeEnumsToString(std::ostream & os, EnumData const& enumData);
void writeFlagsToString(std::ostream & os, std::string const& flagsName, EnumData const &enumData);
void writeFunction(std::ostream & os, std::string const& indentation, VkData const& vkData, CommandData const& commandData, bool definition, bool enhanced, bool singular, bool unique, bool isStructureChain);
void writeFunctionBodyEnhanced(std::ostream & os, std::string const& indentation, VkData const& vkData, CommandData const& commandData, bool singular, bool isStructureChain);
void writeFunctionBodyEnhancedCall(std::ostream &os, std::string const& indentation, std::set<std::string> const& vkTypes, CommandData const& commandData, bool singular);
void writeFunctionBodyEnhancedCallResult(std::ostream &os, std::string const& indentation, std::set<std::string> const& vkTypes, CommandData const& commandData, bool singular);
void writeFunctionBodyEnhancedCallTwoStep(std::ostream & os, std::string const& indentation, std::set<std::string> const& vkTypes, std::string const& returnName, std::string const& sizeName, CommandData const& commandData);
void writeFunctionBodyEnhancedCallTwoStepChecked(std::ostream & os, std::string const& indentation, std::set<std::string> const& vkTypes, std::string const& returnName, std::string const& sizeName, CommandData const& commandData);
void writeFunctionBodyEnhancedCallTwoStepIterate(std::ostream & os, std::string const& indentation, std::set<std::string> const& vkTypes, std::string const& returnName, std::string const& sizeName, CommandData const& commandData);
void writeFunctionBodyEnhancedLocalCountVariable(std::ostream & os, std::string const& indentation, CommandData const& commandData);
std::string writeFunctionBodyEnhancedLocalReturnVariable(std::ostream & os, std::string const& indentation, CommandData const& commandData, bool singular, bool isStructureChain);
void writeFunctionBodyEnhancedMultiVectorSizeCheck(std::ostream & os, std::string const& indentation, CommandData const& commandData);
void writeFunctionBodyEnhancedReturnResultValue(std::ostream & os, std::string const& indentation, std::string const& returnName, CommandData const& commandData, bool singular);
void writeFunctionBodyStandard(std::ostream & os, std::string const& indentation, VkData const& vkData, CommandData const& commandData);
void writeFunctionBodyUnique(std::ostream & os, std::string const& indentation, VkData const& vkData, CommandData const& commandData, bool singular);
void writeFunctionHeaderArguments(std::ostream & os, VkData const& vkData, CommandData const& commandData, bool enhanced, bool singular, bool withDefaults);
void writeFunctionHeaderArgumentsEnhanced(std::ostream & os, VkData const& vkData, CommandData const& commandData, bool singular, bool withDefaults);
void writeFunctionHeaderArgumentsStandard(std::ostream & os, CommandData const& commandData);
void writeFunctionHeaderName(std::ostream & os, std::string const& name, bool singular, bool unique);
void writeFunctionHeaderReturnType(std::ostream & os, std::string const& indentation, CommandData const& commandData, bool enhanced, bool singular, bool unique, bool isStructureChain);
void writeFunctionHeaderTemplate(std::ostream & os, std::string const& indentation, CommandData const& commandData, bool withDefault, bool isStructureChain);
void writeReinterpretCast(std::ostream & os, bool leadingConst, bool vulkanType, std::string const& type, bool trailingPointerToConst);
void writeStandardOrEnhanced(std::ostream & os, std::string const& standard, std::string const& enhanced);
void writeStructConstructor( std::ostream & os, std::string const& name, StructData const& structData, std::set<std::string> const& vkTypes, std::map<std::string,std::string> const& defaultValues );
void writeStructSetter( std::ostream & os, std::string const& structureName, MemberData const& memberData, std::set<std::string> const& vkTypes, std::map<std::string,StructData> const& structs );
void writeTypeCommand(std::ostream & os, VkData const& vkData, DependencyData const& dependencyData);
void writeTypeCommand(std::ostream &os, std::string const& indentation, VkData const& vkData, CommandData const& commandData, bool definition);
void writeTypeEnum(std::ostream & os, EnumData const& enumData);
bool isErrorEnum(std::string const& enumName);
std::string stripErrorEnumPrefix(std::string const& enumName);
void writeExceptionsForEnum(std::ostream & os, EnumData const& enumData);
void writeThrowExceptions(std::ostream& os, EnumData const& enumData);
void writeTypeFlags(std::ostream & os, std::string const& flagsName, FlagData const& flagData, EnumData const& enumData);
void writeTypeHandle(std::ostream & os, VkData const& vkData, DependencyData const& dependencyData, HandleData const& handle, std::list<DependencyData> const& dependencies);
void writeTypeScalar( std::ostream & os, DependencyData const& dependencyData );
void writeTypeStruct( std::ostream & os, VkData const& vkData, DependencyData const& dependencyData, std::map<std::string,std::string> const& defaultValues );
void writeTypeUnion( std::ostream & os, VkData const& vkData, DependencyData const& dependencyData, std::map<std::string,std::string> const& defaultValues );
void writeTypes(std::ostream & os, VkData const& vkData, std::map<std::string, std::string> const& defaultValues);
void writeVersionCheck(std::ostream & os, std::string const& version);
void writeTypesafeCheck(std::ostream & os, std::string const& typesafeCheck);
void EnumData::addEnumMember(std::string const &name, std::string const& tag)
{
NameValue nv;
nv.name = "e" + toCamelCase(strip(name, prefix, postfix));
nv.value = name;
if (bitmask)
{
size_t pos = nv.name.find("Bit");
if (pos != std::string::npos)
{
nv.name.erase(pos, 3);
}
}
if (!tag.empty() && (nv.name.substr(nv.name.length() - tag.length()) == toCamelCase(tag)))
{
nv.name = nv.name.substr(0, nv.name.length() - tag.length()) + tag;
}
members.push_back(nv);
}
void createDefaults( VkData const& vkData, std::map<std::string,std::string> & defaultValues )
{
for (auto dependency : vkData.dependencies)
{
assert( defaultValues.find( dependency.name ) == defaultValues.end() );
switch( dependency.category )
{
case DependencyData::Category::COMMAND : // commands should never be asked for defaults
break;
case DependencyData::Category::ENUM :
{
assert(vkData.enums.find(dependency.name) != vkData.enums.end());
EnumData const & enumData = vkData.enums.find(dependency.name)->second;
if (!enumData.members.empty())
{
defaultValues[dependency.name] = dependency.name + "::" + vkData.enums.find(dependency.name)->second.members.front().name;
}
else
{
defaultValues[dependency.name] = dependency.name + "()";
}
}
break;
case DependencyData::Category::FLAGS :
case DependencyData::Category::HANDLE: