1 // Created on: 1998-12-14
2 // Created by: Christian CAILLET
3 // Copyright (c) 1998-1999 Matra Datavision
4 // Copyright (c) 1999-2014 OPEN CASCADE SAS
6 // This file is part of Open CASCADE Technology software library.
8 // This library is free software; you can redistribute it and/or modify it under
9 // the terms of the GNU Lesser General Public License version 2.1 as published
10 // by the Free Software Foundation, with special exception defined in the file
11 // OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
12 // distribution for complete text of the license and disclaimer of any warranty.
14 // Alternatively, this file may be used under the terms of Open CASCADE
15 // commercial license or contractual agreement.
17 #ifndef _MoniTool_Option_HeaderFile
18 #define _MoniTool_Option_HeaderFile
20 #include <Standard.hxx>
21 #include <Standard_Type.hxx>
23 #include <TCollection_AsciiString.hxx>
24 #include <Standard_Type.hxx>
25 #include <MMgt_TShared.hxx>
26 #include <Standard_CString.hxx>
27 #include <Standard_Boolean.hxx>
28 #include <TColStd_HSequenceOfAsciiString.hxx>
29 class MoniTool_TypedValue;
30 class Dico_DictionaryOfTransient;
31 class Standard_Transient;
32 class TCollection_AsciiString;
35 class MoniTool_Option;
36 DEFINE_STANDARD_HANDLE(MoniTool_Option, MMgt_TShared)
38 //! An Option gives a way of recording an enumerated list of
39 //! instances of a given class, each instance being identified
42 //! Also, an Option allows to manage basic types through a Typed
43 //! Value (which also applies to Static Parameter). It may record
44 //! an enumerated list of values for a TypedValue or Static
45 //! Parameter, each of them is recorded as a string (HAsciiString)
47 //! An Option is defined by the type of the class to be optioned,
48 //! or (mutually exclusive) the TypedValue/Static of which values
49 //! are to be optioned, a specific name, a list of named values.
50 //! It brings a current case with its name and value
51 //! It may also have a default case (the first recorded one if not
54 //! An Option may be created from another one, by sharing its Type
55 //! and its list of Items (one per case), with the same name or
56 //! another one. It may then be duplicated to break this sharing.
57 class MoniTool_Option : public MMgt_TShared
63 //! Creates an Option from scratch, with a Type and a Name
64 Standard_EXPORT MoniTool_Option(const Handle(Standard_Type)& atype, const Standard_CString aname);
66 //! Creates an Option for a TypedValue (for basic, non-cdl-typed,
67 //! value : integer, real, string ...)
68 //! If <name> is not given, the name of the TypedValue is taken
69 //! Remark that Type is then enforced to TCollection_HAsciiString
70 Standard_EXPORT MoniTool_Option(const Handle(MoniTool_TypedValue)& aval, const Standard_CString aname = "");
72 //! Creates an Option from another one, the name can be redefined
73 //! The Type remains the same. The list of Items, too, it can also
74 //! be later duplicated by call to Duplicate
75 Standard_EXPORT MoniTool_Option(const Handle(MoniTool_Option)& other, const Standard_CString aname = "");
77 //! Adds an item : value and name (replaces it if name is already
79 //! Returns True when done, False if <val> is not Kind of the
81 //! For a TypedValue, val must be a HAsciiString, its content must
82 //! satisfy the definition of the TypedValue
83 Standard_EXPORT Standard_Boolean Add (const Standard_CString name, const Handle(Standard_Transient)& val);
85 //! Short-cut to add an item for a TypedValue (basic type) : name
86 //! is the name of the case, val is its value as a CString
87 //! If val is not provided, val = name is assumed
88 //! Returns True when done, False if this Option is not for a
89 //! TypedValue or if the new value does not satisfy the definition
91 Standard_EXPORT Standard_Boolean AddBasic (const Standard_CString name, const Standard_CString val = "");
93 //! Duplicates the list of items
94 //! It starts with the same definitions as before Duplicate, but
95 //! it is not longer shared with other options
96 Standard_EXPORT void Duplicate();
98 //! Returns the Name of the Option
99 Standard_EXPORT const TCollection_AsciiString& Name() const;
101 //! Returns the Type of the Option
102 Standard_EXPORT Handle(Standard_Type) Type() const;
104 //! Returns the TypedValue of the Option, or a Null Handle
105 Standard_EXPORT Handle(MoniTool_TypedValue) TypedValue() const;
107 //! Gives the value bound with a name, in val
108 //! Returns True if <name> is found, False else
109 //! This way of returning a Transient, bound with the Type Control
110 //! avoids DownCast and ensures the value is directly usable
111 Standard_EXPORT Standard_Boolean Item (const Standard_CString name, Handle(Standard_Transient)& val) const;
113 //! Returns the list of available item names
114 Standard_EXPORT Handle(TColStd_HSequenceOfAsciiString) ItemList() const;
116 //! Returns the list of cases, other than <name>, which bring the
117 //! same value as <name>
118 //! Empty list (not a Null Handle) if no alias, or <name> unknown
119 //! if <exact> is True (D), exact name is required, no completion
120 //! if <exact> is False and <name> is not complete, but addresses
121 //! only one item, completion is done and the list includes the
123 Standard_EXPORT Handle(TColStd_HSequenceOfAsciiString) Aliases (const Standard_CString name, const Standard_Boolean exact = Standard_True) const;
125 //! Commands the Option to switch on an item name
126 //! Returns True when done, False if <name> is not recorded
127 //! (in that case, former switch remains unchanged)
128 //! If no switch has been called, it is active on the last added
130 Standard_EXPORT Standard_Boolean Switch (const Standard_CString name);
132 //! Returns the Name of the currently switched item (Case)
133 Standard_EXPORT const TCollection_AsciiString& CaseName() const;
135 //! Returns the Value of the currently switch item
136 //! To be down-casted as needed before use
137 Standard_EXPORT Handle(Standard_Transient) CaseValue() const;
139 //! Returns the Value of the currently switch item
140 //! This way of returning a Transient, bound with the Type Control
141 //! avoids DownCast and ensures the value is directly usable
142 //! For a TypedValue, returns the corresponding HAsciiString
143 Standard_EXPORT void Value (Handle(Standard_Transient)& val) const;
148 DEFINE_STANDARD_RTTIEXT(MoniTool_Option,MMgt_TShared)
158 //! Returns the list of items, to be shared (to copy an option)
159 Standard_EXPORT Handle(Dico_DictionaryOfTransient) Items() const;
161 TCollection_AsciiString thename;
162 Handle(Standard_Type) thetype;
163 Handle(MoniTool_TypedValue) thevalue;
164 Handle(Dico_DictionaryOfTransient) theitems;
165 TCollection_AsciiString thecase;
166 Handle(Standard_Transient) theval;
177 #endif // _MoniTool_Option_HeaderFile