text:
//
//  main.cpp
//  opencl-language-server-tests
//
//  Created by Ilya Shoshin (Galarius) on 7/16/21.
//

#include <catch2/catch.hpp>

#include "jsonrpc.hpp"
#define __glogger_implementation__    // define this only once
#include <glogger.hpp>
#include "diagnostics.hpp"
#include <boost/json/src.hpp>

using namespace vscode::opencl;
using namespace boost;

namespace {

std::string BuildRequest(const std::string& content)
{
    std::string request;
    request.append("Content-Length: " + std::to_string(content.size()) + "\r\n");
    request.append("Content-Type: application/vscode-jsonrpc;charset=utf-8\r\n");
    request.append("\r\n");
    request.append(content);
    return request;
}

std::string BuildRequest(const json::object& obj)
{
    return BuildRequest(json::serialize(json::value_from(obj)));
}

void Send(const std::string& request, JsonRPC& jrpc)
{
    for(auto c: request)
        jrpc.Consume(c);
}

std::string ParseResponse(std::string str)
{
    std::string delimiter = "\r\n";
    size_t pos = 0;
    while ((pos = str.find(delimiter)) != std::string::npos) {
        str.erase(0, pos + delimiter.length());
    }
    return str;
}

void EnableTracing()
{
     GLogger::instance().SetOutputMode(GLogger::Output::Console);
     GLogger::instance().SetMinLevel(GLogger::Output::Console, GLogger::Level::Trace);
}

}

TEST_CASE( "JSON-RPC TESTS", "<->" )
{
    // EnableTracing();

    SECTION( "Invalid request handling" ) {
        const std::string message = BuildRequest(R"!({"jsonrpc: 2.0", "id":0, [method]: "initialize"})!");
        JsonRPC jrpc;
        jrpc.RegisterOutputCallback([](const std::string& message) {
            auto response = boost::json::parse(ParseResponse(message)).as_object();
            const auto code = response["error"].as_object()["code"].as_int64();
            REQUIRE(code == static_cast<int64_t>(JsonRPC::ErrorCode::ParseError));
        });
        Send(message, jrpc);
    }

    SECTION( "Out of order request" ) {
        const std::string message = BuildRequest(json::object(
            {
                {"jsonrpc", "2.0"},
                {"id", 0},
                {"method", "textDocument/didOpen"},
                {"params", {}}
            }
        ));
        JsonRPC jrpc;
        jrpc.RegisterOutputCallback([](const std::string& message) {
            auto response = boost::json::parse(ParseResponse(message)).as_object();
            const auto code = response["error"].as_object()["code"].as_int64();
            REQUIRE(code == static_cast<int64_t>(JsonRPC::ErrorCode::NotInitialized));
        });
        Send(message, jrpc);
    }

    const std::string initRequest = BuildRequest(json::object(
        {
            {"jsonrpc", "2.0"},
            {"id", 0},
            {"method", "initialize"},
            {"params", {
                {"processId", 60650},
                {"trace", "off"}
            }}
        }
    ));

    SECTION( "Method/initialize" ) {
        JsonRPC jrpc;
        jrpc.RegisterOutputCallback([](const std::string&) {});
        jrpc.RegisterMethodCallback("initialize", [](const boost::json::object& request) {
           const auto& processId = request.at("params").as_object()
                                          .at("processId").as_int64();
           REQUIRE(processId == 60650);
        });
        Send(initRequest, jrpc);
    }

    const auto InitializeJsonRPC = [&initRequest](JsonRPC& jrpc) {
        jrpc.RegisterOutputCallback([](const std::string&) {});

        jrpc.RegisterMethodCallback("initialize", [](const boost::json::object& request) {});
        Send(initRequest, jrpc);
        jrpc.Reset();
    };

    SECTION( "Respond to unsupported method" ) {
        JsonRPC jrpc;
        InitializeJsonRPC(jrpc);
        // send unsupported request
        const std::string request = BuildRequest(json::object(
            {
                {"jsonrpc", "2.0"},
                {"id", 0},
                {"method", "textDocument/didOpen"},
                {"params", {}}
            }
        ));
        jrpc.RegisterOutputCallback([](const std::string& message) {
            auto response = boost::json::parse(ParseResponse(message)).as_object();
            const auto code = response["error"].as_object()["code"].as_int64();
            REQUIRE(code == static_cast<int64_t>(JsonRPC::ErrorCode::MethodNotFound));
        });
        Send(request, jrpc);
    }
}

max_stars_repo_name: williamboman/opencl-language-server

max_issues_repo_name: williamboman/opencl-language-server

max_forks_repo_name: williamboman/opencl-language-server


text:
//
// Created by erik on 1/19/18.
//

#include "observers/observer.hpp"
#include <boost/test/unit_test.hpp>
#include "test_helpers.hpp"

// additional tests:
//	check master observer
//  check observer integration with tracer

BOOST_AUTO_TEST_SUITE(observer_test)

    class TestObserver : public Observer
    {
    public:
        explicit TestObserver(const std::string& file_name) : Observer(file_name) {}
        bool watch(const State&, double) override { return false; }
        void startTrajectory(const InitialCondition&, std::size_t) override {}
        void save( std::ostream& ) override { };
        std::shared_ptr<Observer> makeThreadCopy() override { return nullptr; };
    };

    /*
     * The only actual behaviour that is defined in `Observer` is the
     * caching of the desired save file name, so that is what we test
     * here.
     */
    BOOST_AUTO_TEST_CASE(observer_base_class)
    {
        TestObserver test("file_name");
        BOOST_CHECK_EQUAL(test.filename(), "file_name");

        test.setFileName("other_file");
        BOOST_CHECK_EQUAL(test.filename(), "other_file");
    }

    // -----------------------------------------------------------------------------------------------------------------

    class TestThreadLocalObserver : public ThreadLocalObserver
    {
    public:
        explicit TestThreadLocalObserver(const std::string& file_name) : ThreadLocalObserver(file_name) {}
        bool watch(const State&, double) override { return false; }
        void startTrajectory(const InitialCondition&, std::size_t) override {}
        void save( std::ostream& ) override { };

        int combined = 0;
    private:
        std::shared_ptr<ThreadLocalObserver> clone() const override {
            return std::make_shared<TestThreadLocalObserver>(filename());
        }

        void combine( ThreadLocalObserver& ) override { ++combined; }
    };

    /*
     * The ThreadLocalObserver observer adds a registration for a root observer, and reduction operations.
     * A freshly created observer is neither root nor slave.
     */
    BOOST_AUTO_TEST_CASE(thread_local_observer_ctor_dtor) {
        auto test = std::make_shared<TestThreadLocalObserver>("file_name");
        BOOST_CHECK_EQUAL(test->filename(), "file_name");
        // this is fine, test has not been assigned to another root observer, so we can delete it without error.

        BOOST_CHECK(!test->is_slave());
        BOOST_CHECK(!test->is_root());

        // unfortunately, we cannot simply test the error checking in the destructor of
        // ThreadLocalObserver, as that would immediately go to terminate and kill the test.
    }

    /*
     * When we make a new thread copy of a ThreadLocalObserver, this new observer is a slave observer,
     * and the old observer becomes a root observer. We can then perform a reduction to merge the two
     * observers, which detaches the new observer from its old root, so a second reduce will not change
     * anything.
     *
     * Unfortunately I don't know how we could test the correct use of mutexes to ensure thread safety.
     */
    BOOST_AUTO_TEST_CASE(thread_local_observer_thread_copy_and_reduce) {
        auto test = std::make_shared<TestThreadLocalObserver>("file_name");
        auto copy = std::dynamic_pointer_cast<ThreadLocalObserver>(test->makeThreadCopy());

        BOOST_CHECK(!test->is_slave());
        BOOST_CHECK(test->is_root());
        BOOST_CHECK(copy->is_slave());
        BOOST_CHECK(!copy->is_root());

        copy->reduce();
        BOOST_CHECK(!copy->is_slave());
        BOOST_CHECK_EQUAL(test->combined, 1);

        // check that reduce only works once.
        copy->reduce();
        BOOST_CHECK_EQUAL(test->combined, 1);
    }

    // -----------------------------------------------------------------------------------------------------------------

    class TestThreadSharedObserver : public ThreadSharedObserver
    {
    public:
        explicit TestThreadSharedObserver(const std::string& file_name) : ThreadSharedObserver(file_name) {}
        bool watch(const State&, double) override { return false; }
        void startTrajectory(const InitialCondition&, std::size_t) override {}
        void save( std::ostream& ) override { };
    };

    /*
     * Check that file name is correctly propagated.
     */
    BOOST_AUTO_TEST_CASE(thread_shared_observer_ctor) {
        TestThreadSharedObserver test("file_name");
        BOOST_CHECK_EQUAL(test.filename(), "file_name");
    }

    /*
     * Check that thread copy always refers to the same element.
     */
    BOOST_AUTO_TEST_CASE(thread_shared_observer_copy) {
        auto test = std::make_shared<TestThreadSharedObserver>("file_name");
        auto copy = std::dynamic_pointer_cast<TestThreadSharedObserver>(test->makeThreadCopy());

        // refer to the same object
        BOOST_CHECK(test.get() == copy.get());
        auto m1 = test->getLock().mutex();
        auto m2 = copy->getLock().mutex();
        BOOST_CHECK(m1 == m2);
    }

BOOST_AUTO_TEST_SUITE_END()

ext: cpp


text:
#ifndef CONTRACTOR_TERMS_TENSOR_HPP_
#define CONTRACTOR_TERMS_TENSOR_HPP_

#include "terms/Index.hpp"
#include "terms/IndexSubstitution.hpp"
#include "terms/PermutationGroup.hpp"
#include "utils/IterableView.hpp"

#include <boost/multiprecision/cpp_int.hpp>

#include <limits.h>
#include <ostream>
#include <string>
#include <string_view>
#include <unordered_map>
#include <utility>
#include <vector>

class IndexSpace;

namespace Contractor::Utils {
class IndexSpaceResolver;
};

namespace Contractor::Terms {

class ContractionResult;
class IndexSubstitution;

/**
 * A class representing an element formally holding a value. An element may be attached to
 * (creator/annihilator) indices that are required in order to formally extract a concrete value from
 * this element.
 * An example of a Tensor is a matrix element (e.g. <i | h | j>) but this class is meant to also
 * represent things like amplitudes (t^{ij}_{ab}). Thus the more general name.
 */
class Tensor {
public:
	/**
	 * Type that is used for storing the list of attached indices
	 */
	using index_list_t = std::vector< Index >;

	struct has_same_name {
		bool operator()(const Tensor &left, const Tensor &right) const { return left.getName() == right.getName(); }
	};

	struct tensor_name_hash {
		std::size_t operator()(const Tensor &tensor) const { return std::hash< std::string_view >{}(tensor.getName()); }
	};

	struct is_same_tensor_element {
		bool operator()(const Tensor &left, const Tensor &right) const { return left.refersToSameElement(right); }
	};

	struct tensor_element_hash {
		std::size_t operator()(const Tensor &tensor) const {
			std::size_t hash = 0;
			for (std::size_t i = 0; i < tensor.getIndices().size(); ++i) {
				// Include the position of the index in order to ensure that a different index sequence will result
				// in a different hash value. In order for symmetry-equivalent tensors to arrive at the same hash,
				// we use the "canonical" index sequence for this Tensor
				const Index &currentIndex = tensor.getSymmetry().getCanonicalRepresentation()[i];
				// We only care about an Index's space and spin as the explicit name is not important for the tensor
				// element
				hash += (std::hash< IndexSpace >{}(currentIndex.getSpace()) << 0)
						^ (std::hash< Index::Spin >{}(currentIndex.getSpin()) << 1) ^ std::hash< std::size_t >{}(i);
			}

			hash ^= std::hash< std::string_view >{}(tensor.getName()) << 1;

			return hash;
		}
	};

