📄 cdlcore.hxx
字号:
#ifndef __CDLCORE_HXX# define __CDLCORE_HXX//{{{ Banner //==========================================================================//// cdlcore.hxx//// The core parts of the library. This header defines aspects of// CDL that are shared between software cdl, hcdl, scdl, and any// future languages based on the same core technology.////==========================================================================//####COPYRIGHTBEGIN####// // ----------------------------------------------------------------------------// Copyright (C) 1999, 2000 Red Hat, Inc.//// This file is part of the eCos host tools.//// This program is free software; you can redistribute it and/or modify it // under the terms of the GNU General Public License as published by the Free // Software Foundation; either version 2 of the License, or (at your option) // any later version.// // This program is distributed in the hope that it will be useful, but WITHOUT // ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or // FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for // more details.// // You should have received a copy of the GNU General Public License along with// this program; if not, write to the Free Software Foundation, Inc., // 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.//// ----------------------------------------------------------------------------// //####COPYRIGHTEND####//==========================================================================//#####DESCRIPTIONBEGIN#### //// Author(s): bartv// Contributors: bartv// Date: 1999-04-15////####DESCRIPTIONEND####//==========================================================================//}}}//{{{ Platform dependencies // ----------------------------------------------------------------------------// Visual C++ has the delightful feature that the source browser will generate// warnings if there are any identifiers of length >= 256 characters, while at// the same time use of templates in the standard C++ library can easily// generate functions that long. It appears that the only way to disable the// warnings is by use of a %$#@(%*&%! #pragma.//// Similarly, VC++ gives spurious warnings when it comes to multiple virtual// inheritance.#ifdef _MSC_VER# pragma warning( disable: 4786 )# pragma warning( disable: 4250 )#endif//}}}//{{{ nested #include's // ----------------------------------------------------------------------------// The libcdl API is defined using parts of the standard C++ library,// including strings and various bits of STL. Therefore these headers must// be #include'd here for the header file to work.#include <vector>#include <list>#include <map>#include <set>#include <deque>#include <string>#include <functional>#include <algorithm>// Now for some eCos host-side infrastructure headers.//// Get the cyg_int64 data type and CYG_UNUSED_PARAM() macro.#include <cyg/infra/cyg_type.h>// Some of the classes need to reference the cyg_assert_class_zeal enum.// Also inline functions may perform assertions.#include <cyg/infra/cyg_ass.h>// This header file also depends on having a suitable Tcl installation// Unfortunately <tcl.h> does some ugly things in the interests of// portability, including defining symbols such as EXTERN when// necessary, and this has to be patched up here as cleanly as possible.#ifndef CONST# define __CDL_CONST_UNDEFINED#endif#ifndef EXTERN# define __CDL_EXTERN_UNDEFINED#endif#ifndef VOID# define __CDL_VOID_UNDEFINED#endif#ifndef CHAR# define __CDL_CHAR_UNDEFINED#endif#ifndef SHORT# define __CDL_SHORT_UNDEFINED#endif#ifndef LONG# define __CDL_LONG_UNDEFINED#endifextern "C" {#include <tcl.h>}#ifdef __CDL_CONST_UNDEFINED# undef CONST# undef __CDL_CONST_UNDEFINED#endif#ifdef __CDL_EXTERN_UNDEFINED# undef EXTERN# undef __CDL_EXTERN_UNDEFINED#endif#ifdef __CDL_VOID_UNDEFINED# undef VOID# undef __CDL_VOID_UNDEFINED#endif#ifdef __CDL_CHAR_UNDEFINED# undef CHAR# undef __CDL_CHAR_UNDEFINED#endif#ifdef __CDL_SHORT_UNDEFINED# undef SHORT# undef __CDL_SHORT_UNDEFINED#endif#ifdef __CDL_LONG_UNDEFINED# undef LONG# undef __CDL_LONG_UNDEFINED#endif//}}}//{{{ Primitive types, constants:, enums, etc. // ----------------------------------------------------------------------------// The CDL languages are defined in terms of arbitrary precision// arithmetic. This is necessary to allow e.g. pointers to be// manipulated at the CDL level on 64 bit target processors.//// Temporarily it is not necessary to provide this precision, so it is// convenient to stick to 64 bit integers as provided by the// underlying infrastructure. However the API is defined in terms of// the type cdl_int, so that it will be easier in future to make the// change to the correct datatype. At that point cdl_int can be// redefined to be a class which supports the appropriate operators.typedef cyg_int64 cdl_int;// ---------------------------------------------------------------------------// A common concept in the CDL language is a small amount of TCL code.// This is currently stored as a simple string. Conceivably it could// be byte-compiled and stored accordingly.typedef std::string cdl_tcl_code;// ----------------------------------------------------------------------------// CDL values.//// CDL is a declarative programming language. It does involve the// manipulation of values, but such values do not necessarily// correspond to hardware-level entities such as integers or double// precision numbers. Hence the term "type" is avoided, "flavor"// is used instead. CDL understands four different flavors.//// None | Bool// --------+--------// Data |BoolData////// The flavor "none" is used for entities that serve only as// placeholders in the hierarchy, allowing other entities to be// grouped more easily.//// Boolean entities can be either enabled or disabled. This is the// most common flavor for software configuration options, the user can// either enable or disable some unit of functionality. For software// packages implemented in C or C++ the implementation is obvious: iff// the entity is enabled then there will be a #define, and code will// check the setting using e.g. #ifdef.//// The flavor "data" implies some arbitrary data. Internally this will// be held as a string. Other properties such as legal_values,// check_proc and entry_proc can be used to constrain the// actual values, for example to an integer value within a certain// range.//// The flavor "booldata" combines the previous two: it means that// the option can be either enabled or disabled, and if it is// enabled then it must have a value as per legal_values etc.// One example of this is a software package: this may be either// enabled or disabled, and if it is enabled then it has a value// corresponding to the version string. Another example is a hardware// pin: this may or may not be connected, and if it is connected// then its value identifies some other pin.//// An entity's flavor is not always sufficient by itself to specify// how the user can manipulate it in a graphical tool. Obviously an// entity of flavor "none" cannot be manipulated at all. Flavor "bool"// normally implies a checkbutton, but occasionally a radiobutton will// be more appropriate. "Data" says very little about the user// interaction, it will be necessary to examine other properties such// as legal_values to determine a sensible representation. The same// goes for "BoolData", with the additional possibility that the// entity may be disabled.//// It can be argued that three of the flavors are redundant: both Bool// and BoolData could be implemented as cases of "Data" with a special// legal value "disabled" (or false, or whatever); "None" could be// implemented as constant "Data"; effectively CDL would manipulate// all data as strings, just like e.g. all variables in Tcl, or just// like all scalars in Perl. This approach is certainly tempting and// might well make it easier to document the language, but in practice// it would result in more verbose CDL: boolean entities really are a// different beast from data entities.//// It can also be argued that there should be more flavors. For// example there could be separate flavors for integer data, floating// point data, string data, and so on. There are a number of good// reasons for not doing so://// 1) applying separate constraints such as legal_values allows much// finer control over the actual values, for example numbers within a// given range. As likely as not, a value will be constrained to// something smaller than the range MININT to MAXINT (whatever those// happen to be for the current target).//// 2) where do you stop? Do you provide separate flavors for signed// vs. unsigned? Char, wchar_t, short, int, long, long long? How about// the eCos data types cyg_ucount8, cyg_uint8, ... Is there support// for enums? Arrays? Bitfields? Structures? Unions? C++ classes?// How about other programming languages such as Ada or Java?//// Any attempt to implement a grand union of all data types in CDL // is doomed to failure and should not be attempted. Treating// everything as a string instead has proven successful in a number// of languages, including Tcl and Perl.//// 3) for some variants of CDL, for example hardware CDL, it may not// make much sense to display a value directly and allow it to be// manipulated directly. The value associated with a pin entity// identifies the pin to which it is connected, and typically// this value will be manipulated by drag and drop rather than by// typing some characters. Such a value certainly does not correspond// to any machine data type.//// Another reason for extending the number of flavors is to provide// more information. For example there could be a specialized version// of the boolean flavor called "radio". This would imply a specific// representation in the user interface, and it would also impose// a constraint that it implicitly precludes any other radio entities// within the same group. However the same information can be specified// by other more general means such as requires statements.enum CdlValueFlavor { CdlValueFlavor_Invalid = 0, CdlValueFlavor_None = 1, CdlValueFlavor_Bool = 2, CdlValueFlavor_BoolData = 3, CdlValueFlavor_Data = 4};// Another important aspect of a value is where it came from. There// are a number of possible sources: the default value, calculated// from a default_value property; a value inferred by the inference// engine; a value set by a wizard; and a value set explicitly by// the user. These sources have different priorities, so for example// the inference engine can safely replace a calculated default// value without prompting the user, but changing a user-set value// automatically is undesirable.//// Wizard-generated values are considered more valuable than default// or inferred values (there is some user input involved), but less// valuable than values set explicitly by the user: the idea is that// a wizard asks fairly generic questions and makes a best guess at// the correct values, which may not be precise enough for the// user's needs.//// Arguably dialogs provide a level between wizards and users, in that// a dialog can theoretically manipulate several entities in one go so// it is a less precise way of setting values. At this stage it does// not seem worthwhile to add this distinction.//// The library actually maintains separate values for each source,// as well as the current source which is what actually gets used.// In theory it is possible for the user interface code to let// the user switch between these. It is not yet clear whether this// makes sense from an end user's perspective.enum CdlValueSource { CdlValueSource_Invalid = -1, // 0 is needed for array indexing CdlValueSource_Default = 0, CdlValueSource_Inferred = 1, CdlValueSource_Wizard = 2, CdlValueSource_User = 3, CdlValueSource_Current = 4};
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -