BaseNetwork.hxx

Go to the documentation of this file.
00001 /*
00002  * Copyright (c) 2008 Fundació Barcelona Media Universitat Pompeu Fabra
00003  *
00004  *
00005  * This program is free software; you can redistribute it and/or modify
00006  * it under the terms of the GNU General Public License as published by
00007  * the Free Software Foundation; either version 2 of the License, or
00008  * (at your option) any later version.
00009  *
00010  * This program is distributed in the hope that it will be useful,
00011  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00012  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00013  * GNU General Public License for more details.
00014  *
00015  * You should have received a copy of the GNU General Public License
00016  * along with this program; if not, write to the Free Software
00017  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00018  *
00019  */
00020 
00021 #ifndef _BaseNetwork_hxx_
00022 #define _BaseNetwork_hxx_
00023 
00024 #include "Processing.hxx"
00025 #include "InPort.hxx"
00026 #include "OutPort.hxx"
00027 #include "InControl.hxx"
00028 #include "OutControl.hxx"
00029 #include <string>
00030 #include <list>
00031 #include <map>
00032 #include <set>
00033 #include "Component.hxx"
00034 
00035 namespace CLAM
00036 {
00037 // abstract clase of a base Network
00038 class BaseNetwork : public Component
00039 {
00040 public:
00041         // used types
00042         typedef std::list<std::string> NamesList;
00043         typedef std::map <std::string, Processing* > ProcessingsMap;
00044         typedef std::list<InPortBase *> InPortsList;
00045 
00046         typedef struct { int x, y, width, height; } Geometry;
00047         typedef std::map <std::string, Geometry> ProcessingsGeometriesMap;
00048         typedef struct { std::string sourceName, sinkName; } Connection;
00049         typedef std::list<Connection> ConnectionsList;
00050 
00051         // constructor / destructor
00052         BaseNetwork() {}
00053         virtual ~BaseNetwork() {}
00054         virtual const char * GetClassName() const = 0;
00055         virtual void Clear() = 0;
00056 
00057         // serialization methods
00058         virtual void StoreOn( Storage & storage) const = 0;
00059         virtual void LoadFrom( Storage & storage) = 0;
00060 
00061         // name and processing id 
00062         virtual const std::string& GetName() const = 0;
00063         virtual void SetName( const std::string& name ) = 0;
00064         virtual const std::string & GetNetworkId(const Processing * proc) const = 0;
00065 
00066         // accessors to nodes and processing
00067         virtual ProcessingsMap::iterator BeginProcessings() = 0; // { return _processings.begin(); }
00068         virtual ProcessingsMap::iterator EndProcessings() = 0;// { return _processings.end(); }
00069         virtual ProcessingsMap::const_iterator BeginProcessings() const = 0; //{ return _processings.begin(); }
00070         virtual BaseNetwork::ProcessingsMap::const_iterator EndProcessings() const = 0; //{ return _processings.end(); }
00071 
00072         virtual NamesList  GetInPortsConnectedTo( const std::string & producer ) const = 0;
00073         virtual NamesList  GetInControlsConnectedTo( const std::string & producer ) const = 0;
00074         virtual InPortsList GetInPortsConnectedTo( OutPortBase & producer ) const = 0;
00075         virtual std::string GetConnectorIdentifier( const std::string& ) const = 0;
00076         virtual std::string GetProcessingIdentifier( const std::string& ) const = 0;
00077         virtual InPortBase & GetInPortByCompleteName( const std::string & name ) const = 0;
00078         virtual OutPortBase & GetOutPortByCompleteName( const std::string & name ) const = 0;
00079         virtual InControl & GetInControlByCompleteName( const std::string & name ) const = 0;
00080         virtual OutControl & GetOutControlByCompleteName( const std::string & name ) const = 0;
00081 
00082         // methods related to connect/disconnect interface
00083         virtual bool ConnectPorts( const std::string &, const std::string & ) = 0;
00084         virtual bool ConnectControls( const std::string &, const std::string & ) = 0;
00085         virtual bool DisconnectPorts( const std::string &, const std::string & ) = 0;
00086         virtual bool DisconnectControls( const std::string &, const std::string & ) = 0;
00087 
00092         virtual std::string GetUnconnectedInPorts() const = 0;
00094         virtual bool HasProcessing( const std::string & name ) const = 0;
00095         virtual Processing& GetProcessing( const std::string & name ) const = 0;
00097         virtual void AddProcessing( const std::string &, Processing* ) = 0;
00099         virtual void AddProcessing( const std::string & name, const std::string & key ) = 0;
00100         virtual std::string AddProcessing( const std::string& key ) = 0;
00101         virtual std::string GetUnusedName( const std::string& prefix ) const = 0;
00102         virtual bool RenameProcessing( const std::string & oldName, const std::string & newName ) = 0;
00103         virtual void RemoveProcessing ( const std::string & ) = 0;
00104 
00110         virtual bool IsReady() const = 0;
00112         virtual bool IsEmpty() const = 0;
00114         virtual bool HasMisconfiguredProcessings() const = 0;
00116         virtual bool HasUnconnectedInPorts() const = 0;
00121         virtual bool HasSyncSource() const = 0;
00125         virtual bool ConfigureProcessing( const std::string &, const ProcessingConfig & ) = 0;
00127         virtual void ReconfigureAllProcessings() = 0;
00132         virtual std::string GetConfigurationErrors() const = 0;
00133         // methods related to copy&paste processings from canvas
00134         virtual bool UpdateSelections (const NamesList & processingsNamesList) = 0;
00135         virtual void setPasteMode() = 0;
00136         // canvas related geometries
00137         virtual bool SetProcessingsGeometries (const ProcessingsGeometriesMap & processingsGeometries) = 0;
00138         virtual const ProcessingsGeometriesMap GetAndClearGeometries() = 0;
00139 /*// TODO: make individual geometries loadings/storings??
00140         const Geometry GetAndEraseGeometry(std::string name);*/
00141 
00142         virtual unsigned BackendBufferSize() = 0;
00143         virtual unsigned BackendSampleRate() = 0;
00144 
00145 protected:
00146         static std::size_t PositionOfLastIdentifier( const std::string& str)
00147         {
00148                 std::size_t result = str.find_last_of( NamesIdentifiersSeparator() );
00149                 CLAM_ASSERT( result!=std::string::npos, "Malformed port/control name. It should be ProcessingName.[Port/Control]Name");
00150                 return result;
00151         }
00152         static std::size_t PositionOfProcessingIdentifier( const std::string& str)
00153         {
00154                 std::size_t endPos = PositionOfLastIdentifier(str)-1;
00155                 std::size_t     last_ofResult = str.find_last_of( NamesIdentifiersSeparator(), endPos );
00156                 return last_ofResult == std::string::npos ? 0 : last_ofResult+1;
00157         }
00158         static char NamesIdentifiersSeparator()
00159         {
00160                 return '.';
00161         }
00162         // attributes for canvas copy & paste
00163         typedef std::set<std::string> NamesSet;
00164         virtual bool HasSelectionAndContains(const std::string & name) const = 0;
00165 
00166         //virtual const ConnectionsList GetPortsConnections() =0;
00167         //virtual const ConnectionsList GetControlsConnections()=0;
00168         //virtual void RefreshConnections() =0;
00169 };
00170 }
00171 #endif

Generated on Tue Aug 12 22:33:42 2008 for CLAM by  doxygen 1.5.5