	/**
	 * Transfers the symmetry of the given source Tensor to the given destination. Note that in order for
	 * this to work, both Tensors have to refer to the same element.
	 * The symmetry transfer is performed via the indices of the involved Index objects.
	 *
	 * If destination already has any kind of symmetry, it will be overwritten by this function.
	 *
	 * @param source The Tensor whose symmetry is to be mimicked
	 * @param destination The Tensor to apply the symmetry to
	 */
	static void transferSymmetry(const Tensor &source, Tensor &destination);

	explicit Tensor(const std::string_view name, const index_list_t &indices, const PermutationGroup &symmetry = {});
	explicit Tensor(const std::string_view name = "", index_list_t &&indices = {}, PermutationGroup &&symmetry = {});

	Tensor(const Tensor &other) = default;
	Tensor(Tensor &&other)      = default;
	Tensor &operator=(const Tensor &other) = default;
	Tensor &operator=(Tensor &&other) = default;

	friend bool operator==(const Tensor &lhs, const Tensor &rhs);
	friend bool operator!=(const Tensor &lhs, const Tensor &rhs);
	friend bool operator<(const Tensor &lhs, const Tensor &rhs);

	friend std::ostream &operator<<(std::ostream &out, const Tensor &element);

	/**
	 * @returns The list of indices of this Tensor
	 */
	const index_list_t &getIndices() const;
	/**
	 * @returns The list of indices of this Tensor
	 */
	index_list_t &getIndices();

	/**
	 * @returns This Tensor's name
	 */
	const std::string_view getName() const;

	void setName(const std::string_view &name);

	const PermutationGroup &getSymmetry() const;

	PermutationGroup &accessSymmetry();

	void setSymmetry(const PermutationGroup &symmetry);

	/**
	 * @returns The total spin S property of this Tensor.
	 * If this is the highest possible value representable with an int, then this means
	 * that this property is unspecified.
	 */
	int getS() const;
	/**
	 * Sets the total spin S property of this Tensor
	 *
	 * @param S The new spin property
	 */
	void setS(int S);
	/**
	 * @returns Whether this Tensor has a defined spin property
	 */
	bool hasS() const;

	/**
	 * @returns The Delta S_z property (change in the M_s quantum number) of this Tensor. The returned number
	 * is twice the actual M_s QN in order to also make half-integer values representable as integers
	 */
	int getDoubleMs() const;
	/**
	 * Sets the Delta S_z property (change in the M_s quantum number) of this Tensor
	 *
	 * @param Ms The new property to use. This is to be twice the actual M_s QN in order to
	 * make half-integer values be representable as ints as well
	 */
	void setDoubleMs(int doubleMs);

	/**
	 * @returns Whether this Tensor is fully anti-symmetrized. That means that pairwise exchange
	 * of creator or annihilator indices leads only to a sign-change.
	 */
	bool isAntisymmetrized() const;

	/**
	 * @returns Whether this Tensor is partially anti-symmetrized. That means that at least the creator
	 * or the annihilator indices are antisymmetrized (pairwise exchange leads only to sign-change).
	 */
	bool isPartiallyAntisymmetrized() const;

	/**
	 * @returns Whether this Tensor shows full column symmetry (exchanging the nth and the (n+1)th creator and
	 * at the same time exchanging the annihilators at the same positions yields the exact same value
	 * (without sign-change) for all n).
	 */
	bool hasColumnSymmetry() const;

	/**
	 * @returns Whether this Tensor shows partial column symmetry (exchanging the nth and the (n+1)th creator and
	 * at the same time exchanging the annihilators at the same positions yields the exact same value
	 * (without sign-change) for at least one n).
	 */
	bool hasPartialColumnSymmetry() const;

	/**
	 * @param other The Tensor to compare to
	 * @param accountForSymmetry Whether symmetry of the involved Tensors shall be taken
	 * into account.
	 * @returns Whether both Tensors are actually referring to the same element. This differs
	 * from equality as the actual index IDs are not important for this, only the relative
	 * order and the index space and type. Note however that duplicate indices in either Tensor
	 * have to have a corresponding counterpart in the other one.
	 */
	bool refersToSameElement(const Tensor &other, bool accountForSymmetry = true) const;

	/**
	 * @param indices The index list to check
	 * @param Whether to take this Tensor's symmetry into account
	 * @returns Whether the given index sequence is equivalent to the one of this Tensor
	 */
	bool refersToSameIndexSequence(const Tensor::index_list_t &indices, bool accountForSymmetry = true) const;

	/**
	 * This gets the index mapping from this Tensor to another one. Note that both Tensors
	 * must refer to the same element.
	 *
	 * @param other The Tensor to compare to
	 * @returns An IndexSubstitution that describes the mapping of indices. When applying the
	 * substitution to this Tensor, it will have the same indices as the given one.
	 */
	IndexSubstitution getIndexMapping(const Tensor &other) const;

	/**
	 * Contracts this Tensor with the given one
	 *
	 * @param other The Tensor to contract with
	 * @param resolver The IndexSpaceResolver providing access to the underlaying IndexSpaceMeta
	 * objects (required to calculate the contraction's cost)
	 * @returns A ContractionResult object representing the result of this contraction
	 */
	ContractionResult contract(const Tensor &other, const Utils::IndexSpaceResolver &resolver) const;

	/**
	 * Brings the indices of this Tensor into "canonical" order. That means the indices are sorted
	 * in such a way that creator indices come before annihilator ones which come before other indices.
	 * During this procedure the relative order within each index group is not changed.
	 */
	void sortIndices();

	/**
	 * @returns Whether this Tensor is using its "canonical" index represenation (considering
	 * its symmetry)
	 */
	bool hasCanonicalIndexSequence() const;

	/**
	 * Brings the indices in this Tensor into their "canonical" sequence (based on this
	 * Tensor's index symmetry)
	 *
	 * @returns The factor that is associated with this transformation
	 */
	int canonicalizeIndices();

protected:
	index_list_t m_indices;
	std::string m_name;
	PermutationGroup m_symmetry;
	int m_S        = std::numeric_limits< int >::max();
	int m_doubleMs = 0;
};

/**
 * Struct holding the result of a contraction
 */
struct ContractionResult {
#ifdef NDEBUG
	using cost_t = boost::multiprecision::uint512_t;
#else
	// The checked version does perform (overflow) checks and throws exceptions
	// if there is something odd going on with this number (e.g. overflows).
	using cost_t = boost::multiprecision::checked_uint512_t;
#endif

	/**
	 * The Tensor representing the contracted result
	 */
	Tensor resultTensor;
	/**
	 * The cost of the contraction. The cost equals the amount of iterations that
	 * are needed to contract all common indices (with all their possible values).
	 *
	 * A cost of 0  means that no (real) contraction was possible.
	 */
	cost_t cost;
	/**
	 * A map containing the exponents of the formal scaling of this contraction
	 * in terms of the different index spaces.
	 */
	std::unordered_map< IndexSpace, unsigned int > spaceExponents;
};

}; // namespace Contractor::Terms

// Provide template specialization of std::hash for the Tensor class
namespace std {
template<> struct hash< Contractor::Terms::Tensor > {
	std::size_t operator()(const Contractor::Terms::Tensor &tensor) const {
		std::size_t hash = 0;
		for (std::size_t i = 0; i < tensor.getIndices().size(); ++i) {
			// Include the position of the index in order to ensure that a different index sequence will result
			// in a different hash value. In order for symmetry-equivalent tensors to arrive at the same hash,
			// we use the "canonical" index sequence for this Tensor
			hash += std::hash< Contractor::Terms::Index >{}(tensor.getSymmetry().getCanonicalRepresentation()[i])
					^ std::hash< std::size_t >{}(i);
		}

		hash ^= std::hash< std::string_view >{}(tensor.getName()) << 1;
		hash ^= std::hash< Contractor::Terms::PermutationGroup >{}(tensor.getSymmetry()) << 2;

		return hash;
	}
};
}; // namespace std

#endif // CONTRACTOR_TERMS_TENSOR_HPP_

ext: hpp

max_stars_repo_name: Krzmbrzl/contractor

max_issues_repo_name: Krzmbrzl/contractor

max_forks_repo_name: Krzmbrzl/contractor


text:
/**
 * @author     : Zhao Chonyyao (cyzhao@zju.edu.cn)
 * @date       : 2021-04-30
 * @description: simple mass spring problem
 * @version    : 1.0
 */
#include <memory>

#include <boost/property_tree/ptree.hpp>

#include "Common/error.h"

// TODO: possible bad idea of having dependence to model in problem module
#include "Model/fem/elas_energy.h"
#include "Model/fem/mass_matrix.h"
#include "Model/mass_spring/mass_spring_obj.h"
#include "Model/mass_spring/para.h"

#include "Problem/energy/basic_energy.h"
#include "Io/io.h"
#include "Geometry/extract_surface.imp"

#include "mass_spring_problem.h"

namespace PhysIKA {
using namespace std;
using namespace Eigen;

template <typename T>
using MAT = Eigen::Matrix<T, -1, -1>;
template <typename T>
using VEC = Eigen::Matrix<T, -1, 1>;

template <typename T>
ms_problem_builder<T>::ms_problem_builder(const T* x, const boost::property_tree::ptree& para_tree)
    : pt_(para_tree)
{
    auto blender            = para_tree.get_child("blender");
    auto simulation_para    = para_tree.get_child("simulation_para");
    auto common             = para_tree.get_child("common");
    para::dt                = common.get<double>("time_step", 0.01);
    para::line_search       = simulation_para.get<int>("line_search", true);  // todo
    para::density           = common.get<double>("density", 10);
    para::frame             = common.get<int>("frame", 100);
    para::newton_fastMS     = simulation_para.get<string>("newton_fastMS");
    para::stiffness         = simulation_para.get<double>("stiffness", 8000);
    para::gravity           = common.get<double>("gravity", 9.8);
    para::object_name       = blender.get<string>("surf");
    para::out_dir_simulator = common.get<string>("out_dir_simulator");
    para::simulation_type   = simulation_para.get<string>("simulation", "static");
    para::weight_line_search =
        simulation_para.get<double>("weight_line_search", 1e-5);
    para::input_object   = common.get<string>("input_object");
    para::force_function = simulation_para.get<string>("force_function");
    para::intensity      = simulation_para.get<double>("intensity");
    para::coll_z         = simulation_para.get<bool>("coll_z", false);
    //TODO: need to check exception

    const string      filename = para::input_object;
    Matrix<T, -1, -1> nods;
    MatrixXi          cells;
    IF_ERR(exit, mesh_read_from_vtk<T, 4>(filename.c_str(), nods, cells));

    const size_t num_nods = nods.cols();
    if (x != nullptr)
        nods = Map<const MAT<T>>(x, nods.rows(), nods.cols());

    REST_  = nods;
    cells_ = cells;

    //read fixed points
    vector<size_t> cons(0);
    if (para_tree.find("input_constraint") != para_tree.not_found())
    {
        const string cons_file_path = common.get<string>("input_constraint");
        /* IF_ERR(exit, read_fixed_verts_from_csv(cons_file_path.c_str(), cons));*/
    }
    cout << "constrint " << cons.size() << " points" << endl;

    //calc mass vector
    Matrix<T, -1, 1> mass_vec(num_nods);
    calc_mass_vector<T>(nods, cells, para::density, mass_vec);
    // mass_calculator<T, 3, 4, 1, 1, basis_func, quadrature>(nods, cells, para::density, mass_vec);

    cout << "build energy" << endl;
    int ELAS = 0;
    int GRAV = 1;
    int KIN  = 2;
    int POS  = 3;
    if (pt_.get<string>("solver_type") == "explicit")
        POS = 2;

    ebf_.resize(POS + 1);
    ebf_[ELAS] = make_shared<MassSpringObj<T>>(para::input_object.c_str(), para::stiffness);
    char axis  = common.get<char>("grav_axis", 'y') | 0x20;

    ebf_[GRAV] = make_shared<gravity_energy<T, 3>>(num_nods, 1, para::gravity, mass_vec, axis);
    kinetic_   = make_shared<momentum<T, 3>>(nods.data(), num_nods, mass_vec, para::dt);

    if (pt_.get<string>("solver_type") == "implicit")
        ebf_[KIN] = kinetic_;
    ebf_[POS] = make_shared<position_constraint<T, 3>>(nods.data(), num_nods, simulation_para.get<double>("w_pos", 1e6), cons);

    //set constraint
    enum constraint_type
    {
        COLL
    };
    cbf_.resize(COLL + 1);
    collider_  = nullptr;
    cbf_[COLL] = collider_;

    if (pt_.get<string>("solver_type") == "explicit")
    {
        Map<Matrix<T, -1, 1>> position(REST_.data(), REST_.size());
        semi_implicit_ = make_shared<semi_implicit<T>>(para::dt, mass_vec, position);
    }
}

template <typename T>
std::shared_ptr<Problem<T, 3>> ms_problem_builder<T>::build_problem() const
{
    cout << "assemble energy" << endl;
    shared_ptr<Functional<T, 3>> energy;
    try
    {
        energy = build_energy_t<T, 3>(ebf_);
    }
    catch (std::exception& e)
    {
        cerr << e.what() << endl;
        exit(EXIT_FAILURE);
    }

    shared_ptr<Constraint<T>> constraint;
    cout << "assemble constraint" << endl;
    bool all_null = true;
    for (auto& c : cbf_)
        if (c != nullptr)
            all_null = false;
    if (all_null)
    {
        constraint = nullptr;
        cout << "WARNGING: No hard constraints." << endl;
    }
    else
    {
        try
        {
            constraint = build_constraint_t<T>(cbf_);
        }
        catch (std::exception& e)
        {
            cerr << e.what() << endl;
            exit(EXIT_FAILURE);
        }
    }

    exit_if(constraint != nullptr && energy->Nx() != constraint->Nx(), "energy and constraint has different dimension.");
    return make_shared<Problem<T, 3>>(energy, constraint);
}

template <typename T>
int ms_problem_builder<T>::update_problem(const T* x, const T* v)
{
    IF_ERR(return, kinetic_->update_location_and_velocity(x, v));
    if (collider_ != nullptr)
        IF_ERR(return, collider_->update(x));
    return 0;
}

template class ms_problem_builder<double>;

template class ms_problem_builder<float>;

}  // namespace PhysIKA

