GLIP-Lib
 All Classes Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
LayoutLoaderModules.hpp
Go to the documentation of this file.
1 /* ************************************************************************************************************* */
2 /* */
3 /* GLIP-LIB */
4 /* OpenGL Image Processing LIBrary */
5 /* */
6 /* Author : R. Kerviche */
7 /* LICENSE : MIT License */
8 /* Website : glip-lib.net */
9 /* */
10 /* File : LayoutLoaderModules.hpp */
11 /* Original Date : October 14th 2013 */
12 /* */
13 /* Description : Layout Loader Modules. */
14 /* */
15 /* ************************************************************************************************************* */
16 
24 #ifndef __LAYOUT_LOADER_MODULES_INCLUDE__
25 #define __LAYOUT_LOADER_MODULES_INCLUDE__
26 
27  #include <vector>
28  #include "Core/LibTools.hpp"
29  #include "Core/HdlTexture.hpp"
30  #include "Core/Geometry.hpp"
31  #include "Core/ShaderSource.hpp"
32  #include "Core/Filter.hpp"
33  #include "Core/Pipeline.hpp"
34  #include "Modules/VanillaParser.hpp"
35 
36 namespace Glip
37 {
38  using namespace CoreGL;
39  using namespace CorePipeline;
40 
41  namespace Modules
42  {
43  // Prototype :
44  class LayoutLoader;
45 
46  // Classes :
746  class GLIP_API LayoutLoaderModule
747  {
748  private :
749  const std::string name;
750  std::string description,
751  bodyDescription;
752  std::vector<std::pair<std::string,std::string> > argumentsDescriptions;
753  const int minNumArguments,
754  maxNumArguments;
755  const char bodyPresence;
756 
757  void initManual(const std::string& _manual);
758 
759  protected :
760  LayoutLoaderModule( const std::string& _name, const std::string& _manual, const int& _minNumArguments, const int& _maxNumArguments, const char& _bodyPresence);
761 
762  public :
764  virtual ~LayoutLoaderModule(void);
765 
802  virtual void apply( const std::vector<std::string>& arguments,
803  const std::string& body,
804  const std::string& currentPath,
805  std::vector<std::string>& dynamicPaths,
806  std::map<std::string, HdlTextureFormat>& formatList,
807  std::map<std::string, ShaderSource>& sourceList,
808  std::map<std::string, GeometryModel>& geometryList,
809  std::map<std::string, FilterLayout>& filterList,
810  std::map<std::string, PipelineLayout>& pipelineList,
811  std::string& mainPipelineName,
812  const std::vector<std::string>& staticPaths,
813  const std::map<std::string, HdlTextureFormat>& requiredFormatList,
814  const std::map<std::string, ShaderSource>& requiredSourceList,
815  const std::map<std::string, GeometryModel>& requiredGeometryList,
816  const std::map<std::string, PipelineLayout>& requiredPipelineList,
817  const std::map<std::string, LayoutLoaderModule*>& moduleList,
818  const std::string& sourceName,
819  const int startLine,
820  const int bodyLine,
821  std::string& executionSource,
822  std::string& executionSourceName,
823  int& executionStartLine) = 0;
824 
825  const std::string& getName(void) const;
826  const int& getMinNumArguments(void) const;
827  const int& getMaxNumArguments(void) const;
828  const char& bodyPresenceTest(void) const;
829  const std::string& getDescription(void) const;
830  const std::string& getBodyDescription(void) const;
831  const std::vector<std::pair<std::string,std::string> >& getArgumentsDescriptions(void) const;
832  std::string getManual(void) const;
833 
834  // Events :
835  virtual void beginLoadLayout(void);
836  virtual void endLoadLayout(void);
837 
838  // Static tools :
839  static void addBasicModules(LayoutLoader& loader);
840  static std::vector<LayoutLoaderModule*> getBasicModulesList(void);
841  static bool getBoolean(const std::string& arg, const std::string& sourceName="", int line=1);
842  static void getCases(const std::string& body, std::string& trueCase, int& trueCaseStartLine, std::string& falseCase, int& falseCaseStartLine, const std::string& sourceName="", int bodyLine=1);
843  static std::vector<std::string> findFile(const std::string& filename, const std::vector<std::string>& dynamicPaths);
844  };
845 
846  // Simple MACROS :
848  #define LAYOUT_LOADER_ARGUMENTS_LIST const std::vector<std::string>& arguments, \
849  const std::string& body, \
850  const std::string& currentPath, \
851  std::vector<std::string>& dynamicPaths, \
852  std::map<std::string, Glip::CoreGL::HdlTextureFormat>& formatList, \
853  std::map<std::string, Glip::CoreGL::ShaderSource>& sourceList, \
854  std::map<std::string, Glip::CorePipeline::GeometryModel>& geometryList, \
855  std::map<std::string, Glip::CorePipeline::FilterLayout>& filterList, \
856  std::map<std::string, Glip::CorePipeline::PipelineLayout>& pipelineList, \
857  std::string& mainPipelineName, \
858  const std::vector<std::string>& staticPaths, \
859  const std::map<std::string, Glip::CoreGL::HdlTextureFormat>& requiredFormatList, \
860  const std::map<std::string, Glip::CoreGL::ShaderSource>& requiredSourceList, \
861  const std::map<std::string, Glip::CorePipeline::GeometryModel>& requiredGeometryList, \
862  const std::map<std::string, Glip::CorePipeline::PipelineLayout>& requiredPipelineList, \
863  const std::map<std::string, Glip::Modules::LayoutLoaderModule*>& moduleList, \
864  const std::string& sourceName, \
865  const int startLine, \
866  const int bodyLine, \
867  std::string& executionSource, \
868  std::string& executionSourceName, \
869  int& executionStartLine
870 
872  #define LAYOUT_LOADER_MODULE_DEFINITION( name ) class name : public Glip::Modules::LayoutLoaderModule \
873  { \
874  public : \
875  name (void); \
876  \
877  void apply(LAYOUT_LOADER_ARGUMENTS_LIST); \
878  };
879 
881  #define LAYOUT_LOADER_MODULE_APPLY( moduleName, minArgs, maxArgs, bodyPresence, moduleManual) \
882  moduleName :: moduleName (void) : Glip::Modules::LayoutLoaderModule( #moduleName, moduleManual, minArgs, maxArgs, bodyPresence) { } \
883  void moduleName :: apply(LAYOUT_LOADER_ARGUMENTS_LIST)
884 
885 
886  #define __ITERATOR_FIND(type, varName, iteratorName, elementName) std::map<std::string, type >::iterator iteratorName = varName.find( elementName );
887  #define __CONST_ITERATOR_FIND(type, varName, iteratorName, elementName) std::map<std::string, type >::const_iterator iteratorName = varName.find( elementName );
888  #define __ELEMENT_MUST_BE_IN(iteratorName, varName, elementName) { if(iteratorName==varName.end()) throw Exception("Element \"" + elementName + "\" was not found in \"" + #varName + "\".", sourceName, startLine, Exception::ClientScriptException); }
889  #define __ELEMENT_MUST_NOT_BE_IN(iteratorName, varName, elementName) { if(iteratorName!=varName.end()) throw Exception("Element \"" + elementName + "\" already exists in \"" + #varName + "\".", sourceName, startLine, Exception::ClientScriptException); }
890  #define __APPEND_NEW_ELEMENT(type, varName, elementName, element) varName.insert( std::pair<std::string, type>( elementName, element ) );
891 
893  #define ITERATOR_TO_FORMAT( iteratorName, elementName ) __ITERATOR_FIND(Glip::CoreGL::HdlTextureFormat, formatList, iteratorName, elementName)
894 
895  #define CONST_ITERATOR_TO_FORMAT( iteratorName, elementName ) __CONST_ITERATOR_FIND(Glip::CoreGL::HdlTextureFormat, formatList, iteratorName, elementName)
896 
897  #define VALID_ITERATOR_TO_FORMAT( iteratorName ) ( iteratorName != formatList.end() )
898 
899  #define FORMAT_MUST_EXIST( elementName ) { __CONST_ITERATOR_FIND(Glip::CoreGL::HdlTextureFormat, formatList, iteratorName, elementName) __ELEMENT_MUST_BE_IN(iteratorName, formatList, elementName) }
900 
901  #define FORMAT_MUST_NOT_EXIST( elementName ) { __CONST_ITERATOR_FIND(Glip::CoreGL::HdlTextureFormat, formatList, iteratorName, elementName) __ELEMENT_MUST_NOT_BE_IN(iteratorName, formatList, elementName) }
902 
903  #define APPEND_NEW_FORMAT(elementName, newElement) __APPEND_NEW_ELEMENT(Glip::CoreGL::HdlTextureFormat, formatList, elementName, newElement)
904 
906  #define ITERATOR_TO_SOURCE( iteratorName, elementName ) __ITERATOR_FIND(Glip::CoreGL::ShaderSource, sourceList, iteratorName, elementName)
907 
908  #define CONST_ITERATOR_TO_SOURCE( iteratorName, elementName ) __CONST_ITERATOR_FIND(Glip::CoreGL::ShaderSource, sourceList, iteratorName, elementName)
909 
910  #define VALID_ITERATOR_TO_SOURCE( iteratorName ) ( iteratorName != sourceList.end() )
911 
912  #define SOURCE_MUST_EXIST( elementName ) { __CONST_ITERATOR_FIND(Glip::CoreGL::ShaderSource, sourceList, iteratorName, elementName) __ELEMENT_MUST_BE_IN(iteratorName, sourceList, elementName) }
913 
914  #define SOURCE_MUST_NOT_EXIST( elementName ) { __CONST_ITERATOR_FIND(Glip::CoreGL::ShaderSource, sourceList, iteratorName, elementName) __ELEMENT_MUST_NOT_BE_IN(iteratorName, sourceList, elementName) }
915 
916  #define APPEND_NEW_SOURCE(elementName, newElement) __APPEND_NEW_ELEMENT(Glip::CoreGL::ShaderSource, sourceList, elementName, newElement)
917 
919  #define ITERATOR_TO_GEOMETRY( iteratorName, elementName ) __ITERATOR_FIND(Glip::CorePipeline::GeometryModel, geometryList, iteratorName, elementName)
920 
921  #define CONST_ITERATOR_TO_GEOMETRY( iteratorName, elementName ) __CONST_ITERATOR_FIND(Glip::CorePipeline::GeometryModel, geometryList, iteratorName, elementName)
922 
923  #define VALID_ITERATOR_TO_GEOMETRY( iteratorName ) ( iteratorName != geometryList.end() )
924 
925  #define GEOMETRY_MUST_EXIST( elementName ) { __CONST_ITERATOR_FIND(Glip::CorePipelin::GeometryModel, geometryList, iteratorName, elementName) __ELEMENT_MUST_BE_IN(iteratorName, geometryList, elementName) }
926 
927  #define GEOMETRY_MUST_NOT_EXIST( elementName ) { __CONST_ITERATOR_FIND(Glip::CorePipeline::GeometryModel, geometryList, iteratorName, elementName) __ELEMENT_MUST_NOT_BE_IN(iteratorName, geometryList, elementName) }
928 
929  #define APPEND_NEW_GEOMETRY(elementName, newElement) __APPEND_NEW_ELEMENT(Glip::CorePipeline::GeometryModel, geometryList, elementName, newElement)
930 
932  #define ITERATOR_TO_FILTER( iteratorName, elementName ) __ITERATOR_FIND(Glip::CorePipeline::FilterLayout, filterList, iteratorName, elementName)
933 
934  #define CONST_ITERATOR_TO_FILTER( iteratorName, elementName ) __CONST_ITERATOR_FIND(Glip::CorePipeline::FilterLayout, filterList, iteratorName, elementName)
935 
936  #define VALID_ITERATOR_TO_FILTER( iteratorName ) ( iteratorName != filterList.end() )
937 
938  #define FILTER_MUST_EXIST( elementName ) { __CONST_ITERATOR_FIND(Glip::CorePipeline::FilterLayout, filterList, iteratorName, elementName) __ELEMENT_MUST_BE_IN(iteratorName, filterList, elementName) }
939 
940  #define FILTER_MUST_NOT_EXIST( elementName ) { __CONST_ITERATOR_FIND(Glip::CorePipeline::FilterLayout, filterList, iteratorName, elementName) __ELEMENT_MUST_NOT_BE_IN(iteratorName, filterList, elementName) }
941 
942  #define APPEND_NEW_FILTER(elementName, newElement) __APPEND_NEW_ELEMENT(Glip::CorePipeline::FilterLayout, filterList, elementName, newElement)
943 
945  #define ITERATOR_TO_PIPELINE( iteratorName, elementName ) __ITERATOR_FIND(Glip::CorePipeline::PipelineLayout, pipelineList, iteratorName, elementName)
946 
947  #define CONST_ITERATOR_TO_PIPELINE( iteratorName, elementName ) __CONST_ITERATOR_FIND(Glip::CorePipeline::PipelineLayout, pipelineList, iteratorName, elementName)
948 
949  #define VALID_ITERATOR_TO_PIPELINE( iteratorName ) ( iteratorName != pipelineList.end() )
950 
951  #define PIPELINE_MUST_EXIST( elementName ) { __CONST_ITERATOR_FIND(Glip::CorePipeline::PipelineLayout, pipelineList, iteratorName, elementName) __ELEMENT_MUST_BE_IN(iteratorName, pipelineList, elementName) }
952 
953  #define PIPELINE_MUST_NOT_EXIST( elementName ) { __CONST_ITERATOR_FIND(Glip::CorePipeline::PipelineLayout, pipelineList, iteratorName, elementName) __ELEMENT_MUST_NOT_BE_IN(iteratorName, pipelineList, elementName) }
954 
955  #define APPEND_NEW_PIPELINE(elementName, newElement) __APPEND_NEW_ELEMENT(Glip::CorePipeline::PipelineLayout, pipelineList, elementName, newElement)
956 
958  #define CONST_ITERATOR_TO_REQUIREDFORMAT( iteratorName, elementName ) __CONST_ITERATOR_FIND(Glip::CoreGL::HdlTextureFormat, requiredFormatList, iteratorName, elementName)
959 
960  #define VALID_ITERATOR_TO_REQUIREDFORMAT( iteratorName ) ( iteratorName != requiredFormatList.end() )
961 
962  #define REQUIREDFORMAT_MUST_EXIST( elementName ) { __CONST_ITERATOR_FIND(Glip::CoreGL::HdlTextureFormat, requiredFormatList, iteratorName, elementName) __ELEMENT_MUST_BE_IN(iteratorName, requiredFormatList, elementName) }
963 
964  #define REQUIREDFORMAT_MUST_NOT_EXIST( elementName ) { __CONST_ITERATOR_FIND(Glip::CoreGL::HdlTextureFormat, requiredFormatList, iteratorName, elementName) __ELEMENT_MUST_NOT_BE_IN(iteratorName, requiredFormatList, elementName) }
965 
967  #define CONST_ITERATOR_TO_REQUIREDSOURCE( iteratorName, elementName ) __CONST_ITERATOR_FIND(Glip::CoreGL::ShaderSource, requiredSourceList, iteratorName, elementName)
968 
969  #define VALID_ITERATOR_TO_REQUIREDSOURCE( iteratorName ) ( iteratorName != requiredSourceList.end() )
970 
971  #define REQUIREDSOURCE_MUST_EXIST( elementName ) { __CONST_ITERATOR_FIND(Glip::CoreGL::ShaderSource, requiredSourceList, iteratorName, elementName) __ELEMENT_MUST_BE_IN(iteratorName, requiredSourceList, elementName) }
972 
973  #define REQUIREDSOURCE_MUST_NOT_EXIST( elementName ) { __CONST_ITERATOR_FIND(Glip::CoreGL::ShaderSource, requiredSourceList, iteratorName, elementName) __ELEMENT_MUST_NOT_BE_IN(iteratorName, requiredSourceList, elementName) }
974 
976  #define CONST_ITERATOR_TO_REQUIREDGEOMETRY( iteratorName, elementName ) __CONST_ITERATOR_FIND(Glip::CorePipeline::GeometryModel, requiredGeometryList, iteratorName, elementName)
977 
978  #define VALID_ITERATOR_TO_REQUIREDGEOMETRY( iteratorName ) ( iteratorName != requiredGeometryList.end() )
979 
980  #define REQUIREDGEOMETRY_MUST_EXIST( elementName ) { __CONST_ITERATOR_FIND(Glip::CorePipeline::GeometryModel, requiredGeometryList, iteratorName, elementName) __ELEMENT_MUST_BE_IN(iteratorName, requiredGeometryList, elementName) }
981 
982  #define REQUIREDGEOMETRY_MUST_NOT_EXIST( elementName ) { __CONST_ITERATOR_FIND(Glip::CorePipeline::GeometryModel, requiredGeometryList, iteratorName, elementName) __ELEMENT_MUST_NOT_BE_IN(iteratorName, requiredGeometryList, elementName) }
983 
985  #define CONST_ITERATOR_TO_REQUIREDPIPELINE( iteratorName, elementName ) __CONST_ITERATOR_FIND(Glip::CorePipeline::PipelineLayout, requiredPipelineList, iteratorName, elementName)
986 
987  #define VALID_ITERATOR_TO_REQUIREDPIPELINE( iteratorName ) ( iteratorName != requiredPipelineList.end() )
988 
989  #define REQUIREDPIPELINE_MUST_EXIST( elementName ) { __CONST_ITERATOR_FIND(Glip::CorePipeline::PipelineLayout, requiredPipelineList, iteratorName, elementName) __ELEMENT_MUST_BE_IN(iteratorName, requirePipelineList, elementName) }
990 
991  #define REQUIREDPIPELINE_MUST_NOT_EXIST( elementName ) { __CONST_ITERATOR_FIND(Glip::CorePipeline::PipelineLayout, requiredPipelineList, iteratorName, elementName) __ELEMENT_MUST_NOT_BE_IN(iteratorName, requiredPipelineList, elementName) }
992 
994  #define CONST_ITERATOR_TO_MODULE( iteratorName, elementName ) __CONST_ITERATOR_FIND(Glip::Modules::LayoutLoaderModule*, moduleList, iteratorName, elementName)
995 
996  #define VALID_ITERATOR_TO_MODULE( iteratorName ) ( iteratorName != moduleList.end() )
997 
998  #define MODULE_MUST_EXIST( elementName ) { __CONST_ITERATOR_FIND(Glip::Modules::LayoutLoaderModule*, moduleList, iteratorName, elementName) __ELEMENT_MUST_BE_IN(iteratorName, moduleList, elementName) }
999 
1000  #define MODULE_MUST_NOT_EXIST( elementName ) { __CONST_ITERATOR_FIND(Glip::Modules::LayoutLoaderModule*, moduleList, iteratorName, elementName) __ELEMENT_MUST_NOT_BE_IN(iteratorName, moduleList, elementName) }
1001 
1002 
1004  #define CAST_ARGUMENT( argID, type, varName ) type varName; if(!fromString(arguments[ argID ], varName)) throw Exception("Unable to cast argument " + toString( argID ) + " (\"" + arguments[argID] + "\") to " + #type + ".", sourceName, startLine, Exception::ClientScriptException);
1005 
1006  // Basic Modules :
1007  LAYOUT_LOADER_MODULE_DEFINITION( IF_MODULE_AVAILABLE )
1008  LAYOUT_LOADER_MODULE_DEFINITION( IF_FORMAT_DEFINED )
1009  LAYOUT_LOADER_MODULE_DEFINITION( IF_SOURCE_DEFINED )
1010  LAYOUT_LOADER_MODULE_DEFINITION( IF_GEOMETRY_DEFINED )
1011  LAYOUT_LOADER_MODULE_DEFINITION( IF_FILTERLAYOUT_DEFINED )
1012  LAYOUT_LOADER_MODULE_DEFINITION( IF_PIPELINELAYOUT_DEFINED )
1013  LAYOUT_LOADER_MODULE_DEFINITION( IF_REQUIREDFORMAT_DEFINED )
1014  LAYOUT_LOADER_MODULE_DEFINITION( IF_REQUIREDSOURCE_DEFINED )
1015  LAYOUT_LOADER_MODULE_DEFINITION( IF_REQUIREDGEOMETRY_DEFINED )
1016  LAYOUT_LOADER_MODULE_DEFINITION( IF_REQUIREDPIPELINE_DEFINED )
1017  LAYOUT_LOADER_MODULE_DEFINITION( FORMAT_CHANGE_SIZE )
1018  LAYOUT_LOADER_MODULE_DEFINITION( FORMAT_INCREASE_SIZE )
1019  LAYOUT_LOADER_MODULE_DEFINITION( FORMAT_DECREASE_SIZE )
1020  LAYOUT_LOADER_MODULE_DEFINITION( FORMAT_SCALE_SIZE )
1021  LAYOUT_LOADER_MODULE_DEFINITION( FORMAT_INVSCALE_SIZE )
1022  LAYOUT_LOADER_MODULE_DEFINITION( FORMAT_CHANGE_CHANNELS )
1023  LAYOUT_LOADER_MODULE_DEFINITION( FORMAT_CHANGE_DEPTH )
1024  LAYOUT_LOADER_MODULE_DEFINITION( FORMAT_CHANGE_FILTERING )
1025  LAYOUT_LOADER_MODULE_DEFINITION( FORMAT_CHANGE_WRAPPING )
1026  LAYOUT_LOADER_MODULE_DEFINITION( FORMAT_CHANGE_MIPMAP )
1027  LAYOUT_LOADER_MODULE_DEFINITION( FORMAT_MINIMUM_WIDTH )
1028  LAYOUT_LOADER_MODULE_DEFINITION( FORMAT_MAXIMUM_WIDTH )
1029  LAYOUT_LOADER_MODULE_DEFINITION( FORMAT_MINIMUM_HEIGHT )
1030  LAYOUT_LOADER_MODULE_DEFINITION( FORMAT_MAXIMUM_HEIGHT )
1031  LAYOUT_LOADER_MODULE_DEFINITION( FORMAT_MINIMUM_PIXELS )
1032  LAYOUT_LOADER_MODULE_DEFINITION( FORMAT_MAXIMUM_PIXELS )
1033  LAYOUT_LOADER_MODULE_DEFINITION( FORMAT_MINIMUM_ELEMENTS )
1034  LAYOUT_LOADER_MODULE_DEFINITION( FORMAT_MAXIMUM_ELEMENTS )
1035  LAYOUT_LOADER_MODULE_DEFINITION( FORMAT_SMALLER_POWER_OF_TWO )
1036  LAYOUT_LOADER_MODULE_DEFINITION( FORMAT_LARGER_POWER_OF_TWO )
1037  LAYOUT_LOADER_MODULE_DEFINITION( FORMAT_SWAP_DIMENSIONS )
1038  LAYOUT_LOADER_MODULE_DEFINITION( IF_FORMAT_SETTING_MATCH )
1039  LAYOUT_LOADER_MODULE_DEFINITION( IF_FORMAT_SETTING_LARGERTHAN )
1040  LAYOUT_LOADER_MODULE_DEFINITION( GENERATE_SAME_SIZE_2D_GRID )
1041  LAYOUT_LOADER_MODULE_DEFINITION( GENERATE_SAME_SIZE_3D_GRID )
1042  LAYOUT_LOADER_MODULE_DEFINITION( CHAIN_PIPELINES )
1043  LAYOUT_LOADER_MODULE_DEFINITION( FORMAT_TO_CONSTANT )
1044  LAYOUT_LOADER_MODULE_DEFINITION( SINGLE_FILTER_PIPELINE )
1045  LAYOUT_LOADER_MODULE_DEFINITION( IF_GLSL_VERSION_MATCH )
1046  LAYOUT_LOADER_MODULE_DEFINITION( ABORT_ERROR )
1047  }
1048 }
1049 
1050 #endif
1051 
Specific defines for the API structure.
Pipeline object.
Filter object.
Small file parser.
Module description for the LayoutLoader class.
Definition: LayoutLoaderModules.hpp:746
OpenGL Texture Handle.
Definition: Component.hpp:32
Shader source and tools.
Geometry objects and memory management.
#define LAYOUT_LOADER_MODULE_DEFINITION(name)
Definition: LayoutLoaderModules.hpp:872
Load and save pipelines layouts to file.
Definition: LayoutLoader.hpp:706