Example #1
0
//this is a higher level error checked version of copywin
void copy(frame& src, frame& dst, 
          const point& src_upper_left,  
          const point& dst_upper_left, 
          const point& size) {

	auto dst_lower_right=dst_upper_left + size - point{1,1};

#ifndef NDEBUG 
	{
		//this like all high arity functions is a bitch to get right
		//hence this debug block
		auto dst_dim=dst.get_dimension();
		auto src_dim=src.get_dimension();
		auto src_lower_right=src_upper_left + size - point{1,1};

		CONS_ASSERT(dst_dim.x > dst_lower_right.x
		         && dst_dim.y > dst_lower_right.y,
		            "copy area is larger than destination"
		);
		CONS_ASSERT(src_dim.x > src_lower_right.x
		         && src_dim.y > src_lower_right.y,
	 	            "copy area is larger than source: "
		);
		CONS_ASSERT(src.get_handle(), "source frame is not valid");
		CONS_ASSERT(dst.get_handle(), "destination frame is not valid");
	}
#endif 

	if(::copywin(src.get_handle(),  dst.get_handle(),
                 src_upper_left.y,  src_upper_left.x,
                 dst_upper_left.y,  dst_upper_left.x,
                 dst_lower_right.y, dst_lower_right.x, false)==ERR) {

		std::ostringstream oss;
		oss << "unable to copy window"
		    << "\nsource size " << src.get_dimension()
		    << "\ndestination size " << dst.get_dimension()
			<< "\nupper left source position " << src_upper_left 
			<< "\nupper left destination position " << dst_upper_left 
			<< "\ndimension to copy " << size
			<< "\ncalculated destination lower right " << dst_lower_right;
		throw CONS_MAKE_EXCEPTION(oss.str());
	}
}