ext: cc


text:
/*=============================================================================
    Copyright (c) 2014      John Fletcher

    Distributed under the Boost Software License, Version 1.0. (See accompanying
    file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
==============================================================================*/

#include <boost/phoenix.hpp>
#include <vector>

#include <boost/detail/lightweight_test.hpp>

namespace phx = boost::phoenix;

int main()
{
    std::vector<int> v = phx::let(phx::local_names::_a = std::vector<int>(3))
    [
       phx::local_names::_a
    ]
    ();
    BOOST_TEST( v.size() == 3);
}


text:
#include <ozo/connection_info.h>
#include <ozo/query_builder.h>
#include <ozo/request.h>
#include <ozo/shortcuts.h>
#include <ozo/failover/role_based.h>

#include <boost/asio/spawn.hpp>
#include <boost/range/adaptor/transformed.hpp>

#include <gtest/gtest.h>
#include <gmock/gmock.h>

namespace {

namespace hana = boost::hana;
namespace failover = ozo::failover;
using op = failover::role_based_options;

using namespace testing;

struct callback_mock {
    template <typename Connection>
    void operator () (ozo::error_code ec, Connection&&) const {
        call(ec);
    }
    template <typename Connection, typename Fallback>
    void operator () (ozo::error_code ec, Connection&&, const Fallback&) const {
        call(ec);
    }
    MOCK_CONST_METHOD1(call, void(ozo::error_code));
};

TEST(role_based, should_return_success_for_invalid_connection_info_retried_with_valid_connection_info) {
    using namespace ozo::literals;
    using namespace hana::literals;

    ozo::io_context io;
    auto conn_info = failover::make_role_based_connection_source(
        failover::master=ozo::connection_info("invalid connection info"),
        failover::replica=ozo::connection_info(OZO_PG_TEST_CONNINFO)
    );
    StrictMock<callback_mock> callback;
    auto roles = failover::role_based(failover::master, failover::replica)
                        .set(op::on_fallback=std::cref(callback));

    InSequence s;
    EXPECT_CALL(callback, call(Eq(ozo::errc::connection_error)));
    EXPECT_CALL(callback, call(ozo::error_code{}));

    std::vector<int> res;
    ozo::request[roles](conn_info[io], "SELECT 1"_SQL + " + 1"_SQL, ozo::into(res),
            std::cref(callback));

    io.run();
}

TEST(role_based, should_not_try_next_role_and_return_error_for_sql_syntax_error) {
    using namespace ozo::literals;
    using namespace hana::literals;

    ozo::io_context io;
    auto conn_info = failover::make_role_based_connection_source(
        failover::master=ozo::connection_info(OZO_PG_TEST_CONNINFO),
        failover::replica=ozo::connection_info(OZO_PG_TEST_CONNINFO)
    );
    StrictMock<callback_mock> callback;
    auto roles = failover::role_based(failover::master, failover::replica)
                        .set(op::on_fallback=std::cref(callback));

    std::vector<int> res;
    ozo::request[roles](conn_info[io], "BAD QUERY"_SQL, ozo::into(res),
            std::cref(callback));
    EXPECT_CALL(callback, call(Eq(ozo::sqlstate::syntax_error_or_access_rule_violation)));
    io.run();
}

TEST(role_based, should_return_error_for_invalid_connection_info_of_all_roles) {
    using namespace ozo::literals;
    using namespace hana::literals;

    ozo::io_context io;
    auto conn_info = failover::make_role_based_connection_source(
        failover::master=ozo::connection_info("invalid connection info"),
        failover::replica=ozo::connection_info("invalid connection info")
    );
    StrictMock<callback_mock> callback;
    auto roles = failover::role_based(failover::master, failover::replica)
                        .set(op::on_fallback=std::cref(callback));

    EXPECT_CALL(callback, call(Eq(ozo::errc::connection_error))).Times(2);

    std::vector<int> res;
    ozo::request[roles](conn_info[io], "SELECT 1"_SQL + " + 1"_SQL, ozo::into(res),
            std::cref(callback));

    io.run();
}

} // namespace

max_stars_repo_name: georgthegreat/ozo

max_issues_repo_name: georgthegreat/ozo

max_forks_repo_name: georgthegreat/ozo


text:
/**
 * FastReport Cloud
 * No description provided (generated by Openapi Generator https://github.com/openapitools/openapi-generator)
 *
 * The version of the OpenAPI document: v1
 *
 * NOTE: This class is auto generated by OpenAPI-Generator 5.1.1.
 * https://openapi-generator.tech
 * Do not edit the class manually.
 */

#include "DataSourcesApi.h"
#include "IHttpBody.h"
#include "JsonBody.h"
#include "MultipartFormData.h"

#include <unordered_set>

#include <boost/algorithm/string/replace.hpp>

