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