xref: /386bsd/usr/src/lib/libg++/libg++/PlotFile.cc (revision a2142627)
1 // This may look like C code, but it is really -*- C++ -*-
2 /*
3 Copyright (C) 1988 Free Software Foundation
4     written by Doug Lea (dl@rocky.oswego.edu)
5 
6 This file is part of GNU CC.
7 
8 GNU CC is distributed in the hope that it will be useful,
9 but WITHOUT ANY WARRANTY.  No author or distributor
10 accepts responsibility to anyone for the consequences of using it
11 or for whether it serves any particular purpose or works at all,
12 unless he says so in writing.  Refer to the GNU CC General Public
13 License for full details.
14 
15 Everyone is granted permission to copy, modify and redistribute
16 GNU CC, but only under the conditions described in the
17 GNU CC General Public License.   A copy of this license is
18 supposed to have been given to you along with GNU CC so you
19 can know your rights and responsibilities.  It should be in a
20 file named COPYING.  Among other things, the copyright notice
21 and this notice must be preserved on all copies.
22 */
23 
24 #ifdef __GNUG__
25 #pragma implementation
26 #endif
27 #include <PlotFile.h>
28 
29 /*
30  PlotFile implementation module
31 */
32 
33 
PlotFile()34 PlotFile:: PlotFile() {}
~PlotFile()35 PlotFile::~PlotFile() {}
36 
37 
PlotFile(const char * filename,io_mode m,access_mode a)38 PlotFile::PlotFile(const char* filename,  io_mode m,  access_mode a)
39 :(filename, m, a) {}
40 
PlotFile(const char * filename,const char * m)41 PlotFile::PlotFile(const char* filename,  const char* m)
42 :(filename, m) {}
43 
PlotFile(int filedesc,const io_mode m)44 PlotFile::PlotFile(int filedesc, const io_mode m)
45 :(filedesc, m) {}
46 
PlotFile(FILE * fileptr)47 PlotFile::PlotFile(FILE* fileptr)
48 :(fileptr) {}
49 
operator void*()50 PlotFile::operator void*()
51 {
52   return (state & (_bad|_fail))? 0 : this ;
53 }
54 
55 
open(const char * filename,io_mode m,access_mode a)56 PlotFile& PlotFile::open(const char* filename,
57 			  io_mode m,  access_mode a)
58 {
59  File::open(filename, m, a); return *this;
60 }
61 
open(const char * filename,const char * m)62 PlotFile& PlotFile::open(const char* filename, const char* m)
63 {
64  File::open(filename, m); return *this;
65 }
66 
open(int filedesc,io_mode m)67 PlotFile& PlotFile::open(int  filedesc,  io_mode m)
68 {
69  File::open(filedesc, m); return *this;
70 }
71 
open(FILE * fileptr)72 PlotFile& PlotFile::open(FILE* fileptr)
73 {
74  File::open(fileptr); return *this;
75 }
76 
setbuf(const int buffer_kind)77 PlotFile& PlotFile::setbuf(const int buffer_kind)
78 {
79  File::setbuf(buffer_kind); return *this;
80 }
81 
setbuf(const int size,char * buf)82 PlotFile& PlotFile::setbuf(const int size, char* buf)
83 {
84   File::setbuf(size, buf); return *this;
85 }
86 
87 
cmd(char c)88 PlotFile& PlotFile:: cmd(char c)
89 {
90   File::put(c);
91   return *this;
92 }
93 
operator <<(const int x)94 PlotFile& PlotFile:: operator<<(const int x)
95 {
96 #if defined(convex)
97   File::put((char)(x>>8));
98   File::put((char)(x&0377));
99 #else
100   File::put((char)(x&0377));
101   File::put((char)(x>>8));
102 #endif
103   return *this;
104 }
105 
operator <<(const char * s)106 PlotFile& PlotFile:: operator<<(const char *s)
107 {
108   File::put(s);
109   return *this;
110 }
111 
112 
arc(const int xi,const int yi,const int x0,const int y0,const int x1,const int y1)113 PlotFile& PlotFile:: arc(const int xi, const int yi,
114 			 const int x0, const int y0,
115 			 const int x1, const int y1)
116 {
117   return cmd('a') << xi << yi << x0 << y0 << x1 << y1;
118 }
119 
120 
box(const int x0,const int y0,const int x1,const int y1)121 PlotFile& PlotFile:: box(const int x0, const int y0,
122 			 const int x1, const int y1)
123 {
124   line(x0, y0, x0, y1);
125   line(x0, y1, x1, y1);
126   line(x1, y1, x1, y0);
127   return line(x1, y0, x0, y0);
128 }
129 
circle(const int x,const int y,const int r)130 PlotFile& PlotFile:: circle(const int x, const int y, const int r)
131 {
132   return cmd('c') << x << y << r;
133 }
134 
cont(const int xi,const int yi)135 PlotFile& PlotFile:: cont(const int xi, const int yi)
136 {
137   return cmd('n') << xi << yi;
138 }
139 
dot(const int xi,const int yi,const int dx,int n,const int * pat)140 PlotFile& PlotFile:: dot(const int xi, const int yi, const int dx,
141 			 int n, const int* pat)
142 {
143   cmd('d') << xi << yi << dx << n;
144   while (n-- > 0) *this << *pat++;
145   return *this;
146 }
147 
erase()148 PlotFile& PlotFile:: erase()
149 {
150   return cmd('e');
151 }
152 
label(const char * s)153 PlotFile& PlotFile:: label(const char* s)
154 {
155   return cmd('t') << s << "\n";
156 }
157 
line(const int x0,const int y0,const int x1,const int y1)158 PlotFile& PlotFile:: line(const int x0, const int y0,
159 			  const int x1, const int y1)
160 {
161   return cmd('l') << x0 << y0 << x1 << y1;
162 }
163 
linemod(const char * s)164 PlotFile& PlotFile:: linemod(const char* s)
165 {
166   return cmd('f') << s << "\n";
167 }
168 
move(const int xi,const int yi)169 PlotFile& PlotFile:: move(const int xi, const int yi)
170 {
171   return cmd('m') << xi << yi;
172 }
173 
point(const int xi,const int yi)174 PlotFile& PlotFile:: point(const int xi, const int yi)
175 {
176   return cmd('p') << xi << yi;
177 }
178 
space(const int x0,const int y0,const int x1,const int y1)179 PlotFile& PlotFile:: space(const int x0, const int y0,
180 			   const int x1, const int y1)
181 {
182   return cmd('s') << x0 << y0 << x1 << y1;
183 }
184