namespace fastreport {
namespace cloud {
namespace client {

using namespace fastreport::cloud::models;

DataSourcesApi::DataSourcesApi( std::shared_ptr<const ApiClient> apiClient )
    : m_ApiClient(apiClient)
{
}

DataSourcesApi::~DataSourcesApi()
{
}

pplx::task<std::shared_ptr<DataSourceVM>> DataSourcesApi::dataSourcesCreateDataSource(boost::optional<std::shared_ptr<CreateDataSourceVM>> createDataSourceVM) const
{

    std::shared_ptr<const ApiConfiguration> localVarApiConfiguration( m_ApiClient->getConfiguration() );
    utility::string_t localVarPath = utility::conversions::to_string_t("/api/data/v1/DataSources");

    std::map<utility::string_t, utility::string_t> localVarQueryParams;
    std::map<utility::string_t, utility::string_t> localVarHeaderParams( localVarApiConfiguration->getDefaultHeaders() );
    std::map<utility::string_t, utility::string_t> localVarFormParams;
    std::map<utility::string_t, std::shared_ptr<HttpContent>> localVarFileParams;

    std::unordered_set<utility::string_t> localVarResponseHttpContentTypes;
    localVarResponseHttpContentTypes.insert( utility::conversions::to_string_t("application/json") );

    utility::string_t localVarResponseHttpContentType;

    // use JSON if possible
    if ( localVarResponseHttpContentTypes.size() == 0 )
    {
        localVarResponseHttpContentType = utility::conversions::to_string_t("application/json");
    }
    // JSON
    else if ( localVarResponseHttpContentTypes.find(utility::conversions::to_string_t("application/json")) != localVarResponseHttpContentTypes.end() )
    {
        localVarResponseHttpContentType = utility::conversions::to_string_t("application/json");
    }
    // multipart formdata
    else if( localVarResponseHttpContentTypes.find(utility::conversions::to_string_t("multipart/form-data")) != localVarResponseHttpContentTypes.end() )
    {
        localVarResponseHttpContentType = utility::conversions::to_string_t("multipart/form-data");
    }
    else
    {
        throw ApiException(400, utility::conversions::to_string_t("DataSourcesApi->dataSourcesCreateDataSource does not produce any supported media type"));
    }

    localVarHeaderParams[utility::conversions::to_string_t("Accept")] = localVarResponseHttpContentType;

    std::unordered_set<utility::string_t> localVarConsumeHttpContentTypes;
    localVarConsumeHttpContentTypes.insert( utility::conversions::to_string_t("application/json") );
    localVarConsumeHttpContentTypes.insert( utility::conversions::to_string_t("text/json") );
    localVarConsumeHttpContentTypes.insert( utility::conversions::to_string_t("application/_*+json") );

    std::shared_ptr<IHttpBody> localVarHttpBody;
    utility::string_t localVarRequestHttpContentType;

    // use JSON if possible
    if ( localVarConsumeHttpContentTypes.size() == 0 || localVarConsumeHttpContentTypes.find(utility::conversions::to_string_t("application/json")) != localVarConsumeHttpContentTypes.end() )
    {
        localVarRequestHttpContentType = utility::conversions::to_string_t("application/json");
        web::json::value localVarJson;

        if (createDataSourceVM)
            localVarJson = ModelBase::toJson(*createDataSourceVM);

        localVarHttpBody = std::shared_ptr<IHttpBody>( new JsonBody( localVarJson ) );
    }
    // multipart formdata
    else if( localVarConsumeHttpContentTypes.find(utility::conversions::to_string_t("multipart/form-data")) != localVarConsumeHttpContentTypes.end() )
    {
        localVarRequestHttpContentType = utility::conversions::to_string_t("multipart/form-data");
        std::shared_ptr<MultipartFormData> localVarMultipart(new MultipartFormData);

        if(createDataSourceVM && (*createDataSourceVM).get())
        {
            (*createDataSourceVM)->toMultipart(localVarMultipart, utility::conversions::to_string_t("createDataSourceVM"));
        }

        localVarHttpBody = localVarMultipart;
        localVarRequestHttpContentType += utility::conversions::to_string_t("; boundary=") + localVarMultipart->getBoundary();
    }
    else if (localVarConsumeHttpContentTypes.find(utility::conversions::to_string_t("application/x-www-form-urlencoded")) != localVarConsumeHttpContentTypes.end())
    {
        localVarRequestHttpContentType = utility::conversions::to_string_t("application/x-www-form-urlencoded");
    }
    else
    {
        throw ApiException(415, utility::conversions::to_string_t("DataSourcesApi->dataSourcesCreateDataSource does not consume any supported media type"));
    }

    // authentication (ApiKey) required
    // Basic authentication is added automatically as part of the http_client_config
    // authentication (JWT) required
    // Basic authentication is added automatically as part of the http_client_config

    return m_ApiClient->callApi(localVarPath, utility::conversions::to_string_t("POST"), localVarQueryParams, localVarHttpBody, localVarHeaderParams, localVarFormParams, localVarFileParams, localVarRequestHttpContentType)
    .then([=](web::http::http_response localVarResponse)
    {
        if (m_ApiClient->getResponseHandler())
        {
            m_ApiClient->getResponseHandler()(localVarResponse.status_code(), localVarResponse.headers());
        }

        // 1xx - informational : OK
        // 2xx - successful       : OK
        // 3xx - redirection   : OK
        // 4xx - client error  : not OK
        // 5xx - client error  : not OK
        if (localVarResponse.status_code() >= 400)
        {
            throw ApiException(localVarResponse.status_code()
                , utility::conversions::to_string_t("error calling dataSourcesCreateDataSource: ") + localVarResponse.reason_phrase()
                , std::make_shared<std::stringstream>(localVarResponse.extract_utf8string(true).get()));
        }

        // check response content type
        if(localVarResponse.headers().has(utility::conversions::to_string_t("Content-Type")))
        {
            utility::string_t localVarContentType = localVarResponse.headers()[utility::conversions::to_string_t("Content-Type")];
            if( localVarContentType.find(localVarResponseHttpContentType) == std::string::npos )
            {
                throw ApiException(500
                    , utility::conversions::to_string_t("error calling dataSourcesCreateDataSource: unexpected response type: ") + localVarContentType
                    , std::make_shared<std::stringstream>(localVarResponse.extract_utf8string(true).get()));
            }
        }

        return localVarResponse.extract_string();
    })
    .then([=](utility::string_t localVarResponse)
    {
        std::shared_ptr<DataSourceVM> localVarResult(new DataSourceVM());

        if(localVarResponseHttpContentType == utility::conversions::to_string_t("application/json"))
        {
            web::json::value localVarJson = web::json::value::parse(localVarResponse);

            ModelBase::fromJson(localVarJson, localVarResult);
        }
        // else if(localVarResponseHttpContentType == utility::conversions::to_string_t("multipart/form-data"))
        // {
        // TODO multipart response parsing
        // }
        else
        {
            throw ApiException(500
                , utility::conversions::to_string_t("error calling dataSourcesCreateDataSource: unsupported response type"));
        }

        return localVarResult;
    });
}
pplx::task<void> DataSourcesApi::dataSourcesDeleteDataSource(utility::string_t id) const
{

    std::shared_ptr<const ApiConfiguration> localVarApiConfiguration( m_ApiClient->getConfiguration() );
    utility::string_t localVarPath = utility::conversions::to_string_t("/api/data/v1/DataSources/{id}");
    boost::replace_all(localVarPath, utility::conversions::to_string_t("{") + utility::conversions::to_string_t("id") + utility::conversions::to_string_t("}"), ApiClient::parameterToString(id));

    std::map<utility::string_t, utility::string_t> localVarQueryParams;
    std::map<utility::string_t, utility::string_t> localVarHeaderParams( localVarApiConfiguration->getDefaultHeaders() );
    std::map<utility::string_t, utility::string_t> localVarFormParams;
    std::map<utility::string_t, std::shared_ptr<HttpContent>> localVarFileParams;

    std::unordered_set<utility::string_t> localVarResponseHttpContentTypes;
    localVarResponseHttpContentTypes.insert( utility::conversions::to_string_t("application/json") );

    utility::string_t localVarResponseHttpContentType;

    // use JSON if possible
    if ( localVarResponseHttpContentTypes.size() == 0 )
    {
        localVarResponseHttpContentType = utility::conversions::to_string_t("application/json");
    }
    // JSON
    else if ( localVarResponseHttpContentTypes.find(utility::conversions::to_string_t("application/json")) != localVarResponseHttpContentTypes.end() )
    {
        localVarResponseHttpContentType = utility::conversions::to_string_t("application/json");
    }
    // multipart formdata
    else if( localVarResponseHttpContentTypes.find(utility::conversions::to_string_t("multipart/form-data")) != localVarResponseHttpContentTypes.end() )
    {
        localVarResponseHttpContentType = utility::conversions::to_string_t("multipart/form-data");
    }
    else
    {
        throw ApiException(400, utility::conversions::to_string_t("DataSourcesApi->dataSourcesDeleteDataSource does not produce any supported media type"));
    }

    localVarHeaderParams[utility::conversions::to_string_t("Accept")] = localVarResponseHttpContentType;

    std::unordered_set<utility::string_t> localVarConsumeHttpContentTypes;

    std::shared_ptr<IHttpBody> localVarHttpBody;
    utility::string_t localVarRequestHttpContentType;

    // use JSON if possible
    if ( localVarConsumeHttpContentTypes.size() == 0 || localVarConsumeHttpContentTypes.find(utility::conversions::to_string_t("application/json")) != localVarConsumeHttpContentTypes.end() )
    {
        localVarRequestHttpContentType = utility::conversions::to_string_t("application/json");
    }
    // multipart formdata
    else if( localVarConsumeHttpContentTypes.find(utility::conversions::to_string_t("multipart/form-data")) != localVarConsumeHttpContentTypes.end() )
    {
        localVarRequestHttpContentType = utility::conversions::to_string_t("multipart/form-data");
    }
    else if (localVarConsumeHttpContentTypes.find(utility::conversions::to_string_t("application/x-www-form-urlencoded")) != localVarConsumeHttpContentTypes.end())
    {
        localVarRequestHttpContentType = utility::conversions::to_string_t("application/x-www-form-urlencoded");
    }
    else
    {
        throw ApiException(415, utility::conversions::to_string_t("DataSourcesApi->dataSourcesDeleteDataSource does not consume any supported media type"));
    }

    // authentication (ApiKey) required
    // Basic authentication is added automatically as part of the http_client_config
    // authentication (JWT) required
    // Basic authentication is added automatically as part of the http_client_config

    return m_ApiClient->callApi(localVarPath, utility::conversions::to_string_t("DELETE"), localVarQueryParams, localVarHttpBody, localVarHeaderParams, localVarFormParams, localVarFileParams, localVarRequestHttpContentType)
    .then([=](web::http::http_response localVarResponse)
    {
        if (m_ApiClient->getResponseHandler())
        {
            m_ApiClient->getResponseHandler()(localVarResponse.status_code(), localVarResponse.headers());
        }

        // 1xx - informational : OK
        // 2xx - successful       : OK
        // 3xx - redirection   : OK
        // 4xx - client error  : not OK
        // 5xx - client error  : not OK
        if (localVarResponse.status_code() >= 400)
        {
            throw ApiException(localVarResponse.status_code()
                , utility::conversions::to_string_t("error calling dataSourcesDeleteDataSource: ") + localVarResponse.reason_phrase()
                , std::make_shared<std::stringstream>(localVarResponse.extract_utf8string(true).get()));
        }

        // check response content type
        if(localVarResponse.headers().has(utility::conversions::to_string_t("Content-Type")))
        {
            utility::string_t localVarContentType = localVarResponse.headers()[utility::conversions::to_string_t("Content-Type")];
            if( localVarContentType.find(localVarResponseHttpContentType) == std::string::npos )
            {
                throw ApiException(500
                    , utility::conversions::to_string_t("error calling dataSourcesDeleteDataSource: unexpected response type: ") + localVarContentType
                    , std::make_shared<std::stringstream>(localVarResponse.extract_utf8string(true).get()));
            }
        }

        return localVarResponse.extract_string();
    })
    .then([=](utility::string_t localVarResponse)
    {
        return void();
    });
}
pplx::task<void> DataSourcesApi::dataSourcesFetchData(utility::string_t id) const
{

    std::shared_ptr<const ApiConfiguration> localVarApiConfiguration( m_ApiClient->getConfiguration() );
    utility::string_t localVarPath = utility::conversions::to_string_t("/api/data/v1/DataSources/{id}/fetch");
    boost::replace_all(localVarPath, utility::conversions::to_string_t("{") + utility::conversions::to_string_t("id") + utility::conversions::to_string_t("}"), ApiClient::parameterToString(id));

    std::map<utility::string_t, utility::string_t> localVarQueryParams;
    std::map<utility::string_t, utility::string_t> localVarHeaderParams( localVarApiConfiguration->getDefaultHeaders() );
    std::map<utility::string_t, utility::string_t> localVarFormParams;
    std::map<utility::string_t, std::shared_ptr<HttpContent>> localVarFileParams;

    std::unordered_set<utility::string_t> localVarResponseHttpContentTypes;
    localVarResponseHttpContentTypes.insert( utility::conversions::to_string_t("application/json") );

    utility::string_t localVarResponseHttpContentType;

    // use JSON if possible
    if ( localVarResponseHttpContentTypes.size() == 0 )
    {
        localVarResponseHttpContentType = utility::conversions::to_string_t("application/json");
    }
    // JSON
    else if ( localVarResponseHttpContentTypes.find(utility::conversions::to_string_t("application/json")) != localVarResponseHttpContentTypes.end() )
    {
        localVarResponseHttpContentType = utility::conversions::to_string_t("application/json");
    }
    // multipart formdata
    else if( localVarResponseHttpContentTypes.find(utility::conversions::to_string_t("multipart/form-data")) != localVarResponseHttpContentTypes.end() )
    {
        localVarResponseHttpContentType = utility::conversions::to_string_t("multipart/form-data");
    }
    else
    {
        throw ApiException(400, utility::conversions::to_string_t("DataSourcesApi->dataSourcesFetchData does not produce any supported media type"));
    }

    localVarHeaderParams[utility::conversions::to_string_t("Accept")] = localVarResponseHttpContentType;

    std::unordered_set<utility::string_t> localVarConsumeHttpContentTypes;

    std::shared_ptr<IHttpBody> localVarHttpBody;
    utility::string_t localVarRequestHttpContentType;

    // use JSON if possible
    if ( localVarConsumeHttpContentTypes.size() == 0 || localVarConsumeHttpContentTypes.find(utility::conversions::to_string_t("application/json")) != localVarConsumeHttpContentTypes.end() )
    {
        localVarRequestHttpContentType = utility::conversions::to_string_t("application/json");
    }
    // multipart formdata
    else if( localVarConsumeHttpContentTypes.find(utility::conversions::to_string_t("multipart/form-data")) != localVarConsumeHttpContentTypes.end() )
    {
        localVarRequestHttpContentType = utility::conversions::to_string_t("multipart/form-data");
    }
    else if (localVarConsumeHttpContentTypes.find(utility::conversions::to_string_t("application/x-www-form-urlencoded")) != localVarConsumeHttpContentTypes.end())
    {
        localVarRequestHttpContentType = utility::conversions::to_string_t("application/x-www-form-urlencoded");
    }
    else
    {
        throw ApiException(415, utility::conversions::to_string_t("DataSourcesApi->dataSourcesFetchData does not consume any supported media type"));
    }

    // authentication (ApiKey) required
    // Basic authentication is added automatically as part of the http_client_config
    // authentication (JWT) required
    // Basic authentication is added automatically as part of the http_client_config

    return m_ApiClient->callApi(localVarPath, utility::conversions::to_string_t("GET"), localVarQueryParams, localVarHttpBody, localVarHeaderParams, localVarFormParams, localVarFileParams, localVarRequestHttpContentType)
    .then([=](web::http::http_response localVarResponse)
    {
        if (m_ApiClient->getResponseHandler())
        {
            m_ApiClient->getResponseHandler()(localVarResponse.status_code(), localVarResponse.headers());
        }

        // 1xx - informational : OK
        // 2xx - successful       : OK
        // 3xx - redirection   : OK
        // 4xx - client error  : not OK
        // 5xx - client error  : not OK
        if (localVarResponse.status_code() >= 400)
        {
            throw ApiException(localVarResponse.status_code()
                , utility::conversions::to_string_t("error calling dataSourcesFetchData: ") + localVarResponse.reason_phrase()
                , std::make_shared<std::stringstream>(localVarResponse.extract_utf8string(true).get()));
        }

        // check response content type
        if(localVarResponse.headers().has(utility::conversions::to_string_t("Content-Type")))
        {
            utility::string_t localVarContentType = localVarResponse.headers()[utility::conversions::to_string_t("Content-Type")];
            if( localVarContentType.find(localVarResponseHttpContentType) == std::string::npos )
            {
                throw ApiException(500
                    , utility::conversions::to_string_t("error calling dataSourcesFetchData: unexpected response type: ") + localVarContentType
                    , std::make_shared<std::stringstream>(localVarResponse.extract_utf8string(true).get()));
            }
        }

        return localVarResponse.extract_string();
    })
    .then([=](utility::string_t localVarResponse)
    {
        return void();
    });
}
pplx::task<std::shared_ptr<DataSourcesVM>> DataSourcesApi::dataSourcesGetAvailableDataSources(boost::optional<utility::string_t> subscriptionId, boost::optional<int32_t> skip, boost::optional<int32_t> take, boost::optional<std::shared_ptr<DataSourceSorting>> orderBy, boost::optional<bool> desc) const
{

    std::shared_ptr<const ApiConfiguration> localVarApiConfiguration( m_ApiClient->getConfiguration() );
    utility::string_t localVarPath = utility::conversions::to_string_t("/api/data/v1/DataSources");

    std::map<utility::string_t, utility::string_t> localVarQueryParams;
    std::map<utility::string_t, utility::string_t> localVarHeaderParams( localVarApiConfiguration->getDefaultHeaders() );
    std::map<utility::string_t, utility::string_t> localVarFormParams;
    std::map<utility::string_t, std::shared_ptr<HttpContent>> localVarFileParams;

    std::unordered_set<utility::string_t> localVarResponseHttpContentTypes;
    localVarResponseHttpContentTypes.insert( utility::conversions::to_string_t("application/json") );

    utility::string_t localVarResponseHttpContentType;

    // use JSON if possible
    if ( localVarResponseHttpContentTypes.size() == 0 )
    {
        localVarResponseHttpContentType = utility::conversions::to_string_t("application/json");
    }
    // JSON
    else if ( localVarResponseHttpContentTypes.find(utility::conversions::to_string_t("application/json")) != localVarResponseHttpContentTypes.end() )
    {
        localVarResponseHttpContentType = utility::conversions::to_string_t("application/json");
    }
    // multipart formdata
    else if( localVarResponseHttpContentTypes.find(utility::conversions::to_string_t("multipart/form-data")) != localVarResponseHttpContentTypes.end() )
    {
        localVarResponseHttpContentType = utility::conversions::to_string_t("multipart/form-data");
    }
    else
    {
        throw ApiException(400, utility::conversions::to_string_t("DataSourcesApi->dataSourcesGetAvailableDataSources does not produce any supported media type"));
    }

    localVarHeaderParams[utility::conversions::to_string_t("Accept")] = localVarResponseHttpContentType;

    std::unordered_set<utility::string_t> localVarConsumeHttpContentTypes;

    if (subscriptionId)
    {
        localVarQueryParams[utility::conversions::to_string_t("subscriptionId")] = ApiClient::parameterToString(*subscriptionId);
    }
    if (skip)
    {
        localVarQueryParams[utility::conversions::to_string_t("skip")] = ApiClient::parameterToString(*skip);
    }
    if (take)
    {
        localVarQueryParams[utility::conversions::to_string_t("take")] = ApiClient::parameterToString(*take);
    }
    if (orderBy && *orderBy != nullptr)
    {
        localVarQueryParams[utility::conversions::to_string_t("orderBy")] = ApiClient::parameterToString(*orderBy);
    }
    if (desc)
    {
        localVarQueryParams[utility::conversions::to_string_t("desc")] = ApiClient::parameterToString(*desc);
    }

    std::shared_ptr<IHttpBody> localVarHttpBody;
    utility::string_t localVarRequestHttpContentType;

    // use JSON if possible
    if ( localVarConsumeHttpContentTypes.size() == 0 || localVarConsumeHttpContentTypes.find(utility::conversions::to_string_t("application/json")) != localVarConsumeHttpContentTypes.end() )
    {
        localVarRequestHttpContentType = utility::conversions::to_string_t("application/json");
    }
    // multipart formdata
    else if( localVarConsumeHttpContentTypes.find(utility::conversions::to_string_t("multipart/form-data")) != localVarConsumeHttpContentTypes.end() )
    {
        localVarRequestHttpContentType = utility::conversions::to_string_t("multipart/form-data");
    }
    else if (localVarConsumeHttpContentTypes.find(utility::conversions::to_string_t("application/x-www-form-urlencoded")) != localVarConsumeHttpContentTypes.end())
    {
        localVarRequestHttpContentType = utility::conversions::to_string_t("application/x-www-form-urlencoded");
    }
    else
    {
        throw ApiException(415, utility::conversions::to_string_t("DataSourcesApi->dataSourcesGetAvailableDataSources does not consume any supported media type"));
    }

    // authentication (ApiKey) required
    // Basic authentication is added automatically as part of the http_client_config
    // authentication (JWT) required
    // Basic authentication is added automatically as part of the http_client_config

    return m_ApiClient->callApi(localVarPath, utility::conversions::to_string_t("GET"), localVarQueryParams, localVarHttpBody, localVarHeaderParams, localVarFormParams, localVarFileParams, localVarRequestHttpContentType)
    .then([=](web::http::http_response localVarResponse)
    {
        if (m_ApiClient->getResponseHandler())
        {
            m_ApiClient->getResponseHandler()(localVarResponse.status_code(), localVarResponse.headers());
        }

        // 1xx - informational : OK
        // 2xx - successful       : OK
        // 3xx - redirection   : OK
        // 4xx - client error  : not OK
        // 5xx - client error  : not OK
        if (localVarResponse.status_code() >= 400)
        {
            throw ApiException(localVarResponse.status_code()
                , utility::conversions::to_string_t("error calling dataSourcesGetAvailableDataSources: ") + localVarResponse.reason_phrase()
                , std::make_shared<std::stringstream>(localVarResponse.extract_utf8string(true).get()));
        }

        // check response content type
        if(localVarResponse.headers().has(utility::conversions::to_string_t("Content-Type")))
        {
            utility::string_t localVarContentType = localVarResponse.headers()[utility::conversions::to_string_t("Content-Type")];
            if( localVarContentType.find(localVarResponseHttpContentType) == std::string::npos )
            {
                throw ApiException(500
                    , utility::conversions::to_string_t("error calling dataSourcesGetAvailableDataSources: unexpected response type: ") + localVarContentType
                    , std::make_shared<std::stringstream>(localVarResponse.extract_utf8string(true).get()));
            }
        }

        return localVarResponse.extract_string();
    })
    .then([=](utility::string_t localVarResponse)
    {
        std::shared_ptr<DataSourcesVM> localVarResult(new DataSourcesVM());

        if(localVarResponseHttpContentType == utility::conversions::to_string_t("application/json"))
        {
            web::json::value localVarJson = web::json::value::parse(localVarResponse);

            ModelBase::fromJson(localVarJson, localVarResult);
        }
        // else if(localVarResponseHttpContentType == utility::conversions::to_string_t("multipart/form-data"))
        // {
        // TODO multipart response parsing
        // }
        else
        {
            throw ApiException(500
                , utility::conversions::to_string_t("error calling dataSourcesGetAvailableDataSources: unsupported response type"));
        }

        return localVarResult;
    });
}
pplx::task<std::shared_ptr<DataSourceVM>> DataSourcesApi::dataSourcesGetDataSource(utility::string_t id) const
{

    std::shared_ptr<const ApiConfiguration> localVarApiConfiguration( m_ApiClient->getConfiguration() );
    utility::string_t localVarPath = utility::conversions::to_string_t("/api/data/v1/DataSources/{id}");
    boost::replace_all(localVarPath, utility::conversions::to_string_t("{") + utility::conversions::to_string_t("id") + utility::conversions::to_string_t("}"), ApiClient::parameterToString(id));

    std::map<utility::string_t, utility::string_t> localVarQueryParams;
    std::map<utility::string_t, utility::string_t> localVarHeaderParams( localVarApiConfiguration->getDefaultHeaders() );
    std::map<utility::string_t, utility::string_t> localVarFormParams;
    std::map<utility::string_t, std::shared_ptr<HttpContent>> localVarFileParams;

    std::unordered_set<utility::string_t> localVarResponseHttpContentTypes;
    localVarResponseHttpContentTypes.insert( utility::conversions::to_string_t("application/json") );

    utility::string_t localVarResponseHttpContentType;

    // use JSON if possible
    if ( localVarResponseHttpContentTypes.size() == 0 )
    {
        localVarResponseHttpContentType = utility::conversions::to_string_t("application/json");
    }
    // JSON
    else if ( localVarResponseHttpContentTypes.find(utility::conversions::to_string_t("application/json")) != localVarResponseHttpContentTypes.end() )
    {
        localVarResponseHttpContentType = utility::conversions::to_string_t("application/json");
    }
    // multipart formdata
    else if( localVarResponseHttpContentTypes.find(utility::conversions::to_string_t("multipart/form-data")) != localVarResponseHttpContentTypes.end() )
    {
        localVarResponseHttpContentType = utility::conversions::to_string_t("multipart/form-data");
    }
    else
    {
        throw ApiException(400, utility::conversions::to_string_t("DataSourcesApi->dataSourcesGetDataSource does not produce any supported media type"));
    }

    localVarHeaderParams[utility::conversions::to_string_t("Accept")] = localVarResponseHttpContentType;

    std::unordered_set<utility::string_t> localVarConsumeHttpContentTypes;

    std::shared_ptr<IHttpBody> localVarHttpBody;
    utility::string_t localVarRequestHttpContentType;

    // use JSON if possible
    if ( localVarConsumeHttpContentTypes.size() == 0 || localVarConsumeHttpContentTypes.find(utility::conversions::to_string_t("application/json")) != localVarConsumeHttpContentTypes.end() )
    {
        localVarRequestHttpContentType = utility::conversions::to_string_t("application/json");
    }
    // multipart formdata
    else if( localVarConsumeHttpContentTypes.find(utility::conversions::to_string_t("multipart/form-data")) != localVarConsumeHttpContentTypes.end() )
    {
        localVarRequestHttpContentType = utility::conversions::to_string_t("multipart/form-data");
    }
    else if (localVarConsumeHttpContentTypes.find(utility::conversions::to_string_t("application/x-www-form-urlencoded")) != localVarConsumeHttpContentTypes.end())
    {
        localVarRequestHttpContentType = utility::conversions::to_string_t("application/x-www-form-urlencoded");
    }
    else
    {
        throw ApiException(415, utility::conversions::to_string_t("DataSourcesApi->dataSourcesGetDataSource does not consume any supported media type"));
    }

    // authentication (ApiKey) required
    // Basic authentication is added automatically as part of the http_client_config
    // authentication (JWT) required
    // Basic authentication is added automatically as part of the http_client_config

    return m_ApiClient->callApi(localVarPath, utility::conversions::to_string_t("GET"), localVarQueryParams, localVarHttpBody, localVarHeaderParams, localVarFormParams, localVarFileParams, localVarRequestHttpContentType)
    .then([=](web::http::http_response localVarResponse)
    {
        if (m_ApiClient->getResponseHandler())
        {
            m_ApiClient->getResponseHandler()(localVarResponse.status_code(), localVarResponse.headers());
        }

        // 1xx - informational : OK
        // 2xx - successful       : OK
        // 3xx - redirection   : OK
        // 4xx - client error  : not OK
        // 5xx - client error  : not OK
        if (localVarResponse.status_code() >= 400)
        {
            throw ApiException(localVarResponse.status_code()
                , utility::conversions::to_string_t("error calling dataSourcesGetDataSource: ") + localVarResponse.reason_phrase()
                , std::make_shared<std::stringstream>(localVarResponse.extract_utf8string(true).get()));
        }

        // check response content type
        if(localVarResponse.headers().has(utility::conversions::to_string_t("Content-Type")))
        {
            utility::string_t localVarContentType = localVarResponse.headers()[utility::conversions::to_string_t("Content-Type")];
            if( localVarContentType.find(localVarResponseHttpContentType) == std::string::npos )
            {
                throw ApiException(500
                    , utility::conversions::to_string_t("error calling dataSourcesGetDataSource: unexpected response type: ") + localVarContentType
                    , std::make_shared<std::stringstream>(localVarResponse.extract_utf8string(true).get()));
            }
        }

        return localVarResponse.extract_string();
    })
    .then([=](utility::string_t localVarResponse)
    {
        std::shared_ptr<DataSourceVM> localVarResult(new DataSourceVM());

        if(localVarResponseHttpContentType == utility::conversions::to_string_t("application/json"))
        {
            web::json::value localVarJson = web::json::value::parse(localVarResponse);

            ModelBase::fromJson(localVarJson, localVarResult);
        }
        // else if(localVarResponseHttpContentType == utility::conversions::to_string_t("multipart/form-data"))
        // {
        // TODO multipart response parsing
        // }
        else
        {
            throw ApiException(500
                , utility::conversions::to_string_t("error calling dataSourcesGetDataSource: unsupported response type"));
        }

        return localVarResult;
    });
}
pplx::task<std::shared_ptr<DataSourcePermissionsVM>> DataSourcesApi::dataSourcesGetPermissions(utility::string_t id) const
{

    std::shared_ptr<const ApiConfiguration> localVarApiConfiguration( m_ApiClient->getConfiguration() );
    utility::string_t localVarPath = utility::conversions::to_string_t("/api/data/v1/DataSources/{id}/permissions");
    boost::replace_all(localVarPath, utility::conversions::to_string_t("{") + utility::conversions::to_string_t("id") + utility::conversions::to_string_t("}"), ApiClient::parameterToString(id));

    std::map<utility::string_t, utility::string_t> localVarQueryParams;
    std::map<utility::string_t, utility::string_t> localVarHeaderParams( localVarApiConfiguration->getDefaultHeaders() );
    std::map<utility::string_t, utility::string_t> localVarFormParams;
    std::map<utility::string_t, std::shared_ptr<HttpContent>> localVarFileParams;

    std::unordered_set<utility::string_t> localVarResponseHttpContentTypes;
    localVarResponseHttpContentTypes.insert( utility::conversions::to_string_t("application/json") );

    utility::string_t localVarResponseHttpContentType;

    // use JSON if possible
    if ( localVarResponseHttpContentTypes.size() == 0 )
    {
        localVarResponseHttpContentType = utility::conversions::to_string_t("application/json");
    }
    // JSON
    else if ( localVarResponseHttpContentTypes.find(utility::conversions::to_string_t("application/json")) != localVarResponseHttpContentTypes.end() )
    {
        localVarResponseHttpContentType = utility::conversions::to_string_t("application/json");
    }
    // multipart formdata
    else if( localVarResponseHttpContentTypes.find(utility::conversions::to_string_t("multipart/form-data")) != localVarResponseHttpContentTypes.end() )
    {
        localVarResponseHttpContentType = utility::conversions::to_string_t("multipart/form-data");
    }
    else
    {
        throw ApiException(400, utility::conversions::to_string_t("DataSourcesApi->dataSourcesGetPermissions does not produce any supported media type"));
    }

    localVarHeaderParams[utility::conversions::to_string_t("Accept")] = localVarResponseHttpContentType;

    std::unordered_set<utility::string_t> localVarConsumeHttpContentTypes;

    std::shared_ptr<IHttpBody> localVarHttpBody;
    utility::string_t localVarRequestHttpContentType;

    // use JSON if possible
    if ( localVarConsumeHttpContentTypes.size() == 0 || localVarConsumeHttpContentTypes.find(utility::conversions::to_string_t("application/json")) != localVarConsumeHttpContentTypes.end() )
    {
        localVarRequestHttpContentType = utility::conversions::to_string_t("application/json");
    }
    // multipart formdata
    else if( localVarConsumeHttpContentTypes.find(utility::conversions::to_string_t("multipart/form-data")) != localVarConsumeHttpContentTypes.end() )
    {
        localVarRequestHttpContentType = utility::conversions::to_string_t("multipart/form-data");
    }
    else if (localVarConsumeHttpContentTypes.find(utility::conversions::to_string_t("application/x-www-form-urlencoded")) != localVarConsumeHttpContentTypes.end())
    {
        localVarRequestHttpContentType = utility::conversions::to_string_t("application/x-www-form-urlencoded");
    }
    else
    {
        throw ApiException(415, utility::conversions::to_string_t("DataSourcesApi->dataSourcesGetPermissions does not consume any supported media type"));
    }

    // authentication (ApiKey) required
    // Basic authentication is added automatically as part of the http_client_config
    // authentication (JWT) required
    // Basic authentication is added automatically as part of the http_client_config

    return m_ApiClient->callApi(localVarPath, utility::conversions::to_string_t("GET"), localVarQueryParams, localVarHttpBody, localVarHeaderParams, localVarFormParams, localVarFileParams, localVarRequestHttpContentType)
    .then([=](web::http::http_response localVarResponse)
    {
        if (m_ApiClient->getResponseHandler())
        {
            m_ApiClient->getResponseHandler()(localVarResponse.status_code(), localVarResponse.headers());
        }

        // 1xx - informational : OK
        // 2xx - successful       : OK
        // 3xx - redirection   : OK
        // 4xx - client error  : not OK
        // 5xx - client error  : not OK
        if (localVarResponse.status_code() >= 400)
        {
            throw ApiException(localVarResponse.status_code()
                , utility::conversions::to_string_t("error calling dataSourcesGetPermissions: ") + localVarResponse.reason_phrase()
                , std::make_shared<std::stringstream>(localVarResponse.extract_utf8string(true).get()));
        }

        // check response content type
        if(localVarResponse.headers().has(utility::conversions::to_string_t("Content-Type")))
        {
            utility::string_t localVarContentType = localVarResponse.headers()[utility::conversions::to_string_t("Content-Type")];
            if( localVarContentType.find(localVarResponseHttpContentType) == std::string::npos )
            {
                throw ApiException(500
                    , utility::conversions::to_string_t("error calling dataSourcesGetPermissions: unexpected response type: ") + localVarContentType
                    , std::make_shared<std::stringstream>(localVarResponse.extract_utf8string(true).get()));
            }
        }

        return localVarResponse.extract_string();
    })
    .then([=](utility::string_t localVarResponse)
    {
        std::shared_ptr<DataSourcePermissionsVM> localVarResult(new DataSourcePermissionsVM());

        if(localVarResponseHttpContentType == utility::conversions::to_string_t("application/json"))
        {
            web::json::value localVarJson = web::json::value::parse(localVarResponse);

            ModelBase::fromJson(localVarJson, localVarResult);
        }
        // else if(localVarResponseHttpContentType == utility::conversions::to_string_t("multipart/form-data"))
        // {
        // TODO multipart response parsing
        // }
        else
        {
            throw ApiException(500
                , utility::conversions::to_string_t("error calling dataSourcesGetPermissions: unsupported response type"));
        }

        return localVarResult;
    });
}
pplx::task<std::shared_ptr<DataSourceVM>> DataSourcesApi::dataSourcesRenameDataSource(utility::string_t id, boost::optional<std::shared_ptr<RenameDataSourceVM>> renameDataSourceVM) const
{

    std::shared_ptr<const ApiConfiguration> localVarApiConfiguration( m_ApiClient->getConfiguration() );
    utility::string_t localVarPath = utility::conversions::to_string_t("/api/data/v1/DataSources/{id}/rename");
    boost::replace_all(localVarPath, utility::conversions::to_string_t("{") + utility::conversions::to_string_t("id") + utility::conversions::to_string_t("}"), ApiClient::parameterToString(id));

    std::map<utility::string_t, utility::string_t> localVarQueryParams;
    std::map<utility::string_t, utility::string_t> localVarHeaderParams( localVarApiConfiguration->getDefaultHeaders() );
    std::map<utility::string_t, utility::string_t> localVarFormParams;
    std::map<utility::string_t, std::shared_ptr<HttpContent>> localVarFileParams;

    std::unordered_set<utility::string_t> localVarResponseHttpContentTypes;
    localVarResponseHttpContentTypes.insert( utility::conversions::to_string_t("application/json") );

    utility::string_t localVarResponseHttpContentType;

    // use JSON if possible
    if ( localVarResponseHttpContentTypes.size() == 0 )
    {
        localVarResponseHttpContentType = utility::conversions::to_string_t("application/json");
    }
    // JSON
    else if ( localVarResponseHttpContentTypes.find(utility::conversions::to_string_t("application/json")) != localVarResponseHttpContentTypes.end() )
    {
        localVarResponseHttpContentType = utility::conversions::to_string_t("application/json");
    }
    // multipart formdata
    else if( localVarResponseHttpContentTypes.find(utility::conversions::to_string_t("multipart/form-data")) != localVarResponseHttpContentTypes.end() )
    {
        localVarResponseHttpContentType = utility::conversions::to_string_t("multipart/form-data");
    }
    else
    {
        throw ApiException(400, utility::conversions::to_string_t("DataSourcesApi->dataSourcesRenameDataSource does not produce any supported media type"));
    }

    localVarHeaderParams[utility::conversions::to_string_t("Accept")] = localVarResponseHttpContentType;

    std::unordered_set<utility::string_t> localVarConsumeHttpContentTypes;
    localVarConsumeHttpContentTypes.insert( utility::conversions::to_string_t("application/json") );
    localVarConsumeHttpContentTypes.insert( utility::conversions::to_string_t("text/json") );
    localVarConsumeHttpContentTypes.insert( utility::conversions::to_string_t("application/_*+json") );

    std::shared_ptr<IHttpBody> localVarHttpBody;
    utility::string_t localVarRequestHttpContentType;

    // use JSON if possible
    if ( localVarConsumeHttpContentTypes.size() == 0 || localVarConsumeHttpContentTypes.find(utility::conversions::to_string_t("application/json")) != localVarConsumeHttpContentTypes.end() )
    {
        localVarRequestHttpContentType = utility::conversions::to_string_t("application/json");
        web::json::value localVarJson;

        if (renameDataSourceVM)
            localVarJson = ModelBase::toJson(*renameDataSourceVM);

        localVarHttpBody = std::shared_ptr<IHttpBody>( new JsonBody( localVarJson ) );
    }
    // multipart formdata
    else if( localVarConsumeHttpContentTypes.find(utility::conversions::to_string_t("multipart/form-data")) != localVarConsumeHttpContentTypes.end() )
    {
        localVarRequestHttpContentType = utility::conversions::to_string_t("multipart/form-data");
        std::shared_ptr<MultipartFormData> localVarMultipart(new MultipartFormData);

        if(renameDataSourceVM && (*renameDataSourceVM).get())
        {
            (*renameDataSourceVM)->toMultipart(localVarMultipart, utility::conversions::to_string_t("renameDataSourceVM"));
        }

        localVarHttpBody = localVarMultipart;
        localVarRequestHttpContentType += utility::conversions::to_string_t("; boundary=") + localVarMultipart->getBoundary();
    }
    else if (localVarConsumeHttpContentTypes.find(utility::conversions::to_string_t("application/x-www-form-urlencoded")) != localVarConsumeHttpContentTypes.end())
    {
        localVarRequestHttpContentType = utility::conversions::to_string_t("application/x-www-form-urlencoded");
    }
    else
    {
        throw ApiException(415, utility::conversions::to_string_t("DataSourcesApi->dataSourcesRenameDataSource does not consume any supported media type"));
    }

    // authentication (ApiKey) required
    // Basic authentication is added automatically as part of the http_client_config
    // authentication (JWT) required
    // Basic authentication is added automatically as part of the http_client_config

    return m_ApiClient->callApi(localVarPath, utility::conversions::to_string_t("PUT"), localVarQueryParams, localVarHttpBody, localVarHeaderParams, localVarFormParams, localVarFileParams, localVarRequestHttpContentType)
    .then([=](web::http::http_response localVarResponse)
    {
        if (m_ApiClient->getResponseHandler())
        {
            m_ApiClient->getResponseHandler()(localVarResponse.status_code(), localVarResponse.headers());
        }

        // 1xx - informational : OK
        // 2xx - successful       : OK
        // 3xx - redirection   : OK
        // 4xx - client error  : not OK
        // 5xx - client error  : not OK
        if (localVarResponse.status_code() >= 400)
        {
            throw ApiException(localVarResponse.status_code()
                , utility::conversions::to_string_t("error calling dataSourcesRenameDataSource: ") + localVarResponse.reason_phrase()
                , std::make_shared<std::stringstream>(localVarResponse.extract_utf8string(true).get()));
        }

        // check response content type
        if(localVarResponse.headers().has(utility::conversions::to_string_t("Content-Type")))
        {
            utility::string_t localVarContentType = localVarResponse.headers()[utility::conversions::to_string_t("Content-Type")];
            if( localVarContentType.find(localVarResponseHttpContentType) == std::string::npos )
            {
                throw ApiException(500
                    , utility::conversions::to_string_t("error calling dataSourcesRenameDataSource: unexpected response type: ") + localVarContentType
                    , std::make_shared<std::stringstream>(localVarResponse.extract_utf8string(true).get()));
            }
        }

        return localVarResponse.extract_string();
    })
    .then([=](utility::string_t localVarResponse)
    {
        std::shared_ptr<DataSourceVM> localVarResult(new DataSourceVM());

        if(localVarResponseHttpContentType == utility::conversions::to_string_t("application/json"))
        {
            web::json::value localVarJson = web::json::value::parse(localVarResponse);

            ModelBase::fromJson(localVarJson, localVarResult);
        }
        // else if(localVarResponseHttpContentType == utility::conversions::to_string_t("multipart/form-data"))
        // {
        // TODO multipart response parsing
        // }
        else
        {
            throw ApiException(500
                , utility::conversions::to_string_t("error calling dataSourcesRenameDataSource: unsupported response type"));
        }

        return localVarResult;
    });
}
pplx::task<std::shared_ptr<DataSourceVM>> DataSourcesApi::dataSourcesUpdateConnectionString(utility::string_t id, boost::optional<std::shared_ptr<UpdateDataSourceConnectionStringVM>> updateDataSourceConnectionStringVM) const
{

    std::shared_ptr<const ApiConfiguration> localVarApiConfiguration( m_ApiClient->getConfiguration() );
    utility::string_t localVarPath = utility::conversions::to_string_t("/api/data/v1/DataSources/{id}/ConnectionString");
    boost::replace_all(localVarPath, utility::conversions::to_string_t("{") + utility::conversions::to_string_t("id") + utility::conversions::to_string_t("}"), ApiClient::parameterToString(id));

    std::map<utility::string_t, utility::string_t> localVarQueryParams;
    std::map<utility::string_t, utility::string_t> localVarHeaderParams( localVarApiConfiguration->getDefaultHeaders() );
    std::map<utility::string_t, utility::string_t> localVarFormParams;
    std::map<utility::string_t, std::shared_ptr<HttpContent>> localVarFileParams;

    std::unordered_set<utility::string_t> localVarResponseHttpContentTypes;
    localVarResponseHttpContentTypes.insert( utility::conversions::to_string_t("application/json") );

    utility::string_t localVarResponseHttpContentType;

    // use JSON if possible
    if ( localVarResponseHttpContentTypes.size() == 0 )
    {
        localVarResponseHttpContentType = utility::conversions::to_string_t("application/json");
    }
    // JSON
    else if ( localVarResponseHttpContentTypes.find(utility::conversions::to_string_t("application/json")) != localVarResponseHttpContentTypes.end() )
    {
        localVarResponseHttpContentType = utility::conversions::to_string_t("application/json");
    }
    // multipart formdata
    else if( localVarResponseHttpContentTypes.find(utility::conversions::to_string_t("multipart/form-data")) != localVarResponseHttpContentTypes.end() )
    {
        localVarResponseHttpContentType = utility::conversions::to_string_t("multipart/form-data");
    }
    else
    {
        throw ApiException(400, utility::conversions::to_string_t("DataSourcesApi->dataSourcesUpdateConnectionString does not produce any supported media type"));
    }

    localVarHeaderParams[utility::conversions::to_string_t("Accept")] = localVarResponseHttpContentType;

    std::unordered_set<utility::string_t> localVarConsumeHttpContentTypes;
    localVarConsumeHttpContentTypes.insert( utility::conversions::to_string_t("application/json") );
    localVarConsumeHttpContentTypes.insert( utility::conversions::to_string_t("text/json") );
    localVarConsumeHttpContentTypes.insert( utility::conversions::to_string_t("application/_*+json") );

    std::shared_ptr<IHttpBody> localVarHttpBody;
    utility::string_t localVarRequestHttpContentType;

    // use JSON if possible
    if ( localVarConsumeHttpContentTypes.size() == 0 || localVarConsumeHttpContentTypes.find(utility::conversions::to_string_t("application/json")) != localVarConsumeHttpContentTypes.end() )
    {
        localVarRequestHttpContentType = utility::conversions::to_string_t("application/json");
        web::json::value localVarJson;

        if (updateDataSourceConnectionStringVM)
            localVarJson = ModelBase::toJson(*updateDataSourceConnectionStringVM);

        localVarHttpBody = std::shared_ptr<IHttpBody>( new JsonBody( localVarJson ) );
    }
    // multipart formdata
    else if( localVarConsumeHttpContentTypes.find(utility::conversions::to_string_t("multipart/form-data")) != localVarConsumeHttpContentTypes.end() )
    {
        localVarRequestHttpContentType = utility::conversions::to_string_t("multipart/form-data");
        std::shared_ptr<MultipartFormData> localVarMultipart(new MultipartFormData);

        if(updateDataSourceConnectionStringVM && (*updateDataSourceConnectionStringVM).get())
        {
            (*updateDataSourceConnectionStringVM)->toMultipart(localVarMultipart, utility::conversions::to_string_t("updateDataSourceConnectionStringVM"));
        }

        localVarHttpBody = localVarMultipart;
        localVarRequestHttpContentType += utility::conversions::to_string_t("; boundary=") + localVarMultipart->getBoundary();
    }
    else if (localVarConsumeHttpContentTypes.find(utility::conversions::to_string_t("application/x-www-form-urlencoded")) != localVarConsumeHttpContentTypes.end())
    {
        localVarRequestHttpContentType = utility::conversions::to_string_t("application/x-www-form-urlencoded");
    }
    else
    {
        throw ApiException(415, utility::conversions::to_string_t("DataSourcesApi->dataSourcesUpdateConnectionString does not consume any supported media type"));
    }

    // authentication (ApiKey) required
    // Basic authentication is added automatically as part of the http_client_config
    // authentication (JWT) required
    // Basic authentication is added automatically as part of the http_client_config

    return m_ApiClient->callApi(localVarPath, utility::conversions::to_string_t("PUT"), localVarQueryParams, localVarHttpBody, localVarHeaderParams, localVarFormParams, localVarFileParams, localVarRequestHttpContentType)
    .then([=](web::http::http_response localVarResponse)
    {
        if (m_ApiClient->getResponseHandler())
        {
            m_ApiClient->getResponseHandler()(localVarResponse.status_code(), localVarResponse.headers());
        }

        // 1xx - informational : OK
        // 2xx - successful       : OK
        // 3xx - redirection   : OK
        // 4xx - client error  : not OK
        // 5xx - client error  : not OK
        if (localVarResponse.status_code() >= 400)
        {
            throw ApiException(localVarResponse.status_code()
                , utility::conversions::to_string_t("error calling dataSourcesUpdateConnectionString: ") + localVarResponse.reason_phrase()
                , std::make_shared<std::stringstream>(localVarResponse.extract_utf8string(true).get()));
        }

        // check response content type
        if(localVarResponse.headers().has(utility::conversions::to_string_t("Content-Type")))
        {
            utility::string_t localVarContentType = localVarResponse.headers()[utility::conversions::to_string_t("Content-Type")];
            if( localVarContentType.find(localVarResponseHttpContentType) == std::string::npos )
            {
                throw ApiException(500
                    , utility::conversions::to_string_t("error calling dataSourcesUpdateConnectionString: unexpected response type: ") + localVarContentType
                    , std::make_shared<std::stringstream>(localVarResponse.extract_utf8string(true).get()));
            }
        }

        return localVarResponse.extract_string();
    })
    .then([=](utility::string_t localVarResponse)
    {
        std::shared_ptr<DataSourceVM> localVarResult(new DataSourceVM());

        if(localVarResponseHttpContentType == utility::conversions::to_string_t("application/json"))
        {
            web::json::value localVarJson = web::json::value::parse(localVarResponse);

            ModelBase::fromJson(localVarJson, localVarResult);
        }
        // else if(localVarResponseHttpContentType == utility::conversions::to_string_t("multipart/form-data"))
        // {
        // TODO multipart response parsing
        // }
        else
        {
            throw ApiException(500
                , utility::conversions::to_string_t("error calling dataSourcesUpdateConnectionString: unsupported response type"));
        }

        return localVarResult;
    });
}
pplx::task<void> DataSourcesApi::dataSourcesUpdatePermissions(utility::string_t id, boost::optional<std::shared_ptr<UpdateDataSourcePermissionsVM>> updateDataSourcePermissionsVM) const
{

    std::shared_ptr<const ApiConfiguration> localVarApiConfiguration( m_ApiClient->getConfiguration() );
    utility::string_t localVarPath = utility::conversions::to_string_t("/api/data/v1/DataSources/{id}/permissions");
    boost::replace_all(localVarPath, utility::conversions::to_string_t("{") + utility::conversions::to_string_t("id") + utility::conversions::to_string_t("}"), ApiClient::parameterToString(id));

    std::map<utility::string_t, utility::string_t> localVarQueryParams;
    std::map<utility::string_t, utility::string_t> localVarHeaderParams( localVarApiConfiguration->getDefaultHeaders() );
    std::map<utility::string_t, utility::string_t> localVarFormParams;
    std::map<utility::string_t, std::shared_ptr<HttpContent>> localVarFileParams;

    std::unordered_set<utility::string_t> localVarResponseHttpContentTypes;
    localVarResponseHttpContentTypes.insert( utility::conversions::to_string_t("application/json") );

    utility::string_t localVarResponseHttpContentType;

    // use JSON if possible
    if ( localVarResponseHttpContentTypes.size() == 0 )
    {
        localVarResponseHttpContentType = utility::conversions::to_string_t("application/json");
    }
    // JSON
    else if ( localVarResponseHttpContentTypes.find(utility::conversions::to_string_t("application/json")) != localVarResponseHttpContentTypes.end() )
    {
        localVarResponseHttpContentType = utility::conversions::to_string_t("application/json");
    }
    // multipart formdata
    else if( localVarResponseHttpContentTypes.find(utility::conversions::to_string_t("multipart/form-data")) != localVarResponseHttpContentTypes.end() )
    {
        localVarResponseHttpContentType = utility::conversions::to_string_t("multipart/form-data");
    }
    else
    {
        throw ApiException(400, utility::conversions::to_string_t("DataSourcesApi->dataSourcesUpdatePermissions does not produce any supported media type"));
    }

    localVarHeaderParams[utility::conversions::to_string_t("Accept")] = localVarResponseHttpContentType;

    std::unordered_set<utility::string_t> localVarConsumeHttpContentTypes;
    localVarConsumeHttpContentTypes.insert( utility::conversions::to_string_t("application/json") );
    localVarConsumeHttpContentTypes.insert( utility::conversions::to_string_t("text/json") );
    localVarConsumeHttpContentTypes.insert( utility::conversions::to_string_t("application/_*+json") );

    std::shared_ptr<IHttpBody> localVarHttpBody;
    utility::string_t localVarRequestHttpContentType;

    // use JSON if possible
    if ( localVarConsumeHttpContentTypes.size() == 0 || localVarConsumeHttpContentTypes.find(utility::conversions::to_string_t("application/json")) != localVarConsumeHttpContentTypes.end() )
    {
        localVarRequestHttpContentType = utility::conversions::to_string_t("application/json");
        web::json::value localVarJson;

        if (updateDataSourcePermissionsVM)
            localVarJson = ModelBase::toJson(*updateDataSourcePermissionsVM);

        localVarHttpBody = std::shared_ptr<IHttpBody>( new JsonBody( localVarJson ) );
    }
    // multipart formdata
    else if( localVarConsumeHttpContentTypes.find(utility::conversions::to_string_t("multipart/form-data")) != localVarConsumeHttpContentTypes.end() )
    {
        localVarRequestHttpContentType = utility::conversions::to_string_t("multipart/form-data");
        std::shared_ptr<MultipartFormData> localVarMultipart(new MultipartFormData);

        if(updateDataSourcePermissionsVM && (*updateDataSourcePermissionsVM).get())
        {
            (*updateDataSourcePermissionsVM)->toMultipart(localVarMultipart, utility::conversions::to_string_t("updateDataSourcePermissionsVM"));
        }

        localVarHttpBody = localVarMultipart;
        localVarRequestHttpContentType += utility::conversions::to_string_t("; boundary=") + localVarMultipart->getBoundary();
    }
    else if (localVarConsumeHttpContentTypes.find(utility::conversions::to_string_t("application/x-www-form-urlencoded")) != localVarConsumeHttpContentTypes.end())
    {
        localVarRequestHttpContentType = utility::conversions::to_string_t("application/x-www-form-urlencoded");
    }
    else
    {
        throw ApiException(415, utility::conversions::to_string_t("DataSourcesApi->dataSourcesUpdatePermissions does not consume any supported media type"));
    }

    // authentication (ApiKey) required
    // Basic authentication is added automatically as part of the http_client_config
    // authentication (JWT) required
    // Basic authentication is added automatically as part of the http_client_config

    return m_ApiClient->callApi(localVarPath, utility::conversions::to_string_t("POST"), localVarQueryParams, localVarHttpBody, localVarHeaderParams, localVarFormParams, localVarFileParams, localVarRequestHttpContentType)
    .then([=](web::http::http_response localVarResponse)
    {
        if (m_ApiClient->getResponseHandler())
        {
            m_ApiClient->getResponseHandler()(localVarResponse.status_code(), localVarResponse.headers());
        }

        // 1xx - informational : OK
        // 2xx - successful       : OK
        // 3xx - redirection   : OK
        // 4xx - client error  : not OK
        // 5xx - client error  : not OK
        if (localVarResponse.status_code() >= 400)
        {
            throw ApiException(localVarResponse.status_code()
                , utility::conversions::to_string_t("error calling dataSourcesUpdatePermissions: ") + localVarResponse.reason_phrase()
                , std::make_shared<std::stringstream>(localVarResponse.extract_utf8string(true).get()));
        }

        // check response content type
        if(localVarResponse.headers().has(utility::conversions::to_string_t("Content-Type")))
        {
            utility::string_t localVarContentType = localVarResponse.headers()[utility::conversions::to_string_t("Content-Type")];
            if( localVarContentType.find(localVarResponseHttpContentType) == std::string::npos )
            {
                throw ApiException(500
                    , utility::conversions::to_string_t("error calling dataSourcesUpdatePermissions: unexpected response type: ") + localVarContentType
                    , std::make_shared<std::stringstream>(localVarResponse.extract_utf8string(true).get()));
            }
        }

        return localVarResponse.extract_string();
    })
    .then([=](utility::string_t localVarResponse)
    {
        return void();
    });
}
pplx::task<void> DataSourcesApi::dataSourcesUpdateSubscriptionDataSource(utility::string_t id, boost::optional<std::shared_ptr<UpdateDataSourceSubscriptionVM>> updateDataSourceSubscriptionVM) const
{

    std::shared_ptr<const ApiConfiguration> localVarApiConfiguration( m_ApiClient->getConfiguration() );
    utility::string_t localVarPath = utility::conversions::to_string_t("/api/data/v1/DataSources/{id}/updateSubscription");
    boost::replace_all(localVarPath, utility::conversions::to_string_t("{") + utility::conversions::to_string_t("id") + utility::conversions::to_string_t("}"), ApiClient::parameterToString(id));

    std::map<utility::string_t, utility::string_t> localVarQueryParams;
    std::map<utility::string_t, utility::string_t> localVarHeaderParams( localVarApiConfiguration->getDefaultHeaders() );
    std::map<utility::string_t, utility::string_t> localVarFormParams;
    std::map<utility::string_t, std::shared_ptr<HttpContent>> localVarFileParams;

    std::unordered_set<utility::string_t> localVarResponseHttpContentTypes;
    localVarResponseHttpContentTypes.insert( utility::conversions::to_string_t("application/json") );

    utility::string_t localVarResponseHttpContentType;

    // use JSON if possible
    if ( localVarResponseHttpContentTypes.size() == 0 )
    {
        localVarResponseHttpContentType = utility::conversions::to_string_t("application/json");
    }
    // JSON
    else if ( localVarResponseHttpContentTypes.find(utility::conversions::to_string_t("application/json")) != localVarResponseHttpContentTypes.end() )
    {
        localVarResponseHttpContentType = utility::conversions::to_string_t("application/json");
    }
    // multipart formdata
    else if( localVarResponseHttpContentTypes.find(utility::conversions::to_string_t("multipart/form-data")) != localVarResponseHttpContentTypes.end() )
    {
        localVarResponseHttpContentType = utility::conversions::to_string_t("multipart/form-data");
    }
    else
    {
        throw ApiException(400, utility::conversions::to_string_t("DataSourcesApi->dataSourcesUpdateSubscriptionDataSource does not produce any supported media type"));
    }

    localVarHeaderParams[utility::conversions::to_string_t("Accept")] = localVarResponseHttpContentType;

    std::unordered_set<utility::string_t> localVarConsumeHttpContentTypes;
    localVarConsumeHttpContentTypes.insert( utility::conversions::to_string_t("application/json") );
    localVarConsumeHttpContentTypes.insert( utility::conversions::to_string_t("text/json") );
    localVarConsumeHttpContentTypes.insert( utility::conversions::to_string_t("application/_*+json") );

    std::shared_ptr<IHttpBody> localVarHttpBody;
    utility::string_t localVarRequestHttpContentType;

    // use JSON if possible
    if ( localVarConsumeHttpContentTypes.size() == 0 || localVarConsumeHttpContentTypes.find(utility::conversions::to_string_t("application/json")) != localVarConsumeHttpContentTypes.end() )
    {
        localVarRequestHttpContentType = utility::conversions::to_string_t("application/json");
        web::json::value localVarJson;

        if (updateDataSourceSubscriptionVM)
            localVarJson = ModelBase::toJson(*updateDataSourceSubscriptionVM);

        localVarHttpBody = std::shared_ptr<IHttpBody>( new JsonBody( localVarJson ) );
    }
    // multipart formdata
    else if( localVarConsumeHttpContentTypes.find(utility::conversions::to_string_t("multipart/form-data")) != localVarConsumeHttpContentTypes.end() )
    {
        localVarRequestHttpContentType = utility::conversions::to_string_t("multipart/form-data");
        std::shared_ptr<MultipartFormData> localVarMultipart(new MultipartFormData);

        if(updateDataSourceSubscriptionVM && (*updateDataSourceSubscriptionVM).get())
        {
            (*updateDataSourceSubscriptionVM)->toMultipart(localVarMultipart, utility::conversions::to_string_t("updateDataSourceSubscriptionVM"));
        }

        localVarHttpBody = localVarMultipart;
        localVarRequestHttpContentType += utility::conversions::to_string_t("; boundary=") + localVarMultipart->getBoundary();
    }
    else if (localVarConsumeHttpContentTypes.find(utility::conversions::to_string_t("application/x-www-form-urlencoded")) != localVarConsumeHttpContentTypes.end())
    {
        localVarRequestHttpContentType = utility::conversions::to_string_t("application/x-www-form-urlencoded");
    }
    else
    {
        throw ApiException(415, utility::conversions::to_string_t("DataSourcesApi->dataSourcesUpdateSubscriptionDataSource does not consume any supported media type"));
    }

    // authentication (ApiKey) required
    // Basic authentication is added automatically as part of the http_client_config
    // authentication (JWT) required
    // Basic authentication is added automatically as part of the http_client_config

    return m_ApiClient->callApi(localVarPath, utility::conversions::to_string_t("PUT"), localVarQueryParams, localVarHttpBody, localVarHeaderParams, localVarFormParams, localVarFileParams, localVarRequestHttpContentType)
    .then([=](web::http::http_response localVarResponse)
    {
        if (m_ApiClient->getResponseHandler())
        {
            m_ApiClient->getResponseHandler()(localVarResponse.status_code(), localVarResponse.headers());
        }

        // 1xx - informational : OK
        // 2xx - successful       : OK
        // 3xx - redirection   : OK
        // 4xx - client error  : not OK
        // 5xx - client error  : not OK
        if (localVarResponse.status_code() >= 400)
        {
            throw ApiException(localVarResponse.status_code()
                , utility::conversions::to_string_t("error calling dataSourcesUpdateSubscriptionDataSource: ") + localVarResponse.reason_phrase()
                , std::make_shared<std::stringstream>(localVarResponse.extract_utf8string(true).get()));
        }

        // check response content type
        if(localVarResponse.headers().has(utility::conversions::to_string_t("Content-Type")))
        {
            utility::string_t localVarContentType = localVarResponse.headers()[utility::conversions::to_string_t("Content-Type")];
            if( localVarContentType.find(localVarResponseHttpContentType) == std::string::npos )
            {
                throw ApiException(500
                    , utility::conversions::to_string_t("error calling dataSourcesUpdateSubscriptionDataSource: unexpected response type: ") + localVarContentType
                    , std::make_shared<std::stringstream>(localVarResponse.extract_utf8string(true).get()));
            }
        }

        return localVarResponse.extract_string();
    })
    .then([=](utility::string_t localVarResponse)
    {
        return void();
    });
}

}
}
}

max_stars_repo_name: FastReports/FastReport-Cloud-Cpp

max_issues_repo_name: FastReports/FastReport-Cloud-Cpp

max_forks_repo_name: FastReports/FastReport-Cloud-Cpp