]> Creatis software - bbtk.git/blob - kernel/src/bbtkBlackBoxDescriptor.h
*** empty log message ***
[bbtk.git] / kernel / src / bbtkBlackBoxDescriptor.h
1 /*=========================================================================
2                                                                                 
3   Program:   bbtk
4   Module:    $RCSfile: bbtkBlackBoxDescriptor.h,v $
5   Language:  C++
6   Date:      $Date: 2008/04/09 11:16:57 $
7   Version:   $Revision: 1.8 $
8                                                                                 
9   Copyright (c) CREATIS (Centre de Recherche et d'Applications en Traitement de
10   l'Image). All rights reserved. See Doc/License.txt or
11   http://www.creatis.insa-lyon.fr/Public/bbtk/License.html for details.
12                                                                                 
13      This software is distributed WITHOUT ANY WARRANTY; without even
14      the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
15      PURPOSE.  See the above copyright notices for more information.
16                                                                                 
17 =========================================================================*/
18
19 /**
20  *  \file 
21  *  \brief Class bbtk::BlackBoxDescriptor : (abstract) describes of a BlackBox (name, description, author) and is able to create an instance of it.
22  */
23 /**
24  * \class bbtk::BlackBoxDescriptor
25  * \brief (Abstract) Contains information on a BlackBox type (name, description, author, inputs, outputs) and is able to create an instance of it.
26  */
27
28 #ifndef __bbtkBlackBoxDescriptor_h__
29 #define __bbtkBlackBoxDescriptor_h__
30
31 #include "bbtkBlackBoxInputDescriptor.h"
32 #include "bbtkBlackBoxOutputDescriptor.h"
33 #include <map>
34 #include <fstream>
35
36 namespace bbtk
37 {
38
39   class BlackBox;
40   class Package;
41
42   //==========================================================================
43   class BBTK_EXPORT BlackBoxDescriptor
44   {
45   public:
46     /// The type of descriptor of inputs 
47     typedef BlackBoxInputDescriptor InputDescriptor;
48     /// The type of descriptor of outputs 
49     typedef BlackBoxOutputDescriptor OutputDescriptor;
50     /// The type of dictionnary of inputs = map of input descriptors pointers 
51     typedef std::map<std::string, InputDescriptor*> InputDescriptorMapType;
52     /// The type of dictionnary of outputs= map of output descriptors pointers 
53     typedef std::map<std::string, OutputDescriptor*> OutputDescriptorMapType;
54     /// The kinds of black box
55     typedef enum
56     {
57       STANDARD=0,
58       ADAPTOR=1,
59       DEFAULT_ADAPTOR=2,
60       WIDGET_ADAPTOR=3,
61       DEFAULT_WIDGET_ADAPTOR=4
62     }
63     Kind;
64
65     /// Default ctor
66     BlackBoxDescriptor(); 
67     /// Creates an instance with name boxname of the BlackBox
68     /// of which this is the descriptor 
69     virtual BlackBox* CreateInstance(const std::string& boxname) = 0;
70
71     /// Returns the name of the **TYPE** of the black box
72     const std::string& GetTypeName() const { return mTypeName; }
73     
74     /// Returns the full name of the **TYPE** of the black box (+package name)
75     std::string GetFullTypeName() const;
76     
77     /// Returns the description of the BlackBox 
78     const std::string& GetDescription() const { return mDescription; }
79     
80     /// Returns the author(s) of the BlackBox
81     const std::string& GetAuthor() const { return mAuthor; }
82     
83     /// Returns the category(s) of the BlackBox
84     const std::string& GetCategory() const { return mCategory; }
85     
86     /// Returns the Package to which the box belongs
87     Package* GetPackage() { return mPackage; }
88     
89     /// Returns the Package to which the box belongs (const pointer)
90     const Package* GetPackage() const { return mPackage; }
91     
92     /// Returns the kind of box 
93     Kind GetKind() const { return mKind; }
94
95     /// Prints help on the black box
96     virtual void GetHelp(bool full=true) const;
97
98     /// Returns a const ref on the map of input descriptors
99     const InputDescriptorMapType& GetInputDescriptorMap() const 
100       { return mInput; }
101       
102     /// Returns a const ref on the map of output descriptors
103     const OutputDescriptorMapType& GetOutputDescriptorMap() const 
104       { return mOutput; }
105       
106     /// Returns a const pointer on the descriptor of the input of name <name> 
107     const InputDescriptor* GetInputDescriptor(const std::string &name) const;
108
109     /// Returns a const pointer on the descriptor of the output of name <name> 
110     const OutputDescriptor* GetOutputDescriptor(const std::string &name) const;
111
112     /// Sets the name of the **TYPE** of BlackBox
113     void SetTypeName( const std::string& name ) { mTypeName=name; }
114
115     /// Adds the string to the BlackBox description
116     void AddToDescription( const std::string&, bool clear = false );
117     
118     /// Adds the string to the BlackBox author list
119     void AddToAuthor( const std::string&, bool clear = false );
120     
121     /// Adds the string to the BlackBox category list
122     void AddToCategory( const std::string&, bool clear = false );
123     
124     /// Sets the Package to which the box belongs
125     void SetPackage(Package *package) { mPackage = package; }
126     
127     /// Sets the kind of box 
128     void SetKind(Kind kind) { mKind = kind; }
129
130     /* 
131    virtual void InsertHTMLGraph( std::ofstream& s, int detail, int level, 
132                                   const std::string& output_dir = "" ) { }
133     */
134     /// Writes html formatted help into the output file stream. 
135     /// detail and level are used for graphical representation of 
136     /// complex black boxes (see ComplexBlackBox::InsertHTMLGraph)
137     /// output_dir is the directory in which to write auxilliary files 
138     /// (.dot/.png/.cmap)
139     virtual void InsertHtmlHelp ( std::ofstream& s, 
140                                   int detail, int level,
141                                   const std::string& output_dir = "",
142                                   bool relative_link = false );
143
144     /// Increase ref count
145     void Reference() { mRefCount++; }
146     /// Decrease ref count and delete if no more used
147     void UnReference();
148
149     ///
150     virtual void Check(bool recursive=true) const;
151
152   protected:
153     /// Default dtor is protected : use UnRegister to destroy (ref counting)
154     virtual ~BlackBoxDescriptor();
155
156     /// Adds an input descriptor
157     void AddInputDescriptor( BlackBoxInputDescriptor *d ) 
158     { mInput[d->GetName()] = d; }
159     /// Adds an output descriptor
160     void AddOutputDescriptor( BlackBoxOutputDescriptor *d ) 
161     { mOutput[d->GetName()] = d; }
162
163     //  private:
164     /// The name of the type of black box
165     std::string mTypeName;
166     /// The description of the black box
167     std::string mDescription;
168     /// The author of the black box
169     std::string mAuthor;
170     /// The category of the black box
171     std::string mCategory;    
172     /// The kind of box (standard / adaptor)
173     Kind mKind;
174     /// The Package to which the box belongs
175     Package *mPackage;
176     /// The inputs 
177     InputDescriptorMapType mInput;
178     /// The outputs 
179     OutputDescriptorMapType mOutput;
180
181     /// Reference counting
182     int mRefCount;
183     
184   private:
185     BlackBoxDescriptor(const BlackBoxDescriptor&) {}
186   };
187   // class BlackBoxDescriptor
188   //==========================================================================
189
190
191  
192 }
193 // namespace bbtk
194 #endif