00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018 #ifndef VRS_IO_OBJECTLOADER_H
00019 #define VRS_IO_OBJECTLOADER_H
00020
00021 #include <vrs/io/dataresource.h>
00022 #include <vrs/io/ioexceptions.h>
00023 #include <vector>
00024
00025 namespace VRS {
00026
00027 class ObjectReader;
00028 class DataFilter;
00029
00031 class VRS_CORE_API ObjectLoader : public SharedObj {
00032 public:
00033 static bool install(SO<ObjectReader> readerToInstall);
00034 static bool uninstall(SO<ObjectReader> readerToUninstall);
00035 static SO<Iterator<SO<ObjectReader> > > objectReaders();
00037
00038 static bool install(SO<DataFilter> filterToInstall);
00039 static bool uninstall(SO<DataFilter> filterToUninstall);
00040 static SO<Iterator<SO<DataFilter> > > dataFilters();
00042
00043 static SO<SharedObj> readFile(
00044 const std::string& filename,
00045 const ID& targetType = SharedObj::ClassNameVRS(),
00046 bool throwExceptions = false
00047 );
00048 static SO<SharedObj> read(
00049 SO<DataResource> resource,
00050 const ID& targetType = SharedObj::ClassNameVRS(),
00051 bool throwExceptions = false
00052 );
00060
00061
00062 static void setAssociatedResources(
00063 SO<SharedObj> master,
00064 const std::vector<std::string>& resources = std::vector<std::string>()
00065 );
00066
00069 static std::vector<std::string> getAssociatedResources(
00070 SO<SharedObj> master
00071 );
00072
00073 static std::string supportedFileExtensions(
00074 const ID& targetType,
00075 const std::string& prefix = "*.",
00076 const std::string& separator = " ",
00077 const std::string& postfix = ""
00078 );
00079 static std::string supportedFileExtensions(
00080 const std::vector<ID>& targetTypes,
00081 const std::string& prefix = "*.",
00082 const std::string& separator = " ",
00083 const std::string& postfix = ""
00084 );
00091 static std::string supportedFiles(
00092 const ID& targetType,
00093 bool addFormatName = true,
00094 bool addParenthesis = true,
00095 const std::string& formatSeparator = "\n",
00096 const std::string& extPrefix = "*.",
00097 const std::string& extSeparator = " ",
00098 const std::string& extSuffix = ""
00099 );
00100 static std::string supportedFiles(
00101 const std::vector<ID>& targetTypes,
00102 bool addFormatName = true,
00103 bool addParenthesis = true,
00104 const std::string& formatSeparator = "\n",
00105 const std::string& extPrefix = "*.",
00106 const std::string& extSeparator = " ",
00107 const std::string& extSuffix = ""
00108 );
00114 VRS_TYPEINFO(ObjectLoader, SharedObj);
00115 };
00116
00117 #define VRS_LOAD_OBJECT_THROW(TARGET_TYPE, FILE_NAME) \
00118 VRS_Cast(TARGET_TYPE, ::VRS::ObjectLoader::readFile((FILE_NAME), TARGET_TYPE::ClassNameVRS(), true))
00119
00120 #define VRS_LOAD_OBJECT(TARGET_TYPE, FILE_NAME) \
00121 VRS_Cast(TARGET_TYPE, ::VRS::ObjectLoader::readFile((FILE_NAME), TARGET_TYPE::ClassNameVRS(), false))
00122
00123 #define VRS_LoadObject(TARGET_TYPE, FILE_NAME) \
00124 VRS_LOAD_OBJECT(TARGET_TYPE, FILE_NAME)
00125
00126 #define VRS_GuardedLoadObject(TARGET_TYPE, FILE_NAME) \
00127 VRS_GuardedCast(TARGET_TYPE, ::VRS::ObjectLoader::readFile((FILE_NAME), TARGET_TYPE::ClassNameVRS()))
00128
00129 #define VRS_REGISTER_READER(READER) \
00130 namespace { \
00131 bool VRS_ANONYMOUS_IDENTIFIER(registration) = ::VRS::ObjectLoader::install(new READER); \
00132 }
00133
00134 }
00135
00136 #endif // VRS_IO_OBJECTLOADER_H