[FUNCTION_WRAPPER] Add ostream overload approach#100
Conversation
|
Hmmm, what about a inline approach to avoid cpp files. I could even pregenerate the implementation for enums // Color.hpp
#pragma once
#include <iostream>
namespace MyProject {
enum class Color { Red, Green, Blue };
// Must be marked 'inline' if fully defined in the header!
inline std::ostream& operator<<(std::ostream& os, Color color) {
// ... implementation ...
return os;
}
}
I just looked at your approach in more in-depth. I think it is a bit too much: if I want to add a stream overload for a type, I have to touch I think it can be reduced to two file(changes) per object type: namespace OpenSHC {
namespace Audio {
namespace MSS {
// Declared as inline to make it possible to put them in .hpp files
inline std::ostream& operator<<(std::ostream& os, UnkSoundFlagsAndLoopCount const& value)
{
return os << "{loopCount=" << value.loopCount << ", flagsUnk=0x" << std::hex << std::setw(2)
<< std::setfill('0') << static_cast<int>(value.flagsUnk) << std::dec << "}";
}
}
}
}
#ifdef OPEN_SHC_DLL
#include "OStreamOverloadsSupport.hpp" // and add the .cpp to the build process, or make the helper functions also inline!
#include "./OpenSHC/Audio/mss/UnkSoundFlagsAndLoopCount.hpp"
#endif // OPEN_SHC_DLL
I don't think the goal of the ostream logger is to log all functions at once, but only a subset of all 3600 functions we are going to implement, so |
|
So 3 files, basically (2 base and 1 for every overload)? The issue is that the function resolver needs to be aware of the overloads. |
c3692ab to
c070e25
Compare
Closes #28.
As draft first, since I went with a rather strange approach, I guess.
My thoughts were essentially:
I went with the not recommended, unusual cpp-include, building basically one cpp file that I added to core.
So I went with the most complicated first.
I can backpaddle if I overdid it:
What do you think?
Being honest I was actually going with one file, but then I thought about the enums. But the enums as they are used in the function parameters are not enums currently, but aliased ints, etc, so as of now, there is nothing to gain by overloading enums anyway.
Unless we switch the int aliased enums in the function parameters to the actual enum type and only use the int version in case of structs...