]> git.tdb.fi Git - ext/openal.git/blob - al/eax/call.h
Import OpenAL Soft 1.23.1 sources
[ext/openal.git] / al / eax / call.h
1 #ifndef EAX_EAX_CALL_INCLUDED
2 #define EAX_EAX_CALL_INCLUDED
3
4 #include "AL/al.h"
5 #include "alnumeric.h"
6 #include "alspan.h"
7 #include "api.h"
8 #include "fx_slot_index.h"
9
10 enum class EaxCallType {
11     none,
12     get,
13     set,
14 }; // EaxCallType
15
16 enum class EaxCallPropertySetId {
17     none,
18     context,
19     fx_slot,
20     source,
21     fx_slot_effect,
22 }; // EaxCallPropertySetId
23
24 class EaxCall {
25 public:
26     EaxCall(
27         EaxCallType type,
28         const GUID& property_set_guid,
29         ALuint property_id,
30         ALuint property_source_id,
31         ALvoid* property_buffer,
32         ALuint property_size);
33
34     bool is_get() const noexcept { return mCallType == EaxCallType::get; }
35     bool is_deferred() const noexcept { return mIsDeferred; }
36     int get_version() const noexcept { return mVersion; }
37     EaxCallPropertySetId get_property_set_id() const noexcept { return mPropertySetId; }
38     ALuint get_property_id() const noexcept { return mPropertyId; }
39     ALuint get_property_al_name() const noexcept { return mPropertySourceId; }
40     EaxFxSlotIndex get_fx_slot_index() const noexcept { return mFxSlotIndex; }
41
42     template<typename TException, typename TValue>
43     TValue& get_value() const
44     {
45         if(mPropertyBufferSize < sizeof(TValue))
46             fail_too_small();
47
48         return *static_cast<TValue*>(mPropertyBuffer);
49     }
50
51     template<typename TValue>
52     al::span<TValue> get_values(size_t max_count) const
53     {
54         if(max_count == 0 || mPropertyBufferSize < sizeof(TValue))
55             fail_too_small();
56
57         const auto count = minz(mPropertyBufferSize / sizeof(TValue), max_count);
58         return al::as_span(static_cast<TValue*>(mPropertyBuffer), count);
59     }
60
61     template<typename TValue>
62     al::span<TValue> get_values() const
63     {
64         return get_values<TValue>(~size_t{});
65     }
66
67     template<typename TException, typename TValue>
68     void set_value(const TValue& value) const
69     {
70         get_value<TException, TValue>() = value;
71     }
72
73 private:
74     const EaxCallType mCallType;
75     int mVersion;
76     EaxFxSlotIndex mFxSlotIndex;
77     EaxCallPropertySetId mPropertySetId;
78     bool mIsDeferred;
79
80     const ALuint mPropertyId;
81     const ALuint mPropertySourceId;
82     ALvoid*const mPropertyBuffer;
83     const ALuint mPropertyBufferSize;
84
85     [[noreturn]] static void fail(const char* message);
86     [[noreturn]] static void fail_too_small();
87 }; // EaxCall
88
89 EaxCall create_eax_call(
90     EaxCallType type,
91     const GUID* property_set_id,
92     ALuint property_id,
93     ALuint property_source_id,
94     ALvoid* property_buffer,
95     ALuint property_size);
96
97 #endif // !EAX_EAX_CALL_INCLUDED