home *** CD-ROM | disk | FTP | other *** search
/ Freelog 125 / Freelog_MarsAvril2015_No125.iso / Multimedia / AVStoDVD / AVStoDVD_280_Install.exe / AVSMeter / source / avs / minmax.h < prev    next >
C/C++ Source or Header  |  2014-03-02  |  2KB  |  55 lines

  1. // This program is free software; you can redistribute it and/or modify
  2. // it under the terms of the GNU General Public License as published by
  3. // the Free Software Foundation; either version 2 of the License, or
  4. // (at your option) any later version.
  5. //
  6. // This program is distributed in the hope that it will be useful,
  7. // but WITHOUT ANY WARRANTY; without even the implied warranty of
  8. // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  9. // GNU General Public License for more details.
  10. //
  11. // You should have received a copy of the GNU General Public License
  12. // along with this program; if not, write to the Free Software
  13. // Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA, or visit
  14. // http://www.gnu.org/copyleft/gpl.html .
  15. //
  16. // Linking Avisynth statically or dynamically with other modules is making a
  17. // combined work based on Avisynth.  Thus, the terms and conditions of the GNU
  18. // General Public License cover the whole combination.
  19. //
  20. // As a special exception, the copyright holders of Avisynth give you
  21. // permission to link Avisynth with independent modules that communicate with
  22. // Avisynth solely through the interfaces defined in avisynth.h, regardless of the license
  23. // terms of these independent modules, and to copy and distribute the
  24. // resulting combined work under terms of your choice, provided that
  25. // every copy of the combined work is accompanied by a complete copy of
  26. // the source code of Avisynth (the version of Avisynth used to produce the
  27. // combined work), being distributed under the terms of the GNU General
  28. // Public License plus this exception.  An independent module is a module
  29. // which is not derived from or based on Avisynth, such as 3rd-party filters,
  30. // import and export plugins, or graphical user interfaces.
  31.  
  32. #ifndef AVSCORE_MINMAX_H
  33. #define AVSCORE_MINMAX_H
  34.  
  35. template<typename T>
  36. T min(T v1, T v2)
  37. {
  38.   return v1 < v2 ? v1 : v2;
  39. }
  40.  
  41. template<typename T>
  42. T max(T v1, T v2)
  43. {
  44.   return v1 > v2 ? v1 : v2;
  45. }
  46.  
  47. template<typename T>
  48. T clamp(T n, T min, T max)
  49. {
  50.     n = n > max ? max : n;
  51.     return n < min ? min : n;
  52. }
  53.  
  54. #endif // AVSCORE_MINMAX_H
  55.