1 /*
2    Copyright (C) 2004 T. Scott Dattalo
3 
4 This file is part of the libgpsim library of gpsim
5 
6 This library is free software; you can redistribute it and/or
7 modify it under the terms of the GNU Lesser General Public
8 License as published by the Free Software Foundation; either
9 version 2.1 of the License, or (at your option) any later version.
10 
11 This library is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14 Lesser General Public License for more details.
15 
16 You should have received a copy of the GNU Lesser General Public
17 License along with this library; if not, see
18 <http://www.gnu.org/licenses/lgpl-2.1.html>.
19 */
20 
21 
22 #ifndef SRC_GPSIM_OBJECT_H_
23 #define SRC_GPSIM_OBJECT_H_
24 
25 #include <string>
26 
27 class Expression;
28 
29 /// gpsimObject - base class for most of gpsim's objects
30 ///
31 
32 class gpsimObject {
33 public:
34   gpsimObject();
35   gpsimObject(const char *_name, const char *desc = nullptr);
36   virtual ~gpsimObject();
37 
38   /// Get the name of the object
39   virtual std::string &name() const;
40 
41   /// copy the name to a user char array
42   virtual char *name(char *, int len);
43 
44   /// copy the object value to a user char array
45   virtual char *toString(char *, int len);
46   virtual char *toBitStr(char *, int len);
47 
48   /// Assign a new name to the object
49   /// FIXME why have two ways of naming ???
50   virtual void new_name(const char *);
51   virtual void new_name(std::string &);
52 
53   /// TEMPORARY -- remove after gpsimValue and Value have been merged.
54   virtual unsigned int get_value();
55 
56   /// description - get a description of this object. If the object has
57   /// a name, then 'help value_name' at the command line will display
58   /// the description.
59 
60   virtual std::string description();
61   void set_description(const char *);
62 
63   /// Access object-specific information
64   std::string show();
65   std::string showType();
66   virtual std::string toString();
67 
68   // Breakpoint types supported by Value
69   enum ObjectBreakTypes {
70     eBreakAny,    // ???
71     eBreakWrite,  // Register write
72     eBreakRead,   // Register read
73     eBreakChange, // Register change
74     eBreakExecute // Program memory execute
75   };
76 
77   // Breakpoint types supported by Value
78   enum ObjectActionTypes {
79     eActionHalt,
80     eActionLog,
81   };
82 
83   /// breakpoints
84   /// set a break point on a gpsim object. The BreakType specifies the
85   /// the condition for which the break will trigger when this value
86   /// is accessed. In addition, the optional expr is a boolean expression
87   /// that is evaluated when the Object is accessed. The expression must
88   /// evaluate to true for the break to trigger. If the break is successfully
89   /// set then a non-negative number (the break point number) will be returned.
90   /// If the break fails, then -1 is returned.
91   /// The ActionType specifies the action to take when the break is triggered.
92 
93   virtual int set_break(ObjectBreakTypes bt = eBreakAny,
94                         ObjectActionTypes at = eActionHalt,
95                         Expression *expr = nullptr);
96   virtual int clear_break();
97 
98 protected:
99   std::string  name_str;          // A unique name to describe the object
100   const char *cpDescription;      // A desciption of the object
101 };
102 
103 //------------------------------------------------------------------------
104 // BreakTypes
105 //
106 class BreakType
107 {
108 public:
BreakType(int _type)109   explicit BreakType(int _type)
110     : m_type(_type)
111   {
112   }
113 
~BreakType()114   virtual ~BreakType()
115   {
116   }
117 
type()118   virtual int type()
119   {
120     return m_type;
121   }
122 protected:
123   int m_type;
124 };
125 
126 #endif //  SRC_GPSIM_OBJECT_H_
127