Created
September 30, 2015 18:25
-
-
Save krysseltillada/6a29c57d63b34a7d1643 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <iostream> | |
#include "ScreenTemplate.hpp" | |
int main () | |
{ | |
ScreenTemplate <800, 600> screen1; | |
std::cout << screen1 << std::endl; | |
std::cin >> screen1; | |
std::cout << screen1 << std::endl; | |
return 0; | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#pragma once | |
#include <iostream> | |
template <unsigned, unsigned> class ScreenTemplate; | |
template <unsigned getH, unsigned getW> | |
std::ostream &operator << (std::ostream &, const ScreenTemplate <getH, getW> &); | |
template <unsigned getH, unsigned getW> | |
std::istream &operator >> (std::istream &, ScreenTemplate <getH, getW> &); | |
template <unsigned H, unsigned W> | |
class ScreenTemplate { | |
friend std::ostream &operator << <H, W> (std::ostream &, const ScreenTemplate <H, W> &); | |
friend std::istream &operator >> <H, W> (std::istream &, ScreenTemplate <H, W> &); | |
public: | |
ScreenTemplate (const unsigned &, const unsigned &); | |
ScreenTemplate (); | |
unsigned getHeight () const; | |
unsigned getWidth () const; | |
ScreenTemplate &setHeight (const unsigned &); | |
ScreenTemplate &setWidth (const unsigned &); | |
private: | |
unsigned height, width; | |
}; | |
template <unsigned H, unsigned W> | |
std::ostream &operator << (std::ostream &os, const ScreenTemplate <H, W> &rho) { | |
os << rho.height << " " << rho.width; | |
return os; | |
} | |
template <unsigned H, unsigned W> | |
std::istream &operator >> (std::istream &is, ScreenTemplate <H, W> &rho) { | |
is >> rho.height >> rho.width; | |
if (!is) | |
rho = ScreenTemplate <H, W> (); | |
return is; | |
} | |
template <unsigned H, unsigned W> | |
ScreenTemplate <H, W>::ScreenTemplate () : | |
height (H), width (W) { } | |
template <unsigned H, unsigned W> | |
ScreenTemplate <H, W>::ScreenTemplate (const unsigned &h, const unsigned &w) : | |
height (h), width (w) { } | |
template <unsigned H, unsigned W> | |
unsigned ScreenTemplate <H, W>::getHeight () const { | |
return height; | |
} | |
template <unsigned H, unsigned W> | |
unsigned ScreenTemplate <H, W>::getWidth () const { | |
return width; | |
} | |
template <unsigned H, unsigned W> | |
ScreenTemplate <H, W> &ScreenTemplate <H, W>::setHeight (const unsigned &getHeight) { | |
this->height = getHeight; | |
return *this; | |
} | |
template <unsigned H, unsigned W> | |
ScreenTemplate <H, W> &ScreenTemplate <H, W>::setWidth (const unsigned &getWidth) { | |
this->width = getWidth; | |
return *this; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment