123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160 |
- /**
- * Triangles
- * Copyright (C) 2016 POSITIVE MENTAL ATTITUDE
- *
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation, version 3 of the License.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
- #pragma once
- #include <iostream>
- /**
- * @class Rect
- * @author POSITIVE MENTAL ATTITUDE
- * @date 06/09/16
- * @file Utility.hpp
- * @brief Helper class for box collision.
- */
- struct Rect
- {
- float left, right, top, bottom;
- };
- /**
- * @class Echo
- * @author POSITIVE MENTAL ATTITUDE
- * @date 06/09/16
- * @file Utility.hpp
- * @brief Helper class for stdout/stderr output.
- */
- class Echo
- {
- public:
- enum
- {
- Empty, Info, Load, Debug, Error
- };
-
- Echo() = default;
-
- template<typename Type, typename... Args>
- static void out(int prefix, Type out, Args... args);
-
- template<typename Type, typename... Args>
- static void debug(Type out, Args... args);
-
- template<typename Type, typename... Args>
- static void info(Type out, Args... args);
-
- template<typename Type, typename... Args>
- static void load(Type out, Args... args);
-
- template<typename Type, typename... Args>
- static void error(Type out, Args... args);
- static void out(std::string debug);
- static void out(float debug);
- static void setLogLevel(int loglevel);
- private:
- static void helper(bool err, std::wstring out);
-
- template <typename T>
- static void helper(bool err, T out);
- template<typename Type, typename... Args>
- static void helper(bool err, const Type out, Args... args);
- static bool printType(int order);
-
- static int _loglevel;
- };
- template <typename Type>
- void Echo::helper(bool err, Type out)
- {
- if(err)
- std::cerr << out;
- else
- std::cout << out;
- }
- template<typename Type, typename... Args>
- void Echo::helper(bool err, const Type out, Args... args)
- {
- if(err)
- std::cerr << out;
- else
- std::cout << out;
- helper(err, args...);
- }
- template<typename Type, typename... Args>
- void Echo::out(int order, Type out, Args... args)
- {
- if(!printType(order))
- return;
- if(order == Error)
- {
- helper(true, out, args...);
- std::cerr << std::endl;
- }
- else
- {
- helper(false, out, args...);
- std::cout << std::endl;
- }
- }
- template<typename Type, typename... Args>
- void Echo::debug(Type out, Args... args)
- {
- if(!printType(Debug))
- return;
- helper(false, out, args...);
- std::cout << std::endl;
- }
- template<typename Type, typename... Args>
- void Echo::info(Type out, Args... args)
- {
- if(!printType(Info))
- return;
- helper(false, out, args...);
- std::cout << std::endl;
- }
- template<typename Type, typename... Args>
- void Echo::load(Type out, Args... args)
- {
- if(!printType(Load))
- return;
- helper(false, out, args...);
- std::cout << std::endl;
- }
- template<typename Type, typename... Args>
- void Echo::error(Type out, Args... args)
- {
- if(!printType(Error))
- return;
- helper(true, out, args...);
- std::cerr << std::endl;
- }
|