1 /*
2     This file is part of GNU APL, a free implementation of the
3     ISO/IEC Standard 13751, "Programming Language APL, Extended"
4 
5     Copyright (C) 2018-2019  Dr. Jürgen Sauermann
6 
7     This program is free software: you can redistribute it and/or modify
8     it under the terms of the GNU General Public License as published by
9     the Free Software Foundation, either version 3 of the License, or
10     (at your option) any later version.
11 
12     This program is distributed in the hope that it will be useful,
13     but WITHOUT ANY WARRANTY; without even the implied warranty of
14     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15     GNU General Public License for more details.
16 
17     You should have received a copy of the GNU General Public License
18     along with this program.  If not, see <http://www.gnu.org/licenses/>.
19 */
20 
21 #ifndef __Quad_PLOT_DEFINED__
22 #define __Quad_PLOT_DEFINED__
23 
24 #include <math.h>
25 #include <pthread.h>
26 #include <semaphore.h>
27 #include <vector>
28 
29 #include "QuadFunction.hh"
30 #include "Value.hh"
31 
32 class Plot_window_properties;
33 class Plot_data;
34 
35 /// The class implementing ⎕PLOT
36 class Quad_PLOT : public QuadFunction
37 {
38 public:
39    /// Constructor.
40    Quad_PLOT();
41 
42    /// Denstructor.
43    ~Quad_PLOT();
44 
45    static Quad_PLOT * fun;          ///< Built-in function.
46    static Quad_PLOT  _fun;          ///< Built-in function.
47 
48    /// a semaphore protecting plot_threads
49    static sem_t * plot_threads_sema;
50 
51    /// an array of threads (one per plot window) handling X events from the
52    /// window
53    static std::vector<pthread_t> plot_threads;
54 
55 protected:
56    /// overloaded Function::eval_AB()
57    Token eval_AB(Value_P A, Value_P B);
58 
59    /// overloaded Function::eval_B()
60    Token eval_B(Value_P B);
61 
62    /// print attribute help text
63    void help() const;
64 
65    /// plot the data (creating a new plot window in X)
66    Value_P plot_data(Plot_window_properties * w_props,
67                      const Plot_data * data);
68 
69    /// initialize the data to be plotted
70    Plot_data * setup_data(const Value * B);
71 
72    /// whether to print some debug info during plotting
73    int verbosity;
74 };
75 
76 #endif // __Quad_PLOT_DEFINED__
77