
*****************************************************

// Listing 1 - VSMANIP.CPP

#include "vstream.h"
#include <conio.h>
#include <dos.h>
#include "vsmanip.h"



/* Simple no argument manipulator functions */
ostream& beep(ostream& str)
  {
  sound(1000);
  delay(50);
  nosound();
  return str;
  }

ostream& clear_screen(ostream& str)
  {
  clrscr();
  return str;
  }

ostream& del_line(ostream& str)
  {
  delline();
  return str;
  }

ostream& high_video(ostream& str)
  {
  highvideo();
  return str;
  }

ostream& ins_line(ostream& str)
  {
  insline();
  return str;
  }

ostream& low_video(ostream& str)
  {
  lowvideo();
  return str;
  }

ostream& norm_video(ostream& str)
  {
  normvideo();
  return str;
  }

/* Single argument manipulator action functions.
   These functions are static -- they are only used
   by the manipulator object functions of the same
   name (see below) */
static ostream& text_color(ostream& osr,int color)
  {
  textcolor(color);
  return osr;
  }

static ostream& text_background(ostream& osr,int color)
  {
  textbackground(color);
  return osr;
  }

static ostream& text_attr(ostream& osr,int color)
  {
  if (win::top_window())
    win::top_window()->setcolor(color);
  textattr(color);
  return osr;
  }

/* make window goto top */
static ostream& top_window(ostream& osr, win& w)
  {
  w.maketop();
  return osr;
  }


/* Functions for manipulators with two arguments */
static ostream& go_xy(ostream& osr,int& x,int& y)
  {
  gotoxy(x,y);
  return osr;
  }

static ostream& where_xy(ostream& osr,int& x,int& y)
  {
  x=wherex();
  y=wherey();
  return osr;
  }


/* These functions build manipulator objects that
   contain the argument(s) and the action function
   of the same name */

/* One argument */
omanip_int1 text_color(int color)
  {
  omanip_int1 rv(text_color,color);
  return rv;
  };

omanip_int1 text_background(int color)
  {
  omanip_int1 rv(text_background,color);
  return rv;
  };

omanip_int1 text_attr(int color)
  {
  omanip_int1 rv(text_attr,color);
  return rv;
  };

omanip_winr top_window(win& w)
  {
  omanip_winr rv(top_window,w);
  return rv;
  }

/* Two argument functions */
omanip_intr2 go_xy(int& x,int& y)
  {
  omanip_intr2 rv(go_xy,x,y);
  return rv;
  }

omanip_intr2 where_xy(int& x,int& y)
  {
  omanip_intr2 rv(where_xy,x,y);
  return rv;
  }


