]> Creatis software - bbtk.git/blob - kernel/src/bbtkBlackBoxDescriptor.h
97c57b88aea39df86e2b3d812deaec14dc062abc
[bbtk.git] / kernel / src / bbtkBlackBoxDescriptor.h
1 /*=========================================================================                                                                               
2   Program:   bbtk
3   Module:    $RCSfile: bbtkBlackBoxDescriptor.h,v $
4   Language:  C++
5   Date:      $Date: 2012/11/14 07:12:00 $
6   Version:   $Revision: 1.12 $
7 =========================================================================*/
8
9 /* ---------------------------------------------------------------------
10
11 * Copyright (c) CREATIS-LRMN (Centre de Recherche en Imagerie Medicale)
12 * Authors : Eduardo Davila, Laurent Guigues, Jean-Pierre Roux
13 *
14 *  This software is governed by the CeCILL-B license under French law and 
15 *  abiding by the rules of distribution of free software. You can  use, 
16 *  modify and/ or redistribute the software under the terms of the CeCILL-B 
17 *  license as circulated by CEA, CNRS and INRIA at the following URL 
18 *  http://www.cecill.info/licences/Licence_CeCILL-B_V1-en.html 
19 *  or in the file LICENSE.txt.
20 *
21 *  As a counterpart to the access to the source code and  rights to copy,
22 *  modify and redistribute granted by the license, users are provided only
23 *  with a limited warranty  and the software's author,  the holder of the
24 *  economic rights,  and the successive licensors  have only  limited
25 *  liability. 
26 *
27 *  The fact that you are presently reading this means that you have had
28 *  knowledge of the CeCILL-B license and that you accept its terms.
29 * ------------------------------------------------------------------------ */                                                                         
30
31
32 /**
33  *  \file 
34  *  \brief Class bbtk::BlackBoxDescriptor : (abstract) describes of a BlackBox (name, description, author) and is able to create an instance of it.
35  */
36 /**
37  * \class bbtk::BlackBoxDescriptor
38  * \brief (Abstract) Contains information on a BlackBox type (name, description, author, inputs, outputs) and is able to create an instance of it.
39  */
40
41 #ifndef __bbtkBlackBoxDescriptor_h__
42 #define __bbtkBlackBoxDescriptor_h__
43
44 #include "bbtkObject.h"
45 #include "bbtkBlackBoxInputDescriptor.h"
46 #include "bbtkBlackBoxOutputDescriptor.h"
47 #include <map>
48 #include <fstream>
49
50 namespace bbtk
51 {
52
53   class BlackBox;
54   class Package;
55   BBTK_FORWARD_DECLARE_POINTER(BlackBox);
56   BBTK_FORWARD_DECLARE_POINTER(Package);
57
58   //==========================================================================
59   class BBTK_EXPORT BlackBoxDescriptor : public Object
60   {
61     BBTK_ABSTRACT_OBJECT_INTERFACE(BlackBoxDescriptor);
62   public:
63     /// The type of descriptor of inputs 
64     typedef BlackBoxInputDescriptor InputDescriptor;
65     /// The type of descriptor of outputs 
66     typedef BlackBoxOutputDescriptor OutputDescriptor;
67     /// The type of dictionnary of inputs = map of input descriptors pointers 
68     typedef std::map<std::string, InputDescriptor*> InputDescriptorMapType;
69     /// The type of dictionnary of outputs= map of output descriptors pointers 
70     typedef std::map<std::string, OutputDescriptor*> OutputDescriptorMapType;
71     /// The kinds of black box
72     typedef enum
73     {
74       STANDARD=0,
75       ADAPTOR=1,
76       DEFAULT_ADAPTOR=2,
77       GUI=3,
78       DEFAULT_GUI=4
79     }
80     Kind;
81
82         typedef enum
83         {
84                 TS_BINARY=0,
85                 TS_SCRIPT_COMPLEXBOX=1,
86                 TS_SCRIPT_APPLICATION=2
87         } TypeOfScript;
88           
89     /// Releases a descriptor
90     //    static void Release(BlackBoxDescriptor::WeakPointer);
91
92      /// Creates an instance with name boxname of the BlackBox
93     /// of which this is the descriptor 
94     virtual BlackBoxPointer NewBlackBox(const std::string& boxname) = 0;
95
96     /// Returns the name of the **TYPE** of the black box
97     const std::string& GetTypeName() const { return mTypeName; }
98     
99     /// Returns the full name of the **TYPE** of the black box (+package name)
100     std::string GetFullTypeName() const;
101     
102     /// Returns the description of the BlackBox 
103     const std::string& GetDescription() const { return mDescription; }
104     
105     /// Returns the author(s) of the BlackBox
106     const std::string& GetAuthor() const { return mAuthor; }
107     
108     /// Returns the category(s) of the BlackBox
109     const std::string& GetCategory() const { return mCategory; }
110     
111     /// Returns the Package to which the box belongs (const pointer)
112     PackagePointer GetPackage() const { return mPackage; }
113     
114     /// Returns the kind of box 
115     Kind GetKind() const { return mKind; }
116
117     /// Prints help on the black box
118     virtual void GetHelp(bool full=true) const;
119
120     /// Returns a const ref on the map of input descriptors
121     const InputDescriptorMapType& GetInputDescriptorMap() const 
122       { return mInput; }
123       
124     /// Returns a const ref on the map of output descriptors
125     const OutputDescriptorMapType& GetOutputDescriptorMap() const 
126       { return mOutput; }
127       
128     /// Returns a const pointer on the descriptor of the input of name <name> 
129     const InputDescriptor* GetInputDescriptor(const std::string &name) const;
130
131     /// Returns a const pointer on the descriptor of the output of name <name> 
132     const OutputDescriptor* GetOutputDescriptor(const std::string &name) const;
133
134     /// Sets the name of the **TYPE** of BlackBox
135     void SetTypeName( const std::string& name ) { mTypeName=name; }
136
137     /// Adds the string to the BlackBox description
138     void AddToDescription( const std::string&, bool clear = false );
139     
140     /// Adds the string to the BlackBox author list
141     void AddToAuthor( const std::string&, bool clear = false );
142     
143     /// Adds the string to the BlackBox category list
144     void AddToCategory( const std::string&, bool clear = false );
145     
146     /// Sets the Package to which the box belongs
147     void SetPackage(PackagePointer package) { mPackage = package; }
148     
149     /// Sets the kind of box 
150     void SetKind(Kind kind) { mKind = kind; }
151
152     /* 
153    virtual void InsertHTMLGraph( std::ofstream& s, int detail, int level, 
154                                   const std::string& output_dir = "" ) { }
155     */
156     /// Writes html formatted help into the output file stream. 
157     /// detail and level are used for graphical representation of 
158     /// complex black boxes (see ComplexBlackBox::InsertHTMLGraph)
159     /// output_dir is the directory in which to write auxilliary files 
160     /// (.dot/.png/.cmap)
161     virtual void InsertHtmlHelp ( std::ofstream& s, 
162                                   int detail, int level,
163                                   const std::string& output_dir = "",
164                                   bool relative_link = false );
165     ///
166     virtual void Check(bool recursive=true) const;
167
168           
169           
170           /// Sets the name of the script file from which it is defined
171           void SetScriptFileName(const std::string& n) { mScriptFileName = n; }
172           /// Gets the name of the script file from which it is defined
173           std::string GetScriptFileName() const { return mScriptFileName; }
174           
175           
176           
177           
178           /// Gets the type of script  BINARY, SCRIPT_COMPLEXBOX, SCRIPT_APPLICATION 
179           TypeOfScript GetTypeOfScript()                        {       return mTypeOfScript;   };
180           void SetTypeOfScript(TypeOfScript type)       {       mTypeOfScript=type;             };        
181           bool IsTypeOfScript_Application();
182           bool IsTypeOfScript_ComplexBox();
183           void SetTypeOfScript_Application();
184           
185           
186           
187           
188   private:
189           
190           TypeOfScript mTypeOfScript;
191           
192           /// The name of the script file from which it was created
193           std::string mScriptFileName;
194           
195           
196           
197   protected:
198     /// Adds an input descriptor
199     void AddInputDescriptor( BlackBoxInputDescriptor *d ) 
200     { mInput[d->GetName()] = d; }
201     /// Adds an output descriptor
202     void AddOutputDescriptor( BlackBoxOutputDescriptor *d ) 
203     { mOutput[d->GetName()] = d; }
204
205     //  private:
206     /// The name of the type of black box
207     std::string mTypeName;
208     /// The description of the black box
209     std::string mDescription;
210     /// The author of the black box
211     std::string mAuthor;
212     /// The category of the black box
213     std::string mCategory;    
214     /// The kind of box (standard / adaptor)
215     Kind mKind;
216     /// The Package to which the box belongs
217     PackagePointer mPackage;
218     /// The inputs 
219     InputDescriptorMapType mInput;
220     /// The outputs 
221     OutputDescriptorMapType mOutput;
222
223   };
224   // class BlackBoxDescriptor
225   //==========================================================================
226
227
228  
229 }
230 // namespace bbtk
231 #endif