inline void validate() throw (CGException) {
        /**
         * Check the version
         */
        unsigned long (*versionFunc)();
        versionFunc = reinterpret_cast<decltype(versionFunc)> (loadFunction(ModelLibraryCSourceGen<Base>::FUNCTION_VERSION));

        _version = (*versionFunc)();
        if (ModelLibraryCSourceGen<Base>::API_VERSION != _version)
            throw CGException("The API version of the dynamic library (", _version,
                              ") is incompatible with the current version (",
                              ModelLibraryCSourceGen<Base>::API_VERSION, ")");

        /**
         * Load the list of models
         */
        void (*modelsFunc)(char const *const**, int*);
        modelsFunc = reinterpret_cast<decltype(modelsFunc)> (loadFunction(ModelLibraryCSourceGen<Base>::FUNCTION_MODELS));

        char const*const* model_names = nullptr;
        int model_count;
        (*modelsFunc)(&model_names, &model_count);

        for (int i = 0; i < model_count; i++) {
            _modelNames.insert(model_names[i]);
        }
    }
Пример #2
0
	BezierCurve::BezierCurve(const Coordinates& coords) {
		if (coords.size() < 4 || (coords.size() - 4) % 3 != 0) {
			throw CGException("A bezier curve must be defined with 4, 7, 10, 13, 16, ... coordinates");
		}

		addCoordinate(coords);
		regeneratePath(0.1);
	}
Пример #3
0
	SplineCurve::SplineCurve(const Coordinates& coords) {
		if (coords.size() < 4) {
			throw CGException("A spline curve must have at least 4 coordinates");
		}

		addCoordinate(coords);
		regeneratePath(0.1);
	}
    virtual void* loadFunction(const std::string& functionName, bool required = true) throw (CGException) override {
        void* functor = dlsym(_dynLibHandle, functionName.c_str());

        if (required) {
            char *err = dlerror();
            if (err != nullptr)
                throw CGException("Failed to load function '", functionName, "': ", err);
        }

        return functor;
    }
Пример #5
0
    const std::set<std::string>& createBitCode(ClangCompiler<Base>& clang,
                                               const std::string& version) {
        // backup output format so that it can be restored
        OStreamConfigRestore coutb(std::cout);

        if (clang.getVersion() != version) {
            auto expected = ClangCompiler<Base>::parseVersion(version);
            auto execVersion = ClangCompiler<Base>::parseVersion(clang.getVersion());
            bool error = expected.size() > execVersion.size();
            if (!error) {
                for (size_t i = 0; i < expected.size(); ++i) {
                    if (expected[i] != execVersion[i]) {
                        error = true;
                        break;
                    }
                }
            }
            if (error) {
                throw CGException("Expected a clang with version '", version, "' but found version '", clang.getVersion(), "'");
            }
        }

        const std::map<std::string, ModelCSourceGen<Base>*>& models = this->modelLibraryHelper_->getModels();
        try {
            /**
             * generate bit code
             */
            for (const auto& p : models) {
                const std::map<std::string, std::string>& modelSources = this->getSources(*p.second);

                this->modelLibraryHelper_->startingJob("", JobTimer::COMPILING_FOR_MODEL);
                clang.generateLLVMBitCode(modelSources, this->modelLibraryHelper_);
                this->modelLibraryHelper_->finishedJob();
            }

            const std::map<std::string, std::string>& sources = this->getLibrarySources();
            clang.generateLLVMBitCode(sources, this->modelLibraryHelper_);

            const std::map<std::string, std::string>& customSource = this->modelLibraryHelper_->getCustomSources();
            clang.generateLLVMBitCode(customSource, this->modelLibraryHelper_);
        } catch (...) {
            clang.cleanup();
            throw;
        }

        return clang.getBitCodeFiles();
    }