]> Creatis software - bbtk.git/blob - kernel/src/bbtkBlackBoxDescriptor.h
=== MAJOR RELEASE ====
[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/18 12:59:15 $
7   Version:   $Revision: 1.9 $
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 "bbtkObject.h"
32 #include "bbtkBlackBoxInputDescriptor.h"
33 #include "bbtkBlackBoxOutputDescriptor.h"
34 #include <map>
35 #include <fstream>
36
37 namespace bbtk
38 {
39
40   class BlackBox;
41   class Package;
42   BBTK_FORWARD_DECLARE_POINTER(BlackBox);
43   BBTK_FORWARD_DECLARE_POINTER(Package);
44
45   //==========================================================================
46   class BBTK_EXPORT BlackBoxDescriptor : public Object
47   {
48     BBTK_ABSTRACT_OBJECT_INTERFACE(BlackBoxDescriptor);
49   public:
50     /// The type of descriptor of inputs 
51     typedef BlackBoxInputDescriptor InputDescriptor;
52     /// The type of descriptor of outputs 
53     typedef BlackBoxOutputDescriptor OutputDescriptor;
54     /// The type of dictionnary of inputs = map of input descriptors pointers 
55     typedef std::map<std::string, InputDescriptor*> InputDescriptorMapType;
56     /// The type of dictionnary of outputs= map of output descriptors pointers 
57     typedef std::map<std::string, OutputDescriptor*> OutputDescriptorMapType;
58     /// The kinds of black box
59     typedef enum
60     {
61       STANDARD=0,
62       ADAPTOR=1,
63       DEFAULT_ADAPTOR=2,
64       WIDGET_ADAPTOR=3,
65       DEFAULT_WIDGET_ADAPTOR=4
66     }
67     Kind;
68
69     /// Releases a descriptor
70     //    static void Release(BlackBoxDescriptor::WeakPointer);
71
72      /// Creates an instance with name boxname of the BlackBox
73     /// of which this is the descriptor 
74     virtual BlackBoxPointer NewBlackBox(const std::string& boxname) = 0;
75
76     /// Returns the name of the **TYPE** of the black box
77     const std::string& GetTypeName() const { return mTypeName; }
78     
79     /// Returns the full name of the **TYPE** of the black box (+package name)
80     std::string GetFullTypeName() const;
81     
82     /// Returns the description of the BlackBox 
83     const std::string& GetDescription() const { return mDescription; }
84     
85     /// Returns the author(s) of the BlackBox
86     const std::string& GetAuthor() const { return mAuthor; }
87     
88     /// Returns the category(s) of the BlackBox
89     const std::string& GetCategory() const { return mCategory; }
90     
91     /// Returns the Package to which the box belongs (const pointer)
92     PackagePointer GetPackage() const { return mPackage; }
93     
94     /// Returns the kind of box 
95     Kind GetKind() const { return mKind; }
96
97     /// Prints help on the black box
98     virtual void GetHelp(bool full=true) const;
99
100     /// Returns a const ref on the map of input descriptors
101     const InputDescriptorMapType& GetInputDescriptorMap() const 
102       { return mInput; }
103       
104     /// Returns a const ref on the map of output descriptors
105     const OutputDescriptorMapType& GetOutputDescriptorMap() const 
106       { return mOutput; }
107       
108     /// Returns a const pointer on the descriptor of the input of name <name> 
109     const InputDescriptor* GetInputDescriptor(const std::string &name) const;
110
111     /// Returns a const pointer on the descriptor of the output of name <name> 
112     const OutputDescriptor* GetOutputDescriptor(const std::string &name) const;
113
114     /// Sets the name of the **TYPE** of BlackBox
115     void SetTypeName( const std::string& name ) { mTypeName=name; }
116
117     /// Adds the string to the BlackBox description
118     void AddToDescription( const std::string&, bool clear = false );
119     
120     /// Adds the string to the BlackBox author list
121     void AddToAuthor( const std::string&, bool clear = false );
122     
123     /// Adds the string to the BlackBox category list
124     void AddToCategory( const std::string&, bool clear = false );
125     
126     /// Sets the Package to which the box belongs
127     void SetPackage(PackagePointer package) { mPackage = package; }
128     
129     /// Sets the kind of box 
130     void SetKind(Kind kind) { mKind = kind; }
131
132     /* 
133    virtual void InsertHTMLGraph( std::ofstream& s, int detail, int level, 
134                                   const std::string& output_dir = "" ) { }
135     */
136     /// Writes html formatted help into the output file stream. 
137     /// detail and level are used for graphical representation of 
138     /// complex black boxes (see ComplexBlackBox::InsertHTMLGraph)
139     /// output_dir is the directory in which to write auxilliary files 
140     /// (.dot/.png/.cmap)
141     virtual void InsertHtmlHelp ( std::ofstream& s, 
142                                   int detail, int level,
143                                   const std::string& output_dir = "",
144                                   bool relative_link = false );
145     ///
146     virtual void Check(bool recursive=true) const;
147
148   protected:
149     /// Adds an input descriptor
150     void AddInputDescriptor( BlackBoxInputDescriptor *d ) 
151     { mInput[d->GetName()] = d; }
152     /// Adds an output descriptor
153     void AddOutputDescriptor( BlackBoxOutputDescriptor *d ) 
154     { mOutput[d->GetName()] = d; }
155
156     //  private:
157     /// The name of the type of black box
158     std::string mTypeName;
159     /// The description of the black box
160     std::string mDescription;
161     /// The author of the black box
162     std::string mAuthor;
163     /// The category of the black box
164     std::string mCategory;    
165     /// The kind of box (standard / adaptor)
166     Kind mKind;
167     /// The Package to which the box belongs
168     PackagePointer mPackage;
169     /// The inputs 
170     InputDescriptorMapType mInput;
171     /// The outputs 
172     OutputDescriptorMapType mOutput;
173
174   };
175   // class BlackBoxDescriptor
176   //==========================================================================
177
178
179  
180 }
181 // namespace bbtk
182 #endif