Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <cstring>
- #include <type_traits>
- // strcmp(handlers[i].inputFileExtension, inputFileExtension)
- // handlers[i].inputFileExtension.cmp(inputFileExtension)
- enum Constness
- {
- Nonconst,
- NonConst = Nonconst,
- Cnst,
- Const = Cnst
- };
- template<Constness flag, typename T, typename U>
- struct Select { typedef T Result; };
- template<typename T, typename U>
- struct Select<Nonconst, T, U> { typedef U Result; };
- template <Constness isConst = Nonconst>
- struct CString
- {
- typedef typename Select<isConst, const char, char>::Result Char;
- Char * data;
- CString(Char * data)
- {
- this->data = data;
- }
- operator Char *()
- {
- return data;
- }
- Char& operator[](std::size_t idx) { return this->data[idx]; }
- Char& operator[](std::size_t idx) const { return this->data[idx]; }
- CString * operator=(CString * other)
- {
- this->data = other.data;
- return *this;
- }
- inline int cmp(const char * rhs) const {
- return std::strcmp(this->data, rhs);
- }
- };
- struct CommandHandler
- {
- CString<Const> inputFileExtension;
- CString<> outputFileExtension;
- };
- struct CommandHandler2
- {
- const char * inputFileExtension;
- char * outputFileExtension;
- };
- char png_str1[] = "png";
- char png_str2[] = "png";
- struct CommandHandler handlers[] =
- {
- { "1bpp", png_str1},
- { "4bpp", png_str2}
- };
- struct CommandHandler2 handlers2[] =
- {
- { "1bpp", png_str1},
- { "4bpp", png_str2}
- };
- int main2(const char * inputFileExtension)
- {
- if (handlers[0].inputFileExtension.cmp(inputFileExtension) == 0) {
- char t3bpp_str[] = "3bpp";
- handlers[0].outputFileExtension = t3bpp_str;
- handlers[0].inputFileExtension = "9bpp";
- return 10;
- } else {
- return 17;
- }
- }
- int main3(const char * inputFileExtension)
- {
- if (strcmp(handlers2[0].inputFileExtension, inputFileExtension) == 0) {
- char t3bpp_str[] = "3bpp";
- handlers2[0].outputFileExtension = t3bpp_str;
- handlers2[0].inputFileExtension = "9bpp";
- return 10;
- } else {
- return 17;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement