1 ////////////////////////////////////////////////////////////////////////
2 //
3 // Copyright (C) 2018-2021 The Octave Project Developers
4 //
5 // See the file COPYRIGHT.md in the top-level directory of this
6 // distribution or <https://octave.org/copyright/>.
7 //
8 // This file is part of Octave.
9 //
10 // Octave is free software: you can redistribute it and/or modify it
11 // under the terms of the GNU General Public License as published by
12 // the Free Software Foundation, either version 3 of the License, or
13 // (at your option) any later version.
14 //
15 // Octave is distributed in the hope that it will be useful, but
16 // WITHOUT ANY WARRANTY; without even the implied warranty of
17 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18 // GNU General Public License for more details.
19 //
20 // You should have received a copy of the GNU General Public License
21 // along with Octave; see the file COPYING.  If not, see
22 // <https://www.gnu.org/licenses/>.
23 //
24 ////////////////////////////////////////////////////////////////////////
25 
26 #if ! defined (octave_syminfo_h)
27 #define octave_syminfo_h 1
28 
29 #include "octave-config.h"
30 
31 #include <string>
32 #include <iosfwd>
33 
34 #include "base-list.h"
35 
36 #include "ov.h"
37 
38 class octave_map;
39 
40 namespace octave
41 {
42   struct whos_parameter
43   {
44     char command;
45     char modifier;
46     int parameter_length;
47     int first_parameter_length;
48     int balance;
49     std::string text;
50     std::string line;
51   };
52 
53   class symbol_info
54   {
55   public:
56 
symbol_info(const std::string & name,const octave_value & value,bool is_formal,bool is_global,bool is_persistent)57     symbol_info (const std::string& name, const octave_value& value,
58                  bool is_formal, bool is_global, bool is_persistent)
59       : m_name (name), m_value (value), m_is_complex (value.iscomplex ()),
60         m_is_formal (is_formal), m_is_global (is_global),
61         m_is_persistent (is_persistent)
62     { }
63 
name(void)64     std::string name (void) const { return m_name; }
65 
value(void)66     octave_value value (void) const { return m_value; }
67 
is_complex(void)68     bool is_complex (void) const { return m_is_complex; }
69 
is_formal(void)70     bool is_formal (void) const { return m_is_formal; }
71 
is_global(void)72     bool is_global (void) const { return m_is_global; }
73 
is_persistent(void)74     bool is_persistent (void) const { return m_is_persistent; }
75 
76     void display_line (std::ostream& os,
77                        const std::list<whos_parameter>& params) const;
78   private:
79 
80     std::string m_name;
81     octave_value m_value;
82     bool m_is_complex;
83     bool m_is_formal;
84     bool m_is_global;
85     bool m_is_persistent;
86   };
87 
88   class symbol_info_list : public base_list<symbol_info>
89   {
90   public:
91 
92     symbol_info_list (void) = default;
93 
94     symbol_info_list (const symbol_info_list&) = default;
95 
96     symbol_info_list& operator = (const symbol_info_list&) = default;
97 
98     ~symbol_info_list (void) = default;
99 
100     octave_value varval (const std::string& name) const;
101 
102     std::list<std::string> names (void) const;
103 
104     octave_map map_value (const std::string& caller_function_name,
105                           int nesting_level) const;
106 
107     // Print a line of information for a given symbol.
108     void print_descriptor (std::ostream& os,
109                            const std::list<whos_parameter> params) const;
110 
111     void display (std::ostream& os, const std::string& format) const;
112 
113     // Parse FORMAT, and return a parameter list,
114     // containing all information needed to print the given
115     // attributes of the symbols.
116     std::list<whos_parameter>
117     parse_whos_line_format (const std::string& format) const;
118   };
119 }
120 
121 #endif
122