text:
// This file is auto-generated, don't edit it. Thanks.

#include <alibabacloud/cddc_20200320.hpp>
#include <alibabacloud/endpoint_util.hpp>
#include <alibabacloud/open_api.hpp>
#include <alibabacloud/open_api_util.hpp>
#include <boost/any.hpp>
#include <boost/throw_exception.hpp>
#include <darabonba/core.hpp>
#include <darabonba/util.hpp>
#include <iostream>
#include <map>
#include <vector>

using namespace std;

using namespace Alibabacloud_Cddc20200320;

Alibabacloud_Cddc20200320::Client::Client(const shared_ptr<Alibabacloud_OpenApi::Config>& config) : Alibabacloud_OpenApi::Client(config) {
  _endpointRule = make_shared<string>("");
  checkConfig(config);
  _endpoint = make_shared<string>(getEndpoint(make_shared<string>("cddc"), _regionId, _endpointRule, _network, _suffix, _endpointMap, _endpoint));
};

string Alibabacloud_Cddc20200320::Client::getEndpoint(shared_ptr<string> productId,
                                                      shared_ptr<string> regionId,
                                                      shared_ptr<string> endpointRule,
                                                      shared_ptr<string> network,
                                                      shared_ptr<string> suffix,
                                                      shared_ptr<map<string, string>> endpointMap,
                                                      shared_ptr<string> endpoint) {
  if (!Darabonba_Util::Client::empty(endpoint)) {
    return *endpoint;
  }
  if (!Darabonba_Util::Client::isUnset<map<string, string>>(endpointMap) && !Darabonba_Util::Client::empty(make_shared<string>((*endpointMap)[regionId]))) {
    return (*endpointMap)[regionId];
  }
  return Alibabacloud_EndpointUtil::Client::getEndpointRules(productId, regionId, endpointRule, network, suffix);
}

CreateDedicatedHostResponse Alibabacloud_Cddc20200320::Client::createDedicatedHostWithOptions(shared_ptr<CreateDedicatedHostRequest> request, shared_ptr<Darabonba_Util::RuntimeOptions> runtime) {
  Darabonba_Util::Client::validateModel(request);
  shared_ptr<map<string, boost::any>> query = make_shared<map<string, boost::any>>(map<string, boost::any>());
  query->insert(pair<string, string>("AutoRenew", *request->autoRenew));
  query->insert(pair<string, string>("ClientToken", *request->clientToken));
  query->insert(pair<string, string>("DedicatedHostGroupId", *request->dedicatedHostGroupId));
  query->insert(pair<string, string>("HostClass", *request->hostClass));
  query->insert(pair<string, string>("HostName", *request->hostName));
  query->insert(pair<string, string>("ImageCategory", *request->imageCategory));
  query->insert(pair<string, string>("OsPassword", *request->osPassword));
  query->insert(pair<string, long>("OwnerId", *request->ownerId));
  query->insert(pair<string, string>("PayType", *request->payType));
  query->insert(pair<string, string>("Period", *request->period));
  query->insert(pair<string, string>("RegionId", *request->regionId));
  query->insert(pair<string, string>("ResourceOwnerAccount", *request->resourceOwnerAccount));
  query->insert(pair<string, long>("ResourceOwnerId", *request->resourceOwnerId));
  query->insert(pair<string, string>("UsedTime", *request->usedTime));
  query->insert(pair<string, string>("VSwitchId", *request->vSwitchId));
  query->insert(pair<string, string>("ZoneId", *request->zoneId));
  shared_ptr<Alibabacloud_OpenApi::OpenApiRequest> req = make_shared<Alibabacloud_OpenApi::OpenApiRequest>(map<string, boost::any>({
    {"query", boost::any(Alibabacloud_OpenApiUtil::Client::query(query))}
  }));
  shared_ptr<Alibabacloud_OpenApi::Params> params = make_shared<Alibabacloud_OpenApi::Params>(map<string, boost::any>({
    {"action", boost::any(string("CreateDedicatedHost"))},
    {"version", boost::any(string("2020-03-20"))},
    {"protocol", boost::any(string("HTTPS"))},
    {"pathname", boost::any(string("/"))},
    {"method", boost::any(string("POST"))},
    {"authType", boost::any(string("AK"))},
    {"style", boost::any(string("RPC"))},
    {"reqBodyType", boost::any(string("formData"))},
    {"bodyType", boost::any(string("json"))}
  }));
  return CreateDedicatedHostResponse(callApi(params, req, runtime));
}

CreateDedicatedHostResponse Alibabacloud_Cddc20200320::Client::createDedicatedHost(shared_ptr<CreateDedicatedHostRequest> request) {
  shared_ptr<Darabonba_Util::RuntimeOptions> runtime = make_shared<Darabonba_Util::RuntimeOptions>();
  return createDedicatedHostWithOptions(request, runtime);
}

CreateDedicatedHostAccountResponse Alibabacloud_Cddc20200320::Client::createDedicatedHostAccountWithOptions(shared_ptr<CreateDedicatedHostAccountRequest> request, shared_ptr<Darabonba_Util::RuntimeOptions> runtime) {
  Darabonba_Util::Client::validateModel(request);
  shared_ptr<map<string, boost::any>> query = make_shared<map<string, boost::any>>(map<string, boost::any>());
  query->insert(pair<string, string>("AccountName", *request->accountName));
  query->insert(pair<string, string>("AccountPassword", *request->accountPassword));
  query->insert(pair<string, string>("AccountType", *request->accountType));
  query->insert(pair<string, string>("BastionInstanceId", *request->bastionInstanceId));
  query->insert(pair<string, string>("ClientToken", *request->clientToken));
  query->insert(pair<string, string>("DedicatedHostId", *request->dedicatedHostId));
  query->insert(pair<string, long>("OwnerId", *request->ownerId));
  query->insert(pair<string, string>("RegionId", *request->regionId));
  query->insert(pair<string, string>("ResourceOwnerAccount", *request->resourceOwnerAccount));
  query->insert(pair<string, long>("ResourceOwnerId", *request->resourceOwnerId));
  shared_ptr<Alibabacloud_OpenApi::OpenApiRequest> req = make_shared<Alibabacloud_OpenApi::OpenApiRequest>(map<string, boost::any>({
    {"query", boost::any(Alibabacloud_OpenApiUtil::Client::query(query))}
  }));
  shared_ptr<Alibabacloud_OpenApi::Params> params = make_shared<Alibabacloud_OpenApi::Params>(map<string, boost::any>({
    {"action", boost::any(string("CreateDedicatedHostAccount"))},
    {"version", boost::any(string("2020-03-20"))},
    {"protocol", boost::any(string("HTTPS"))},
    {"pathname", boost::any(string("/"))},
    {"method", boost::any(string("POST"))},
    {"authType", boost::any(string("AK"))},
    {"style", boost::any(string("RPC"))},
    {"reqBodyType", boost::any(string("formData"))},
    {"bodyType", boost::any(string("json"))}
  }));
  return CreateDedicatedHostAccountResponse(callApi(params, req, runtime));
}

CreateDedicatedHostAccountResponse Alibabacloud_Cddc20200320::Client::createDedicatedHostAccount(shared_ptr<CreateDedicatedHostAccountRequest> request) {
  shared_ptr<Darabonba_Util::RuntimeOptions> runtime = make_shared<Darabonba_Util::RuntimeOptions>();
  return createDedicatedHostAccountWithOptions(request, runtime);
}

CreateDedicatedHostGroupResponse Alibabacloud_Cddc20200320::Client::createDedicatedHostGroupWithOptions(shared_ptr<CreateDedicatedHostGroupRequest> request, shared_ptr<Darabonba_Util::RuntimeOptions> runtime) {
  Darabonba_Util::Client::validateModel(request);
  shared_ptr<map<string, boost::any>> query = make_shared<map<string, boost::any>>(map<string, boost::any>());
  query->insert(pair<string, string>("AllocationPolicy", *request->allocationPolicy));
  query->insert(pair<string, string>("ClientToken", *request->clientToken));
  query->insert(pair<string, long>("CpuAllocationRatio", *request->cpuAllocationRatio));
  query->insert(pair<string, string>("DedicatedHostGroupDesc", *request->dedicatedHostGroupDesc));
  query->insert(pair<string, long>("DiskAllocationRatio", *request->diskAllocationRatio));
  query->insert(pair<string, string>("Engine", *request->engine));
  query->insert(pair<string, string>("HostReplacePolicy", *request->hostReplacePolicy));
  query->insert(pair<string, long>("MemAllocationRatio", *request->memAllocationRatio));
  query->insert(pair<string, long>("OpenPermission", *request->openPermission));
  query->insert(pair<string, long>("OwnerId", *request->ownerId));
  query->insert(pair<string, string>("RegionId", *request->regionId));
  query->insert(pair<string, string>("ResourceOwnerAccount", *request->resourceOwnerAccount));
  query->insert(pair<string, long>("ResourceOwnerId", *request->resourceOwnerId));
  query->insert(pair<string, string>("VPCId", *request->VPCId));
  shared_ptr<Alibabacloud_OpenApi::OpenApiRequest> req = make_shared<Alibabacloud_OpenApi::OpenApiRequest>(map<string, boost::any>({
    {"query", boost::any(Alibabacloud_OpenApiUtil::Client::query(query))}
  }));
  shared_ptr<Alibabacloud_OpenApi::Params> params = make_shared<Alibabacloud_OpenApi::Params>(map<string, boost::any>({
    {"action", boost::any(string("CreateDedicatedHostGroup"))},
    {"version", boost::any(string("2020-03-20"))},
    {"protocol", boost::any(string("HTTPS"))},
    {"pathname", boost::any(string("/"))},
    {"method", boost::any(string("POST"))},
    {"authType", boost::any(string("AK"))},
    {"style", boost::any(string("RPC"))},
    {"reqBodyType", boost::any(string("formData"))},
    {"bodyType", boost::any(string("json"))}
  }));
  return CreateDedicatedHostGroupResponse(callApi(params, req, runtime));
}

CreateDedicatedHostGroupResponse Alibabacloud_Cddc20200320::Client::createDedicatedHostGroup(shared_ptr<CreateDedicatedHostGroupRequest> request) {
  shared_ptr<Darabonba_Util::RuntimeOptions> runtime = make_shared<Darabonba_Util::RuntimeOptions>();
  return createDedicatedHostGroupWithOptions(request, runtime);
}

DeleteDedicatedHostAccountResponse Alibabacloud_Cddc20200320::Client::deleteDedicatedHostAccountWithOptions(shared_ptr<DeleteDedicatedHostAccountRequest> request, shared_ptr<Darabonba_Util::RuntimeOptions> runtime) {
  Darabonba_Util::Client::validateModel(request);
  shared_ptr<map<string, boost::any>> query = make_shared<map<string, boost::any>>(map<string, boost::any>());
  query->insert(pair<string, string>("AccountName", *request->accountName));
  query->insert(pair<string, string>("DedicatedHostId", *request->dedicatedHostId));
  query->insert(pair<string, long>("OwnerId", *request->ownerId));
  query->insert(pair<string, string>("RegionId", *request->regionId));
  query->insert(pair<string, string>("ResourceOwnerAccount", *request->resourceOwnerAccount));
  query->insert(pair<string, long>("ResourceOwnerId", *request->resourceOwnerId));
  shared_ptr<Alibabacloud_OpenApi::OpenApiRequest> req = make_shared<Alibabacloud_OpenApi::OpenApiRequest>(map<string, boost::any>({
    {"query", boost::any(Alibabacloud_OpenApiUtil::Client::query(query))}
  }));
  shared_ptr<Alibabacloud_OpenApi::Params> params = make_shared<Alibabacloud_OpenApi::Params>(map<string, boost::any>({
    {"action", boost::any(string("DeleteDedicatedHostAccount"))},
    {"version", boost::any(string("2020-03-20"))},
    {"protocol", boost::any(string("HTTPS"))},
    {"pathname", boost::any(string("/"))},
    {"method", boost::any(string("POST"))},
    {"authType", boost::any(string("AK"))},
    {"style", boost::any(string("RPC"))},
    {"reqBodyType", boost::any(string("formData"))},
    {"bodyType", boost::any(string("json"))}
  }));
  return DeleteDedicatedHostAccountResponse(callApi(params, req, runtime));
}

DeleteDedicatedHostAccountResponse Alibabacloud_Cddc20200320::Client::deleteDedicatedHostAccount(shared_ptr<DeleteDedicatedHostAccountRequest> request) {
  shared_ptr<Darabonba_Util::RuntimeOptions> runtime = make_shared<Darabonba_Util::RuntimeOptions>();
  return deleteDedicatedHostAccountWithOptions(request, runtime);
}

DeleteDedicatedHostGroupResponse Alibabacloud_Cddc20200320::Client::deleteDedicatedHostGroupWithOptions(shared_ptr<DeleteDedicatedHostGroupRequest> request, shared_ptr<Darabonba_Util::RuntimeOptions> runtime) {
  Darabonba_Util::Client::validateModel(request);
  shared_ptr<map<string, boost::any>> query = make_shared<map<string, boost::any>>(map<string, boost::any>());
  query->insert(pair<string, string>("DedicatedHostGroupId", *request->dedicatedHostGroupId));
  query->insert(pair<string, long>("OwnerId", *request->ownerId));
  query->insert(pair<string, string>("RegionId", *request->regionId));
  query->insert(pair<string, string>("ResourceOwnerAccount", *request->resourceOwnerAccount));
  query->insert(pair<string, long>("ResourceOwnerId", *request->resourceOwnerId));
  shared_ptr<Alibabacloud_OpenApi::OpenApiRequest> req = make_shared<Alibabacloud_OpenApi::OpenApiRequest>(map<string, boost::any>({
    {"query", boost::any(Alibabacloud_OpenApiUtil::Client::query(query))}
  }));
  shared_ptr<Alibabacloud_OpenApi::Params> params = make_shared<Alibabacloud_OpenApi::Params>(map<string, boost::any>({
    {"action", boost::any(string("DeleteDedicatedHostGroup"))},
    {"version", boost::any(string("2020-03-20"))},
    {"protocol", boost::any(string("HTTPS"))},
    {"pathname", boost::any(string("/"))},
    {"method", boost::any(string("POST"))},
    {"authType", boost::any(string("AK"))},
    {"style", boost::any(string("RPC"))},
    {"reqBodyType", boost::any(string("formData"))},
    {"bodyType", boost::any(string("json"))}
  }));
  return DeleteDedicatedHostGroupResponse(callApi(params, req, runtime));
}

DeleteDedicatedHostGroupResponse Alibabacloud_Cddc20200320::Client::deleteDedicatedHostGroup(shared_ptr<DeleteDedicatedHostGroupRequest> request) {
  shared_ptr<Darabonba_Util::RuntimeOptions> runtime = make_shared<Darabonba_Util::RuntimeOptions>();
  return deleteDedicatedHostGroupWithOptions(request, runtime);
}

DescribeDedicatedHostAttributeResponse Alibabacloud_Cddc20200320::Client::describeDedicatedHostAttributeWithOptions(shared_ptr<DescribeDedicatedHostAttributeRequest> request, shared_ptr<Darabonba_Util::RuntimeOptions> runtime) {
  Darabonba_Util::Client::validateModel(request);
  shared_ptr<map<string, boost::any>> query = make_shared<map<string, boost::any>>(map<string, boost::any>());
  query->insert(pair<string, string>("DedicatedHostGroupId", *request->dedicatedHostGroupId));
  query->insert(pair<string, string>("DedicatedHostId", *request->dedicatedHostId));
  query->insert(pair<string, long>("OwnerId", *request->ownerId));
  query->insert(pair<string, string>("RegionId", *request->regionId));
  query->insert(pair<string, string>("ResourceOwnerAccount", *request->resourceOwnerAccount));
  query->insert(pair<string, long>("ResourceOwnerId", *request->resourceOwnerId));
  shared_ptr<Alibabacloud_OpenApi::OpenApiRequest> req = make_shared<Alibabacloud_OpenApi::OpenApiRequest>(map<string, boost::any>({
    {"query", boost::any(Alibabacloud_OpenApiUtil::Client::query(query))}
  }));
  shared_ptr<Alibabacloud_OpenApi::Params> params = make_shared<Alibabacloud_OpenApi::Params>(map<string, boost::any>({
    {"action", boost::any(string("DescribeDedicatedHostAttribute"))},
    {"version", boost::any(string("2020-03-20"))},
    {"protocol", boost::any(string("HTTPS"))},
    {"pathname", boost::any(string("/"))},
    {"method", boost::any(string("POST"))},
    {"authType", boost::any(string("AK"))},
    {"style", boost::any(string("RPC"))},
    {"reqBodyType", boost::any(string("formData"))},
    {"bodyType", boost::any(string("json"))}
  }));
  return DescribeDedicatedHostAttributeResponse(callApi(params, req, runtime));
}

DescribeDedicatedHostAttributeResponse Alibabacloud_Cddc20200320::Client::describeDedicatedHostAttribute(shared_ptr<DescribeDedicatedHostAttributeRequest> request) {
  shared_ptr<Darabonba_Util::RuntimeOptions> runtime = make_shared<Darabonba_Util::RuntimeOptions>();
  return describeDedicatedHostAttributeWithOptions(request, runtime);
}

DescribeDedicatedHostDisksResponse Alibabacloud_Cddc20200320::Client::describeDedicatedHostDisksWithOptions(shared_ptr<DescribeDedicatedHostDisksRequest> request, shared_ptr<Darabonba_Util::RuntimeOptions> runtime) {
  Darabonba_Util::Client::validateModel(request);
  shared_ptr<map<string, boost::any>> query = make_shared<map<string, boost::any>>(map<string, boost::any>());
  query->insert(pair<string, string>("DedicatedHostId", *request->dedicatedHostId));
  query->insert(pair<string, long>("OwnerId", *request->ownerId));
  query->insert(pair<string, string>("RegionId", *request->regionId));
  query->insert(pair<string, string>("ResourceOwnerAccount", *request->resourceOwnerAccount));
  query->insert(pair<string, long>("ResourceOwnerId", *request->resourceOwnerId));
  shared_ptr<Alibabacloud_OpenApi::OpenApiRequest> req = make_shared<Alibabacloud_OpenApi::OpenApiRequest>(map<string, boost::any>({
    {"query", boost::any(Alibabacloud_OpenApiUtil::Client::query(query))}
  }));
  shared_ptr<Alibabacloud_OpenApi::Params> params = make_shared<Alibabacloud_OpenApi::Params>(map<string, boost::any>({
    {"action", boost::any(string("DescribeDedicatedHostDisks"))},
    {"version", boost::any(string("2020-03-20"))},
    {"protocol", boost::any(string("HTTPS"))},
    {"pathname", boost::any(string("/"))},
    {"method", boost::any(string("POST"))},
    {"authType", boost::any(string("AK"))},
    {"style", boost::any(string("RPC"))},
    {"reqBodyType", boost::any(string("formData"))},
    {"bodyType", boost::any(string("json"))}
  }));
  return DescribeDedicatedHostDisksResponse(callApi(params, req, runtime));
}

DescribeDedicatedHostDisksResponse Alibabacloud_Cddc20200320::Client::describeDedicatedHostDisks(shared_ptr<DescribeDedicatedHostDisksRequest> request) {
  shared_ptr<Darabonba_Util::RuntimeOptions> runtime = make_shared<Darabonba_Util::RuntimeOptions>();
  return describeDedicatedHostDisksWithOptions(request, runtime);
}

DescribeDedicatedHostGroupsResponse Alibabacloud_Cddc20200320::Client::describeDedicatedHostGroupsWithOptions(shared_ptr<DescribeDedicatedHostGroupsRequest> request, shared_ptr<Darabonba_Util::RuntimeOptions> runtime) {
  Darabonba_Util::Client::validateModel(request);
  shared_ptr<map<string, boost::any>> query = make_shared<map<string, boost::any>>(map<string, boost::any>());
  query->insert(pair<string, string>("DedicatedHostGroupId", *request->dedicatedHostGroupId));
  query->insert(pair<string, string>("Engine", *request->engine));
  query->insert(pair<string, string>("ImageCategory", *request->imageCategory));
  query->insert(pair<string, long>("OwnerId", *request->ownerId));
  query->insert(pair<string, string>("RegionId", *request->regionId));
  query->insert(pair<string, string>("ResourceOwnerAccount", *request->resourceOwnerAccount));
  query->insert(pair<string, long>("ResourceOwnerId", *request->resourceOwnerId));
  shared_ptr<Alibabacloud_OpenApi::OpenApiRequest> req = make_shared<Alibabacloud_OpenApi::OpenApiRequest>(map<string, boost::any>({
    {"query", boost::any(Alibabacloud_OpenApiUtil::Client::query(query))}
  }));
  shared_ptr<Alibabacloud_OpenApi::Params> params = make_shared<Alibabacloud_OpenApi::Params>(map<string, boost::any>({
    {"action", boost::any(string("DescribeDedicatedHostGroups"))},
    {"version", boost::any(string("2020-03-20"))},
    {"protocol", boost::any(string("HTTPS"))},
    {"pathname", boost::any(string("/"))},
    {"method", boost::any(string("POST"))},
    {"authType", boost::any(string("AK"))},
    {"style", boost::any(string("RPC"))},
    {"reqBodyType", boost::any(string("formData"))},
    {"bodyType", boost::any(string("json"))}
  }));
  return DescribeDedicatedHostGroupsResponse(callApi(params, req, runtime));
}

DescribeDedicatedHostGroupsResponse Alibabacloud_Cddc20200320::Client::describeDedicatedHostGroups(shared_ptr<DescribeDedicatedHostGroupsRequest> request) {
  shared_ptr<Darabonba_Util::RuntimeOptions> runtime = make_shared<Darabonba_Util::RuntimeOptions>();
  return describeDedicatedHostGroupsWithOptions(request, runtime);
}

DescribeDedicatedHostsResponse Alibabacloud_Cddc20200320::Client::describeDedicatedHostsWithOptions(shared_ptr<DescribeDedicatedHostsRequest> request, shared_ptr<Darabonba_Util::RuntimeOptions> runtime) {
  Darabonba_Util::Client::validateModel(request);
  shared_ptr<map<string, boost::any>> query = make_shared<map<string, boost::any>>(map<string, boost::any>());
  query->insert(pair<string, string>("AllocationStatus", *request->allocationStatus));
  query->insert(pair<string, string>("DedicatedHostGroupId", *request->dedicatedHostGroupId));
  query->insert(pair<string, string>("DedicatedHostId", *request->dedicatedHostId));
  query->insert(pair<string, string>("HostStatus", *request->hostStatus));
  query->insert(pair<string, string>("HostType", *request->hostType));
  query->insert(pair<string, long>("OrderId", *request->orderId));
  query->insert(pair<string, long>("OwnerId", *request->ownerId));
  query->insert(pair<string, long>("PageNumbers", *request->pageNumbers));
  query->insert(pair<string, long>("PageSize", *request->pageSize));
  query->insert(pair<string, string>("RegionId", *request->regionId));
  query->insert(pair<string, string>("ResourceOwnerAccount", *request->resourceOwnerAccount));
  query->insert(pair<string, long>("ResourceOwnerId", *request->resourceOwnerId));
  query->insert(pair<string, string>("Tags", *request->tags));
  query->insert(pair<string, string>("ZoneId", *request->zoneId));
  shared_ptr<Alibabacloud_OpenApi::OpenApiRequest> req = make_shared<Alibabacloud_OpenApi::OpenApiRequest>(map<string, boost::any>({
    {"query", boost::any(Alibabacloud_OpenApiUtil::Client::query(query))}
  }));
  shared_ptr<Alibabacloud_OpenApi::Params> params = make_shared<Alibabacloud_OpenApi::Params>(map<string, boost::any>({
    {"action", boost::any(string("DescribeDedicatedHosts"))},
    {"version", boost::any(string("2020-03-20"))},
    {"protocol", boost::any(string("HTTPS"))},
    {"pathname", boost::any(string("/"))},
    {"method", boost::any(string("POST"))},
    {"authType", boost::any(string("AK"))},
    {"style", boost::any(string("RPC"))},
    {"reqBodyType", boost::any(string("formData"))},
    {"bodyType", boost::any(string("json"))}
  }));
  return DescribeDedicatedHostsResponse(callApi(params, req, runtime));
}

DescribeDedicatedHostsResponse Alibabacloud_Cddc20200320::Client::describeDedicatedHosts(shared_ptr<DescribeDedicatedHostsRequest> request) {
  shared_ptr<Darabonba_Util::RuntimeOptions> runtime = make_shared<Darabonba_Util::RuntimeOptions>();
  return describeDedicatedHostsWithOptions(request, runtime);
}

DescribeHostEcsLevelInfoResponse Alibabacloud_Cddc20200320::Client::describeHostEcsLevelInfoWithOptions(shared_ptr<DescribeHostEcsLevelInfoRequest> request, shared_ptr<Darabonba_Util::RuntimeOptions> runtime) {
  Darabonba_Util::Client::validateModel(request);
  shared_ptr<map<string, boost::any>> query = make_shared<map<string, boost::any>>(map<string, boost::any>());
  query->insert(pair<string, string>("DbType", *request->dbType));
  query->insert(pair<string, string>("ImageCategory", *request->imageCategory));
  query->insert(pair<string, long>("OwnerId", *request->ownerId));
  query->insert(pair<string, string>("RegionId", *request->regionId));
  query->insert(pair<string, string>("ResourceOwnerAccount", *request->resourceOwnerAccount));
  query->insert(pair<string, long>("ResourceOwnerId", *request->resourceOwnerId));
  query->insert(pair<string, string>("StorageType", *request->storageType));
  query->insert(pair<string, string>("ZoneId", *request->zoneId));
  shared_ptr<Alibabacloud_OpenApi::OpenApiRequest> req = make_shared<Alibabacloud_OpenApi::OpenApiRequest>(map<string, boost::any>({
    {"query", boost::any(Alibabacloud_OpenApiUtil::Client::query(query))}
  }));
  shared_ptr<Alibabacloud_OpenApi::Params> params = make_shared<Alibabacloud_OpenApi::Params>(map<string, boost::any>({
    {"action", boost::any(string("DescribeHostEcsLevelInfo"))},
    {"version", boost::any(string("2020-03-20"))},
    {"protocol", boost::any(string("HTTPS"))},
    {"pathname", boost::any(string("/"))},
    {"method", boost::any(string("POST"))},
    {"authType", boost::any(string("AK"))},
    {"style", boost::any(string("RPC"))},
    {"reqBodyType", boost::any(string("formData"))},
    {"bodyType", boost::any(string("json"))}
  }));
  return DescribeHostEcsLevelInfoResponse(callApi(params, req, runtime));
}

DescribeHostEcsLevelInfoResponse Alibabacloud_Cddc20200320::Client::describeHostEcsLevelInfo(shared_ptr<DescribeHostEcsLevelInfoRequest> request) {
  shared_ptr<Darabonba_Util::RuntimeOptions> runtime = make_shared<Darabonba_Util::RuntimeOptions>();
  return describeHostEcsLevelInfoWithOptions(request, runtime);
}

DescribeHostWebShellResponse Alibabacloud_Cddc20200320::Client::describeHostWebShellWithOptions(shared_ptr<DescribeHostWebShellRequest> request, shared_ptr<Darabonba_Util::RuntimeOptions> runtime) {
  Darabonba_Util::Client::validateModel(request);
  shared_ptr<map<string, boost::any>> query = make_shared<map<string, boost::any>>(map<string, boost::any>());
  query->insert(pair<string, string>("DedicatedHostId", *request->dedicatedHostId));
  query->insert(pair<string, long>("OwnerId", *request->ownerId));
  query->insert(pair<string, string>("RegionId", *request->regionId));
  query->insert(pair<string, string>("ResourceOwnerAccount", *request->resourceOwnerAccount));
  query->insert(pair<string, long>("ResourceOwnerId", *request->resourceOwnerId));
  query->insert(pair<string, string>("ZoneId", *request->zoneId));
  shared_ptr<Alibabacloud_OpenApi::OpenApiRequest> req = make_shared<Alibabacloud_OpenApi::OpenApiRequest>(map<string, boost::any>({
    {"query", boost::any(Alibabacloud_OpenApiUtil::Client::query(query))}
  }));
  shared_ptr<Alibabacloud_OpenApi::Params> params = make_shared<Alibabacloud_OpenApi::Params>(map<string, boost::any>({
    {"action", boost::any(string("DescribeHostWebShell"))},
    {"version", boost::any(string("2020-03-20"))},
    {"protocol", boost::any(string("HTTPS"))},
    {"pathname", boost::any(string("/"))},
    {"method", boost::any(string("POST"))},
    {"authType", boost::any(string("AK"))},
    {"style", boost::any(string("RPC"))},
    {"reqBodyType", boost::any(string("formData"))},
    {"bodyType", boost::any(string("json"))}
  }));
  return DescribeHostWebShellResponse(callApi(params, req, runtime));
}

DescribeHostWebShellResponse Alibabacloud_Cddc20200320::Client::describeHostWebShell(shared_ptr<DescribeHostWebShellRequest> request) {
  shared_ptr<Darabonba_Util::RuntimeOptions> runtime = make_shared<Darabonba_Util::RuntimeOptions>();
  return describeHostWebShellWithOptions(request, runtime);
}

DescribeRegionsResponse Alibabacloud_Cddc20200320::Client::describeRegionsWithOptions(shared_ptr<DescribeRegionsRequest> request, shared_ptr<Darabonba_Util::RuntimeOptions> runtime) {
  Darabonba_Util::Client::validateModel(request);
  shared_ptr<map<string, boost::any>> query = make_shared<map<string, boost::any>>(map<string, boost::any>());
  query->insert(pair<string, long>("ResourceOwnerId", *request->resourceOwnerId));
  shared_ptr<Alibabacloud_OpenApi::OpenApiRequest> req = make_shared<Alibabacloud_OpenApi::OpenApiRequest>(map<string, boost::any>({
    {"query", boost::any(Alibabacloud_OpenApiUtil::Client::query(query))}
  }));
  shared_ptr<Alibabacloud_OpenApi::Params> params = make_shared<Alibabacloud_OpenApi::Params>(map<string, boost::any>({
    {"action", boost::any(string("DescribeRegions"))},
    {"version", boost::any(string("2020-03-20"))},
    {"protocol", boost::any(string("HTTPS"))},
    {"pathname", boost::any(string("/"))},
    {"method", boost::any(string("POST"))},
    {"authType", boost::any(string("AK"))},
    {"style", boost::any(string("RPC"))},
    {"reqBodyType", boost::any(string("formData"))},
    {"bodyType", boost::any(string("json"))}
  }));
  return DescribeRegionsResponse(callApi(params, req, runtime));
}

DescribeRegionsResponse Alibabacloud_Cddc20200320::Client::describeRegions(shared_ptr<DescribeRegionsRequest> request) {
  shared_ptr<Darabonba_Util::RuntimeOptions> runtime = make_shared<Darabonba_Util::RuntimeOptions>();
  return describeRegionsWithOptions(request, runtime);
}

ListTagResourcesResponse Alibabacloud_Cddc20200320::Client::listTagResourcesWithOptions(shared_ptr<ListTagResourcesRequest> request, shared_ptr<Darabonba_Util::RuntimeOptions> runtime) {
  Darabonba_Util::Client::validateModel(request);
  shared_ptr<map<string, boost::any>> query = make_shared<map<string, boost::any>>(map<string, boost::any>());
  query->insert(pair<string, long>("OwnerId", *request->ownerId));
  query->insert(pair<string, string>("RegionId", *request->regionId));
  query->insert(pair<string, vector<string>>("ResourceId", *request->resourceId));
  query->insert(pair<string, string>("ResourceOwnerAccount", *request->resourceOwnerAccount));
  query->insert(pair<string, long>("ResourceOwnerId", *request->resourceOwnerId));
  query->insert(pair<string, string>("ResourceType", *request->resourceType));
  query->insert(pair<string, vector<ListTagResourcesRequestTag>>("Tag", *request->tag));
  shared_ptr<Alibabacloud_OpenApi::OpenApiRequest> req = make_shared<Alibabacloud_OpenApi::OpenApiRequest>(map<string, boost::any>({
    {"query", boost::any(Alibabacloud_OpenApiUtil::Client::query(query))}
  }));
  shared_ptr<Alibabacloud_OpenApi::Params> params = make_shared<Alibabacloud_OpenApi::Params>(map<string, boost::any>({
    {"action", boost::any(string("ListTagResources"))},
    {"version", boost::any(string("2020-03-20"))},
    {"protocol", boost::any(string("HTTPS"))},
    {"pathname", boost::any(string("/"))},
    {"method", boost::any(string("POST"))},
    {"authType", boost::any(string("AK"))},
    {"style", boost::any(string("RPC"))},
    {"reqBodyType", boost::any(string("formData"))},
    {"bodyType", boost::any(string("json"))}
  }));
  return ListTagResourcesResponse(callApi(params, req, runtime));
}

ListTagResourcesResponse Alibabacloud_Cddc20200320::Client::listTagResources(shared_ptr<ListTagResourcesRequest> request) {
  shared_ptr<Darabonba_Util::RuntimeOptions> runtime = make_shared<Darabonba_Util::RuntimeOptions>();
  return listTagResourcesWithOptions(request, runtime);
}

ModifyDedicatedHostAccountResponse Alibabacloud_Cddc20200320::Client::modifyDedicatedHostAccountWithOptions(shared_ptr<ModifyDedicatedHostAccountRequest> request, shared_ptr<Darabonba_Util::RuntimeOptions> runtime) {
  Darabonba_Util::Client::validateModel(request);
  shared_ptr<map<string, boost::any>> query = make_shared<map<string, boost::any>>(map<string, boost::any>());
  query->insert(pair<string, string>("AccountName", *request->accountName));
  query->insert(pair<string, string>("AccountPassword", *request->accountPassword));
  query->insert(pair<string, string>("DedicatedHostId", *request->dedicatedHostId));
  query->insert(pair<string, long>("OwnerId", *request->ownerId));
  query->insert(pair<string, string>("RegionId", *request->regionId));
  query->insert(pair<string, string>("ResourceOwnerAccount", *request->resourceOwnerAccount));
  query->insert(pair<string, long>("ResourceOwnerId", *request->resourceOwnerId));
  shared_ptr<Alibabacloud_OpenApi::OpenApiRequest> req = make_shared<Alibabacloud_OpenApi::OpenApiRequest>(map<string, boost::any>({
    {"query", boost::any(Alibabacloud_OpenApiUtil::Client::query(query))}
  }));
  shared_ptr<Alibabacloud_OpenApi::Params> params = make_shared<Alibabacloud_OpenApi::Params>(map<string, boost::any>({
    {"action", boost::any(string("ModifyDedicatedHostAccount"))},
    {"version", boost::any(string("2020-03-20"))},
    {"protocol", boost::any(string("HTTPS"))},
    {"pathname", boost::any(string("/"))},
    {"method", boost::any(string("POST"))},
    {"authType", boost::any(string("AK"))},
    {"style", boost::any(string("RPC"))},
    {"reqBodyType", boost::any(string("formData"))},
    {"bodyType", boost::any(string("json"))}
  }));
  return ModifyDedicatedHostAccountResponse(callApi(params, req, runtime));
}

ModifyDedicatedHostAccountResponse Alibabacloud_Cddc20200320::Client::modifyDedicatedHostAccount(shared_ptr<ModifyDedicatedHostAccountRequest> request) {
  shared_ptr<Darabonba_Util::RuntimeOptions> runtime = make_shared<Darabonba_Util::RuntimeOptions>();
  return modifyDedicatedHostAccountWithOptions(request, runtime);
}

ModifyDedicatedHostAttributeResponse Alibabacloud_Cddc20200320::Client::modifyDedicatedHostAttributeWithOptions(shared_ptr<ModifyDedicatedHostAttributeRequest> request, shared_ptr<Darabonba_Util::RuntimeOptions> runtime) {
  Darabonba_Util::Client::validateModel(request);
  shared_ptr<map<string, boost::any>> query = make_shared<map<string, boost::any>>(map<string, boost::any>());
  query->insert(pair<string, string>("AllocationStatus", *request->allocationStatus));
  query->insert(pair<string, string>("DedicatedHostId", *request->dedicatedHostId));
  query->insert(pair<string, string>("HostName", *request->hostName));
  query->insert(pair<string, long>("OwnerId", *request->ownerId));
  query->insert(pair<string, string>("RegionId", *request->regionId));
  query->insert(pair<string, string>("ResourceOwnerAccount", *request->resourceOwnerAccount));
  query->insert(pair<string, long>("ResourceOwnerId", *request->resourceOwnerId));
  shared_ptr<Alibabacloud_OpenApi::OpenApiRequest> req = make_shared<Alibabacloud_OpenApi::OpenApiRequest>(map<string, boost::any>({
    {"query", boost::any(Alibabacloud_OpenApiUtil::Client::query(query))}
  }));
  shared_ptr<Alibabacloud_OpenApi::Params> params = make_shared<Alibabacloud_OpenApi::Params>(map<string, boost::any>({
    {"action", boost::any(string("ModifyDedicatedHostAttribute"))},
    {"version", boost::any(string("2020-03-20"))},
    {"protocol", boost::any(string("HTTPS"))},
    {"pathname", boost::any(string("/"))},
    {"method", boost::any(string("POST"))},
    {"authType", boost::any(string("AK"))},
    {"style", boost::any(string("RPC"))},
    {"reqBodyType", boost::any(string("formData"))},
    {"bodyType", boost::any(string("json"))}
  }));
  return ModifyDedicatedHostAttributeResponse(callApi(params, req, runtime));
}

ModifyDedicatedHostAttributeResponse Alibabacloud_Cddc20200320::Client::modifyDedicatedHostAttribute(shared_ptr<ModifyDedicatedHostAttributeRequest> request) {
  shared_ptr<Darabonba_Util::RuntimeOptions> runtime = make_shared<Darabonba_Util::RuntimeOptions>();
  return modifyDedicatedHostAttributeWithOptions(request, runtime);
}

ModifyDedicatedHostClassResponse Alibabacloud_Cddc20200320::Client::modifyDedicatedHostClassWithOptions(shared_ptr<ModifyDedicatedHostClassRequest> request, shared_ptr<Darabonba_Util::RuntimeOptions> runtime) {
  Darabonba_Util::Client::validateModel(request);
  shared_ptr<map<string, boost::any>> query = make_shared<map<string, boost::any>>(map<string, boost::any>());
  query->insert(pair<string, string>("DedicatedHostId", *request->dedicatedHostId));
  query->insert(pair<string, long>("OwnerId", *request->ownerId));
  query->insert(pair<string, string>("RegionId", *request->regionId));
  query->insert(pair<string, string>("ResourceOwnerAccount", *request->resourceOwnerAccount));
  query->insert(pair<string, long>("ResourceOwnerId", *request->resourceOwnerId));
  query->insert(pair<string, string>("SwitchTime", *request->switchTime));
  query->insert(pair<string, string>("SwitchTimeMode", *request->switchTimeMode));
  query->insert(pair<string, string>("TargetClassCode", *request->targetClassCode));
  shared_ptr<Alibabacloud_OpenApi::OpenApiRequest> req = make_shared<Alibabacloud_OpenApi::OpenApiRequest>(map<string, boost::any>({
    {"query", boost::any(Alibabacloud_OpenApiUtil::Client::query(query))}
  }));
  shared_ptr<Alibabacloud_OpenApi::Params> params = make_shared<Alibabacloud_OpenApi::Params>(map<string, boost::any>({
    {"action", boost::any(string("ModifyDedicatedHostClass"))},
    {"version", boost::any(string("2020-03-20"))},
    {"protocol", boost::any(string("HTTPS"))},
    {"pathname", boost::any(string("/"))},
    {"method", boost::any(string("POST"))},
    {"authType", boost::any(string("AK"))},
    {"style", boost::any(string("RPC"))},
    {"reqBodyType", boost::any(string("formData"))},
    {"bodyType", boost::any(string("json"))}
  }));
  return ModifyDedicatedHostClassResponse(callApi(params, req, runtime));
}

ModifyDedicatedHostClassResponse Alibabacloud_Cddc20200320::Client::modifyDedicatedHostClass(shared_ptr<ModifyDedicatedHostClassRequest> request) {
  shared_ptr<Darabonba_Util::RuntimeOptions> runtime = make_shared<Darabonba_Util::RuntimeOptions>();
  return modifyDedicatedHostClassWithOptions(request, runtime);
}

ModifyDedicatedHostGroupAttributeResponse Alibabacloud_Cddc20200320::Client::modifyDedicatedHostGroupAttributeWithOptions(shared_ptr<ModifyDedicatedHostGroupAttributeRequest> request, shared_ptr<Darabonba_Util::RuntimeOptions> runtime) {
  Darabonba_Util::Client::validateModel(request);
  shared_ptr<map<string, boost::any>> query = make_shared<map<string, boost::any>>(map<string, boost::any>());
  query->insert(pair<string, string>("AllocationPolicy", *request->allocationPolicy));
  query->insert(pair<string, long>("CpuAllocationRatio", *request->cpuAllocationRatio));
  query->insert(pair<string, string>("DedicatedHostGroupDesc", *request->dedicatedHostGroupDesc));
  query->insert(pair<string, string>("DedicatedHostGroupId", *request->dedicatedHostGroupId));
  query->insert(pair<string, long>("DiskAllocationRatio", *request->diskAllocationRatio));
  query->insert(pair<string, string>("HostReplacePolicy", *request->hostReplacePolicy));
  query->insert(pair<string, long>("MemAllocationRatio", *request->memAllocationRatio));
  query->insert(pair<string, string>("OpenPermission", *request->openPermission));
  query->insert(pair<string, long>("OwnerId", *request->ownerId));
  query->insert(pair<string, string>("RegionId", *request->regionId));
  query->insert(pair<string, string>("ResourceOwnerAccount", *request->resourceOwnerAccount));
  query->insert(pair<string, long>("ResourceOwnerId", *request->resourceOwnerId));
  shared_ptr<Alibabacloud_OpenApi::OpenApiRequest> req = make_shared<Alibabacloud_OpenApi::OpenApiRequest>(map<string, boost::any>({
    {"query", boost::any(Alibabacloud_OpenApiUtil::Client::query(query))}
  }));
  shared_ptr<Alibabacloud_OpenApi::Params> params = make_shared<Alibabacloud_OpenApi::Params>(map<string, boost::any>({
    {"action", boost::any(string("ModifyDedicatedHostGroupAttribute"))},
    {"version", boost::any(string("2020-03-20"))},
    {"protocol", boost::any(string("HTTPS"))},
    {"pathname", boost::any(string("/"))},
    {"method", boost::any(string("POST"))},
    {"authType", boost::any(string("AK"))},
    {"style", boost::any(string("RPC"))},
    {"reqBodyType", boost::any(string("formData"))},
    {"bodyType", boost::any(string("json"))}
  }));
  return ModifyDedicatedHostGroupAttributeResponse(callApi(params, req, runtime));
}

ModifyDedicatedHostGroupAttributeResponse Alibabacloud_Cddc20200320::Client::modifyDedicatedHostGroupAttribute(shared_ptr<ModifyDedicatedHostGroupAttributeRequest> request) {
  shared_ptr<Darabonba_Util::RuntimeOptions> runtime = make_shared<Darabonba_Util::RuntimeOptions>();
  return modifyDedicatedHostGroupAttributeWithOptions(request, runtime);
}

ModifyDedicatedHostPasswordResponse Alibabacloud_Cddc20200320::Client::modifyDedicatedHostPasswordWithOptions(shared_ptr<ModifyDedicatedHostPasswordRequest> request, shared_ptr<Darabonba_Util::RuntimeOptions> runtime) {
  Darabonba_Util::Client::validateModel(request);
  shared_ptr<map<string, boost::any>> query = make_shared<map<string, boost::any>>(map<string, boost::any>());
  query->insert(pair<string, string>("DedicatedHostId", *request->dedicatedHostId));
  query->insert(pair<string, string>("NewPassword", *request->newPassword));
  query->insert(pair<string, long>("OwnerId", *request->ownerId));
  query->insert(pair<string, string>("RegionId", *request->regionId));
  query->insert(pair<string, string>("ResourceOwnerAccount", *request->resourceOwnerAccount));
  query->insert(pair<string, long>("ResourceOwnerId", *request->resourceOwnerId));
  shared_ptr<Alibabacloud_OpenApi::OpenApiRequest> req = make_shared<Alibabacloud_OpenApi::OpenApiRequest>(map<string, boost::any>({
    {"query", boost::any(Alibabacloud_OpenApiUtil::Client::query(query))}
  }));
  shared_ptr<Alibabacloud_OpenApi::Params> params = make_shared<Alibabacloud_OpenApi::Params>(map<string, boost::any>({
    {"action", boost::any(string("ModifyDedicatedHostPassword"))},
    {"version", boost::any(string("2020-03-20"))},
    {"protocol", boost::any(string("HTTPS"))},
    {"pathname", boost::any(string("/"))},
    {"method", boost::any(string("POST"))},
    {"authType", boost::any(string("AK"))},
    {"style", boost::any(string("RPC"))},
    {"reqBodyType", boost::any(string("formData"))},
    {"bodyType", boost::any(string("json"))}
  }));
  return ModifyDedicatedHostPasswordResponse(callApi(params, req, runtime));
}

ModifyDedicatedHostPasswordResponse Alibabacloud_Cddc20200320::Client::modifyDedicatedHostPassword(shared_ptr<ModifyDedicatedHostPasswordRequest> request) {
  shared_ptr<Darabonba_Util::RuntimeOptions> runtime = make_shared<Darabonba_Util::RuntimeOptions>();
  return modifyDedicatedHostPasswordWithOptions(request, runtime);
}

QueryHostBaseInfoByInstanceResponse Alibabacloud_Cddc20200320::Client::queryHostBaseInfoByInstanceWithOptions(shared_ptr<QueryHostBaseInfoByInstanceRequest> request, shared_ptr<Darabonba_Util::RuntimeOptions> runtime) {
  Darabonba_Util::Client::validateModel(request);
  shared_ptr<map<string, boost::any>> query = make_shared<map<string, boost::any>>(map<string, boost::any>());
  query->insert(pair<string, string>("DBInstanceId", *request->DBInstanceId));
  query->insert(pair<string, long>("OwnerId", *request->ownerId));
  query->insert(pair<string, string>("RegionId", *request->regionId));
  query->insert(pair<string, string>("ResourceOwnerAccount", *request->resourceOwnerAccount));
  query->insert(pair<string, long>("ResourceOwnerId", *request->resourceOwnerId));
  shared_ptr<Alibabacloud_OpenApi::OpenApiRequest> req = make_shared<Alibabacloud_OpenApi::OpenApiRequest>(map<string, boost::any>({
    {"query", boost::any(Alibabacloud_OpenApiUtil::Client::query(query))}
  }));
  shared_ptr<Alibabacloud_OpenApi::Params> params = make_shared<Alibabacloud_OpenApi::Params>(map<string, boost::any>({
    {"action", boost::any(string("QueryHostBaseInfoByInstance"))},
    {"version", boost::any(string("2020-03-20"))},
    {"protocol", boost::any(string("HTTPS"))},
    {"pathname", boost::any(string("/"))},
    {"method", boost::any(string("POST"))},
    {"authType", boost::any(string("AK"))},
    {"style", boost::any(string("RPC"))},
    {"reqBodyType", boost::any(string("formData"))},
    {"bodyType", boost::any(string("json"))}
  }));
  return QueryHostBaseInfoByInstanceResponse(callApi(params, req, runtime));
}

QueryHostBaseInfoByInstanceResponse Alibabacloud_Cddc20200320::Client::queryHostBaseInfoByInstance(shared_ptr<QueryHostBaseInfoByInstanceRequest> request) {
  shared_ptr<Darabonba_Util::RuntimeOptions> runtime = make_shared<Darabonba_Util::RuntimeOptions>();
  return queryHostBaseInfoByInstanceWithOptions(request, runtime);
}

QueryHostInstanceConsoleInfoResponse Alibabacloud_Cddc20200320::Client::queryHostInstanceConsoleInfoWithOptions(shared_ptr<QueryHostInstanceConsoleInfoRequest> request, shared_ptr<Darabonba_Util::RuntimeOptions> runtime) {
  Darabonba_Util::Client::validateModel(request);
  shared_ptr<map<string, boost::any>> query = make_shared<map<string, boost::any>>(map<string, boost::any>());
  query->insert(pair<string, string>("DedicatedHostId", *request->dedicatedHostId));
  query->insert(pair<string, long>("OwnerId", *request->ownerId));
  query->insert(pair<string, string>("RegionId", *request->regionId));
  query->insert(pair<string, string>("ResourceOwnerAccount", *request->resourceOwnerAccount));
  query->insert(pair<string, long>("ResourceOwnerId", *request->resourceOwnerId));
  shared_ptr<Alibabacloud_OpenApi::OpenApiRequest> req = make_shared<Alibabacloud_OpenApi::OpenApiRequest>(map<string, boost::any>({
    {"query", boost::any(Alibabacloud_OpenApiUtil::Client::query(query))}
  }));
  shared_ptr<Alibabacloud_OpenApi::Params> params = make_shared<Alibabacloud_OpenApi::Params>(map<string, boost::any>({
    {"action", boost::any(string("QueryHostInstanceConsoleInfo"))},
    {"version", boost::any(string("2020-03-20"))},
    {"protocol", boost::any(string("HTTPS"))},
    {"pathname", boost::any(string("/"))},
    {"method", boost::any(string("POST"))},
    {"authType", boost::any(string("AK"))},
    {"style", boost::any(string("RPC"))},
    {"reqBodyType", boost::any(string("formData"))},
    {"bodyType", boost::any(string("json"))}
  }));
  return QueryHostInstanceConsoleInfoResponse(callApi(params, req, runtime));
}

QueryHostInstanceConsoleInfoResponse Alibabacloud_Cddc20200320::Client::queryHostInstanceConsoleInfo(shared_ptr<QueryHostInstanceConsoleInfoRequest> request) {
  shared_ptr<Darabonba_Util::RuntimeOptions> runtime = make_shared<Darabonba_Util::RuntimeOptions>();
  return queryHostInstanceConsoleInfoWithOptions(request, runtime);
}

ReplaceDedicatedHostResponse Alibabacloud_Cddc20200320::Client::replaceDedicatedHostWithOptions(shared_ptr<ReplaceDedicatedHostRequest> request, shared_ptr<Darabonba_Util::RuntimeOptions> runtime) {
  Darabonba_Util::Client::validateModel(request);
  shared_ptr<map<string, boost::any>> query = make_shared<map<string, boost::any>>(map<string, boost::any>());
  query->insert(pair<string, string>("DedicatedHostId", *request->dedicatedHostId));
  query->insert(pair<string, string>("FailoverMode", *request->failoverMode));
  query->insert(pair<string, long>("OwnerId", *request->ownerId));
  query->insert(pair<string, string>("RegionId", *request->regionId));
  query->insert(pair<string, string>("ResourceOwnerAccount", *request->resourceOwnerAccount));
  query->insert(pair<string, long>("ResourceOwnerId", *request->resourceOwnerId));
  shared_ptr<Alibabacloud_OpenApi::OpenApiRequest> req = make_shared<Alibabacloud_OpenApi::OpenApiRequest>(map<string, boost::any>({
    {"query", boost::any(Alibabacloud_OpenApiUtil::Client::query(query))}
  }));
  shared_ptr<Alibabacloud_OpenApi::Params> params = make_shared<Alibabacloud_OpenApi::Params>(map<string, boost::any>({
    {"action", boost::any(string("ReplaceDedicatedHost"))},
    {"version", boost::any(string("2020-03-20"))},
    {"protocol", boost::any(string("HTTPS"))},
    {"pathname", boost::any(string("/"))},
    {"method", boost::any(string("POST"))},
    {"authType", boost::any(string("AK"))},
    {"style", boost::any(string("RPC"))},
    {"reqBodyType", boost::any(string("formData"))},
    {"bodyType", boost::any(string("json"))}
  }));
  return ReplaceDedicatedHostResponse(callApi(params, req, runtime));
}

ReplaceDedicatedHostResponse Alibabacloud_Cddc20200320::Client::replaceDedicatedHost(shared_ptr<ReplaceDedicatedHostRequest> request) {
  shared_ptr<Darabonba_Util::RuntimeOptions> runtime = make_shared<Darabonba_Util::RuntimeOptions>();
  return replaceDedicatedHostWithOptions(request, runtime);
}

RestartDedicatedHostResponse Alibabacloud_Cddc20200320::Client::restartDedicatedHostWithOptions(shared_ptr<RestartDedicatedHostRequest> request, shared_ptr<Darabonba_Util::RuntimeOptions> runtime) {
  Darabonba_Util::Client::validateModel(request);
  shared_ptr<map<string, boost::any>> query = make_shared<map<string, boost::any>>(map<string, boost::any>());
  query->insert(pair<string, string>("DedicatedHostId", *request->dedicatedHostId));
  query->insert(pair<string, string>("FailoverMode", *request->failoverMode));
  query->insert(pair<string, bool>("ForceStop", *request->forceStop));
  query->insert(pair<string, long>("OwnerId", *request->ownerId));
  query->insert(pair<string, string>("RegionId", *request->regionId));
  query->insert(pair<string, string>("ResourceOwnerAccount", *request->resourceOwnerAccount));
  query->insert(pair<string, long>("ResourceOwnerId", *request->resourceOwnerId));
  shared_ptr<Alibabacloud_OpenApi::OpenApiRequest> req = make_shared<Alibabacloud_OpenApi::OpenApiRequest>(map<string, boost::any>({
    {"query", boost::any(Alibabacloud_OpenApiUtil::Client::query(query))}
  }));
  shared_ptr<Alibabacloud_OpenApi::Params> params = make_shared<Alibabacloud_OpenApi::Params>(map<string, boost::any>({
    {"action", boost::any(string("RestartDedicatedHost"))},
    {"version", boost::any(string("2020-03-20"))},
    {"protocol", boost::any(string("HTTPS"))},
    {"pathname", boost::any(string("/"))},
    {"method", boost::any(string("POST"))},
    {"authType", boost::any(string("AK"))},
    {"style", boost::any(string("RPC"))},
    {"reqBodyType", boost::any(string("formData"))},
    {"bodyType", boost::any(string("json"))}
  }));
  return RestartDedicatedHostResponse(callApi(params, req, runtime));
}

RestartDedicatedHostResponse Alibabacloud_Cddc20200320::Client::restartDedicatedHost(shared_ptr<RestartDedicatedHostRequest> request) {
  shared_ptr<Darabonba_Util::RuntimeOptions> runtime = make_shared<Darabonba_Util::RuntimeOptions>();
  return restartDedicatedHostWithOptions(request, runtime);
}

TagResourcesResponse Alibabacloud_Cddc20200320::Client::tagResourcesWithOptions(shared_ptr<TagResourcesRequest> request, shared_ptr<Darabonba_Util::RuntimeOptions> runtime) {
  Darabonba_Util::Client::validateModel(request);
  shared_ptr<map<string, boost::any>> query = make_shared<map<string, boost::any>>(map<string, boost::any>());
  query->insert(pair<string, long>("OwnerId", *request->ownerId));
  query->insert(pair<string, string>("RegionId", *request->regionId));
  query->insert(pair<string, vector<string>>("ResourceId", *request->resourceId));
  query->insert(pair<string, string>("ResourceOwnerAccount", *request->resourceOwnerAccount));
  query->insert(pair<string, long>("ResourceOwnerId", *request->resourceOwnerId));
  query->insert(pair<string, string>("ResourceType", *request->resourceType));
  query->insert(pair<string, vector<TagResourcesRequestTag>>("Tag", *request->tag));
  shared_ptr<Alibabacloud_OpenApi::OpenApiRequest> req = make_shared<Alibabacloud_OpenApi::OpenApiRequest>(map<string, boost::any>({
    {"query", boost::any(Alibabacloud_OpenApiUtil::Client::query(query))}
  }));
  shared_ptr<Alibabacloud_OpenApi::Params> params = make_shared<Alibabacloud_OpenApi::Params>(map<string, boost::any>({
    {"action", boost::any(string("TagResources"))},
    {"version", boost::any(string("2020-03-20"))},
    {"protocol", boost::any(string("HTTPS"))},
    {"pathname", boost::any(string("/"))},
    {"method", boost::any(string("POST"))},
    {"authType", boost::any(string("AK"))},
    {"style", boost::any(string("RPC"))},
    {"reqBodyType", boost::any(string("formData"))},
    {"bodyType", boost::any(string("json"))}
  }));
  return TagResourcesResponse(callApi(params, req, runtime));
}

TagResourcesResponse Alibabacloud_Cddc20200320::Client::tagResources(shared_ptr<TagResourcesRequest> request) {
  shared_ptr<Darabonba_Util::RuntimeOptions> runtime = make_shared<Darabonba_Util::RuntimeOptions>();
  return tagResourcesWithOptions(request, runtime);
}

UntagResourcesResponse Alibabacloud_Cddc20200320::Client::untagResourcesWithOptions(shared_ptr<UntagResourcesRequest> request, shared_ptr<Darabonba_Util::RuntimeOptions> runtime) {
  Darabonba_Util::Client::validateModel(request);
  shared_ptr<map<string, boost::any>> query = make_shared<map<string, boost::any>>(map<string, boost::any>());
  query->insert(pair<string, bool>("All", *request->all));
  query->insert(pair<string, long>("OwnerId", *request->ownerId));
  query->insert(pair<string, string>("RegionId", *request->regionId));
  query->insert(pair<string, vector<string>>("ResourceId", *request->resourceId));
  query->insert(pair<string, string>("ResourceOwnerAccount", *request->resourceOwnerAccount));
  query->insert(pair<string, long>("ResourceOwnerId", *request->resourceOwnerId));
  query->insert(pair<string, string>("ResourceType", *request->resourceType));
  query->insert(pair<string, vector<string>>("TagKey", *request->tagKey));
  shared_ptr<Alibabacloud_OpenApi::OpenApiRequest> req = make_shared<Alibabacloud_OpenApi::OpenApiRequest>(map<string, boost::any>({
    {"query", boost::any(Alibabacloud_OpenApiUtil::Client::query(query))}
  }));
  shared_ptr<Alibabacloud_OpenApi::Params> params = make_shared<Alibabacloud_OpenApi::Params>(map<string, boost::any>({
    {"action", boost::any(string("UntagResources"))},
    {"version", boost::any(string("2020-03-20"))},
    {"protocol", boost::any(string("HTTPS"))},
    {"pathname", boost::any(string("/"))},
    {"method", boost::any(string("POST"))},
    {"authType", boost::any(string("AK"))},
    {"style", boost::any(string("RPC"))},
    {"reqBodyType", boost::any(string("formData"))},
    {"bodyType", boost::any(string("json"))}
  }));
  return UntagResourcesResponse(callApi(params, req, runtime));
}

UntagResourcesResponse Alibabacloud_Cddc20200320::Client::untagResources(shared_ptr<UntagResourcesRequest> request) {
  shared_ptr<Darabonba_Util::RuntimeOptions> runtime = make_shared<Darabonba_Util::RuntimeOptions>();
  return untagResourcesWithOptions(request, runtime);
}

max_stars_repo_name: aliyun/alibabacloud-cpp-sdk

max_issues_repo_name: aliyun/alibabacloud-cpp-sdk

max_forks_repo_name: aliyun/alibabacloud-cpp-sdk


text:
/**************************************************************************
 * Copyright (c) 2019 Chimney Xu. All Rights Reserve.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *    http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 **************************************************************************/
/* *************************************************************************
   * File Name     : PCLRansacGeometryChecker.hpp
   * Author        : smallchimney
   * Author Email  : smallchimney@foxmail.com
   * Created Time  : 2019-12-12 13:18:53
   * Last Modified : smallchimney
   * Modified Time : 2019-12-27 17:39:39
************************************************************************* */
#ifndef __ROCKAUTO_TDLD_PC_PCL_RANSAC_GEOMETRY_CHECKER_HPP__
#define __ROCKAUTO_TDLD_PC_PCL_RANSAC_GEOMETRY_CHECKER_HPP__

#include "traits.h"
#include <TDLoopDetector/Exception.h>
#include <TDLoopDetector/GeometryChecker.h>
#include <TDBoW/TemplatedDescriptor.hpp>

#include <pcl/recognition/cg/geometric_consistency.h>
#include <boost/make_shared.hpp>

namespace TDLoopDetector {
namespace pc {

template <typename PointT = pcl::PointXYZ>
class PCLRansacGeometryChecker : public GeometryChecker<traits::pcl_type<PointT>::DIM> {
public:
    // The dim of the point type
    static constexpr auto DIM = traits::pcl_type<PointT>::DIM;
    // PCL types define
    typedef pcl::PointCloud<PointT> PointCloud;
    typedef typename PointCloud::Ptr PointCloudPtr;
    typedef pcl::GeometricConsistencyGrouping<PointT, PointT> Checker;
    typedef std::vector<pcl::Correspondences> CorrespondencesArray;
    // Key point types define
    typedef typename GeometryChecker<DIM>::KeyPoint      KeyPoint;
    typedef typename GeometryChecker<DIM>::KeyPoints     KeyPoints;
    typedef typename GeometryChecker<DIM>::KeyPointArray KeyPointArray;
    typedef typename GeometryChecker<DIM>::PointPairsGeomChecker PointPairsGeomChecker;

    /**
     * @brief  Build instance of RANSAC to do the geometry checking.
     * @author smallchimney
     * @param  _Resolution The minimum limit of the instance size (points count)
     * @param  _Threshold  Consensus set resolution.
     */
    PCLRansacGeometryChecker(double _Resolution, int _Threshold, bool _SceneModel = false);

    /**
     * @brief  Current ISO C++ standard don't supported implement this in base class
     * @author smallchimney
     * @return The suitable `PointPairsGeomChecker` callback attached with
     *         current instance
     */
    PointPairsGeomChecker checker() noexcept override {
        return std::bind(&PCLRansacGeometryChecker<PointT>::doGeometryCheck,
                this, std::placeholders::_1, std::placeholders::_2,
                std::placeholders::_3, std::placeholders::_4);
    }

    /**
     * @brief  Geometry checking method based on PCL implement, using RANSAC
     *         indeed.
     * @author smallchimney
     * @param  _Matches          The given points pairs.
     * @param  _Transform (out)  Only if the there are geometric consistency
     *                           between the two scenes, s.t. return {@code true}
     *                           this field will be filled the transform between
     *                           the two scenes. (from model to scene)
     * @param  _HistoryKp        The key points in history scene
     * @param  _QueryKp          The key points in current scene
     * @return                   Whether there are geometric consistency between
     *                           the two scenes
     */
    bool doGeometryCheck(const MatchPairArray& _Matches,
                         Transform& _Transform,
                         const KeyPointArray& _HistoryKp,
                         const KeyPointArray& _QueryKp) override;

    /**
     * @brief  Clear the previous match data
     * @author smallchimney
     */
    void clear() {
        m_aFoundedTf.clear();
        m_aFoundedTf.shrink_to_fit();
        m_aCorrespondences.clear();
        m_aCorrespondences.shrink_to_fit();
    }

    /**
     * @brief  Get the size of last check's result.
     * @author smallchimney
     * @return The number of possible instance (query image) founded in the
     *         scene (history image)
     */
    size_t size() const noexcept { return m_aFoundedTf.size(); }

    /**
     * @brief  Whether there are no any matched instance in the scene.
     * @author smallchimney
     * @return No any match in the two clouds, s.t. no geometric consistency.
     */
    bool empty() const noexcept { return size() == 0; }

    /**
     * @brief  Set the consensus set resolution. This should be in metric units.
     * @author smallchimney
     * @param  _Resolution  Consensus set resolution.
     * @return              The instance itself
     */
    PCLRansacGeometryChecker& setRansacResolution(const double _Resolution) {
        m_cChecker.setGCSize(_Resolution);
        return *this;
    }

    /**
     * @brief  Set the minimum limit of the instance, stands for ransac
     *         must find more points. This value should be set according
     *         to the density of pointcloud.
     * @author smallchimney
     * @param  _Threshold   The minimum limit of the instance size (points
     *                      count)
     * @return              The instance itself
     */
    PCLRansacGeometryChecker& setRansacThreshold(int _Threshold) {
        m_cChecker.setGCThreshold(_Threshold);
        return *this;
    }

    /**
     * @brief  Set the scene points, only needed in scene-model mode.
     * @author smallchimney
     * @param  _Cloud  Descriptors for each point in the scene.
     * @return         The instance itself
     */
    PCLRansacGeometryChecker& setSceneCloud(const PointCloudPtr& _Cloud) noexcept {
        m_pSceneCloud = _Cloud;
        return *this;
    }

    /**
     * @brief  Set the scene points, only needed in scene-model mode.
     * @author smallchimney
     * @param  _Cloud  Descriptors for each point in the scene.
     * @return         The instance itself
     */
    PCLRansacGeometryChecker& setSceneCloud(const KeyPointArray& _Cloud) noexcept {
        m_pSceneCloud = _transform(_Cloud);
        return *this;
    }

    /**
     * @brief  Try to get the last check's transforms' matrix.
     * @author smallchimney
     * @return Return a constant reference of last check's transforms' matrix
     */
    const Transforms& getTransforms() const noexcept { return m_aFoundedTf; }

    /**
     * @brief  Try to get the last check's transforms' correspondences.
     * @author smallchimney
     * @return Return a constant reference of last check's transforms' correspondences
     */
    const CorrespondencesArray& getCorrespondences() const noexcept {
        return m_aCorrespondences;
    }

protected:
    /** @brief Store the last geometric consistency transform matrix */
    Transforms m_aFoundedTf;

    /** @brief Store the last geometric consistency correspondences relation */
    CorrespondencesArray m_aCorrespondences;

    /**
     * @brief Mode designed for RANSAC, will using scene-model check and generate
     *        a lot of false-positive matches. In this mode, each point in the scene
     *        will calculate the shortest distance on descriptor to model's key point.
     */
    const bool m_bSceneModelMode;

    /** @brief Full scene clouds, required when scene-model mode */
    PointCloudPtr m_pSceneCloud;

    /**
     * @brief  Transform key points into cloud, this method will not check the
     *         infinite position, because the indices will get error after filter,
     *         so please make sure the input key points are finite.
     * @author smallchimney
     * @param  _Keys  Inputted key points position (must be finite)
     * @return        PCL format point cloud pointer
     */
    PointCloudPtr _transform(const KeyPointArray& _Keys) const noexcept;

private:
    /** @brief PCL geometric consistency checker based on RANSAC */
    Checker m_cChecker;

};

/* ********************************************************************************
 *                        CONSTRUCTION && INITIALIZATION                          *
 ******************************************************************************** */

template <typename PointT>
PCLRansacGeometryChecker<PointT>::PCLRansacGeometryChecker(
        const double _Resolution, const int _Threshold, const bool _SceneModel)
        : m_bSceneModelMode(_SceneModel), m_cChecker() {
    setRansacResolution(_Resolution).setRansacThreshold(_Threshold);
}

/* ********************************************************************************
 *                              FUNCTIONAL METHODS                                *
 ******************************************************************************** */

template <typename PointT>
bool PCLRansacGeometryChecker<PointT>::doGeometryCheck(
        const MatchPairArray& _Matches, Transform& _Transform,
        const KeyPointArray& _HistoryKp, const KeyPointArray& _QueryKp) {
    PointCloudPtr queryClouds;
    if(m_bSceneModelMode) {
        if(m_pSceneCloud == nullptr) {
            throw NotInitailizedException(TDBOW_LOG("The scene cloud is required in "
                    "scene-model mode, please call `setScene()` before `detectLoop()`"));
        }
        queryClouds = m_pSceneCloud;
    } else {
        queryClouds = _transform(_QueryKp);
    }
    auto correspondences = boost::make_shared<pcl::Correspondences>();
    // Transform two clouds
    auto historyPoints = _transform(_HistoryKp);
    for(const auto& pair : _Matches) {
        // model, scene, distance
        correspondences -> emplace_back(
                std::get<0>(pair), std::get<1>(pair), std::get<2>(pair));
    }
    m_cChecker.setInputCloud(historyPoints);
    m_cChecker.setSceneCloud(queryClouds);
    m_cChecker.setModelSceneCorrespondences(correspondences);
    clear();
    if(!m_cChecker.recognize(m_aFoundedTf, m_aCorrespondences))return false;
    m_aCorrespondences.emplace_back(*correspondences);
    m_pSceneCloud.reset();
    if(!empty()) {
        _Transform = m_aFoundedTf[0];
        return true;
    }
    return false;
}

/* ********************************************************************************
 *                                 INNER METHODS                                  *
 ******************************************************************************** */

template <typename PointT>
typename PCLRansacGeometryChecker<PointT>::PointCloudPtr
PCLRansacGeometryChecker<PointT>::_transform(const KeyPointArray& _Keys) const noexcept {
    auto cloud = boost::make_shared<PointCloud>();
    if(_Keys.empty())return cloud;
    cloud -> resize(_Keys.size());
    if(sizeof(cloud -> at(0)) == sizeof(_Keys[0])) {
        memcpy(cloud -> at(0).data, _Keys[0].data(),
               sizeof(_Keys[0]) * _Keys.size());
    } else {
        for(size_t i = 0; i < _Keys.size(); i++) {
            memcpy(cloud -> at(i).data, _Keys[i].data(), sizeof(float) * DIM);
        }
    }
    return cloud;
}

}}  // namespace TDLoopDetector::pc

#endif //__ROCKAUTO_TDLD_PC_PCL_RANSAC_GEOMETRY_CHECKER_HPP__

ext: hpp

max_stars_repo_name: smallchimney/TDLoopDetector

max_issues_repo_name: smallchimney/TDLoopDetector

max_forks_repo_name: smallchimney/TDLoopDetector


text:
/*
 * event_communicator.hpp
 *
 *  Copyright (c) 2015 Masatoshi Hanai
 *
 *  This software is released under MIT License.
 *  See LICENSE.
 *
 */
#ifndef SCALESIM_COM_EVENT_COMMUNICATOR_HPP_
#define SCALESIM_COM_EVENT_COMMUNICATOR_HPP_

#include <boost/bind.hpp>
#include <boost/shared_ptr.hpp>
#include <boost/thread.hpp>
#include "scalesim/com/mpi/mpi_runner.hpp"
#include "scalesim/logical_process.hpp"
#include "scalesim/util.hpp"

namespace scalesim {

template <class App>
class event_com {
 private:
  event_com(const event_com&);
  void operator=(const event_com&);
 public:
  event_com(): lp_manager_(NULL){};
  virtual ~event_com(){};
 private:
  lp_mngr<App>* lp_manager_;
  int rank_; int rank_size_;
 public:
  void init(lp_mngr<App>* lp_manager);
  void start();
  void stop();
  void finish();

  void send_event(const ev_ptr<App>& event);
  void receive_event(const ev_ptr<App>& event);

  void barrier(bool& wait);

  template<class Obj>
  void shuffle(bool& wait,
               std::vector<boost::shared_ptr<const Obj> >& ret,
               std::vector<boost::shared_ptr<const Obj> >& events,
               const parti_ptr parti);

  void reduce_sum(bool& wait, long& ret, const long val);

  int rank() const ;
  int rank_size() const;
  void reset();
};

template<class App>
void event_com<App>::init(lp_mngr<App>* lp_manager) {
  lp_manager_ = lp_manager;
  boost::function<void(const ev_ptr<App>&)> call_back_f
     = boost::bind(&event_com<App>::receive_event, this, _1);
  mpi_thr<App>::instance()->init(call_back_f);
  rank_ = mpi_thr<App>::instance()->mpi_rank();
  rank_size_ = mpi_thr<App>::instance()->mpi_size();
  bool wait_barrier_ = true;
  mpi_thr<App>::instance()->barrier(wait_barrier_);
  while(wait_barrier_);
};

template<class App>
void event_com<App>::start() {
  mpi_thr<App>::instance()->start();
}

template<class App>
void event_com<App>::stop() {
  mpi_thr<App>::instance()->stop();
}

template<class App>
void event_com<App>::finish() {
  mpi_thr<App>::instance()->finish();
  mpi_thr<App>::del_instance();
};

template<class App>
void event_com<App>::barrier(bool& wait_barrier)
  { mpi_thr<App>::instance()->barrier(wait_barrier); };

template<class App>
void event_com<App>::send_event(const ev_ptr<App>& event) {
  long destination_rank = (*lp_manager_->partition())[event->destination()];
  if (mpi_thr<App>::instance() == NULL ||
      destination_rank == mpi_thr<App>::instance()->mpi_rank()) {
    /* inner communication */
    lp<App>* lp_;
    lp_manager_->get_lp(lp_, event->destination());
    lp_->buffer(event);
  } else {
    /* rank to rank communication */
    mpi_thr<App>::instance()->buffer_send_message(destination_rank, event);
  }
};

template<class App>
void event_com<App>::receive_event(const ev_ptr<App>& event) {
  lp<App>* lp_;
  lp_manager_->get_lp(lp_, event->destination());
  lp_->buffer(event);
};

template<class App>
template<class Obj>
void event_com<App>::shuffle(bool& wait,
                             std::vector<boost::shared_ptr<const Obj> >& ret,
                             std::vector<boost::shared_ptr<const Obj> >& objs,
                             parti_ptr parti) {
  mpi_thr<App>::instance()->template shuffle<Obj>(wait, ret, objs, parti);
};

template<class App>
void event_com<App>::reduce_sum(bool& wait, long& ret, long val)
  { mpi_thr<App>::instance()->reduce_sum(wait, ret, val); };

template<class App>
int event_com<App>::rank() const { return rank_; };

template<class App>
int event_com<App>::rank_size() const { return rank_size_; };

template<class App>
void event_com<App>::reset() { mpi_thr<App>::instance()->reset(); };

} /* namespae scalesim */

#endif /* SCALESIM_COM_EVENT_COMMUNICATOR_HPP_ */

max_stars_repo_name: asia-lab-sustech/ScaleSim

max_issues_repo_name: asia-lab-sustech/ScaleSim

max_forks_repo_name: asia-lab-sustech/ScaleSim


text:
/*
  MIT License

  Copyright (c) 2018 Nicolai Trandafil

  Permission is hereby granted, free of charge, to any person obtaining a copy
  of this software and associated documentation files (the "Software"), to deal
  in the Software without restriction, including without limitation the rights
  to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  copies of the Software, and to permit persons to whom the Software is
  furnished to do so, subject to the following conditions:

  The above copyright notice and this permission notice shall be included in all
  copies or substantial portions of the Software.

  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
  SOFTWARE.
*/

#include "matchers.hpp"

#include <yenxo/comparison_traits.hpp>
#include <yenxo/ostream_traits.hpp>
#include <yenxo/string_conversion.hpp>
#include <yenxo/value_tag.hpp>
#include <yenxo/variant.hpp>
#include <yenxo/variant_traits.hpp>

#include <catch2/catch.hpp>

#include <boost/hana.hpp>

namespace hana = boost::hana;

using namespace yenxo;

using namespace hana::literals;
using namespace std::literals;

namespace {

struct X {
    static Variant toVariant(X const&);
    static X fromVariant(Variant const&);
};
static_assert(hasFromVariant(boost::hana::type_c<X>));
static_assert(hasToVariant(boost::hana::type_c<X>));

struct Hobby
        : trait::Var<Hobby>
        , trait::UpdateFromVar<Hobby>
        , trait::EqualityComparison<Hobby> {
    Hobby()
            : id(0) {
    }

    Hobby(int id, std::string const& description)
            : id(id)
            , description(description) {
    }

    int id;
    std::string description;
};

struct OptPerson : trait::EqualityComparison<OptPerson> {
    OptPerson() = default;

    OptPerson(std::string const& name, int age, Hobby const& hobby)
            : name(name)
            , age(age)
            , hobby(hobby) {
    }

    std::optional<std::string> name;
    std::optional<int> age;
    std::optional<Hobby> hobby;
};

struct Person
        : trait::Var<Person>
        , trait::UpdateFromVar<Person>
        , trait::UpdateFromOpt<Person, OptPerson>
        , trait::EqualityComparison<Person> {
    Person()
            : age(0) {
    }

    Person(std::string const& name, int age, Hobby const& hobby)
            : name(name)
            , age(age)
            , hobby(hobby) {
    }

    std::string name;
    int age;
    Hobby hobby;
};

struct AllowAdditionalPropertiesPolicy : trait::VarPolicy {
    static auto constexpr allow_additional_properties = false;
};

struct PersonNoAdditionalProperties
        : trait::UpdateFromVar<PersonNoAdditionalProperties,
                               AllowAdditionalPropertiesPolicy>
        , trait::EqualityComparison<PersonNoAdditionalProperties> {
    PersonNoAdditionalProperties() = default;
    PersonNoAdditionalProperties(std::string const& name, int age, Hobby const& hobby)
            : name(name)
            , age(age)
            , hobby(hobby) {
    }
    BOOST_HANA_DEFINE_STRUCT(PersonNoAdditionalProperties,
                             (std::string, name),
                             (int, age),
                             (Hobby, hobby));
};

struct PersonWithVector
        : trait::Var<PersonWithVector>
        , trait::EqualityComparison<PersonWithVector> {
    PersonWithVector() = default;
    PersonWithVector(std::string const& name, std::vector<Hobby> const& hobbies)
            : name(name)
            , hobbies(hobbies) {
    }

    std::string name;
    std::vector<Hobby> hobbies;
};

struct Dict
        : trait::Var<Dict>
        , trait::EqualityComparison<Dict> {
    Dict() = default;

    Dict(int x, std::unordered_map<std::string, int> const& map)
            : x(x)
            , map(map) {
    }

    int x;
    std::unordered_map<std::string, int> map;
};

} // namespace

BOOST_HANA_ADAPT_STRUCT(Hobby, id, description);
BOOST_HANA_ADAPT_STRUCT(OptPerson, name, age, hobby);
BOOST_HANA_ADAPT_STRUCT(Person, name, age, hobby);
BOOST_HANA_ADAPT_STRUCT(PersonWithVector, name, hobbies);
BOOST_HANA_ADAPT_STRUCT(Dict, x, map);

TEST_CASE("detail::toVariant", "[variant_trait_helpers]") {
    auto const x = toVariant(5);
    REQUIRE(x == Variant(5));
    REQUIRE(5 == fromVariant<int>(Variant(5)));

    auto const x1 = toVariant("Hello");
    REQUIRE(x1 == Variant("Hello"));
    REQUIRE("Hello" == fromVariant<std::string>(Variant("Hello")));

    struct X {
        static Variant toVariant(X const& x) {
            return Variant(x.m);
        }
        static X fromVariant(Variant const& x) {
            return {x.int32()};
        }
        int m{5};
    };

    auto const x2 = toVariant(X());
    REQUIRE(x2 == Variant(5));
    REQUIRE(6 == fromVariant<X>(Variant(6)).m);

    SECTION("quick struct") {
        Variant::Map const m{std::make_pair("a", Variant(1))};
        auto hm = hana::make_map(hana::make_pair("a"_s, 1));
        auto const hm_v = toVariant(hm);
        REQUIRE(hm_v == Variant(m));
        REQUIRE(boost::hana::equal(fromVariant<decltype(hm)>(Variant(m)), hm));
        auto hm2 = hana::make_map(hana::make_pair("b"_s, 2));
        REQUIRE_THROWS_WITH(fromVariant<decltype(hm2)>(Variant(m)), "b is required");
    }

    SECTION("integral constant") {
        Variant ok(2);
        Variant not_ok(3);
        std::integral_constant<int, 2> c;
        REQUIRE(fromVariant<decltype(c)>(ok) == c);
        REQUIRE_THROWS_AS(fromVariant<decltype(c)>(not_ok), VariantBadType);
        REQUIRE(toVariant(c) == Variant(2));
    }
}

TEST_CASE("Check trait::Var and trait::UpdateFromVar", "[variant_traits]") {
    SECTION("optional") {
        struct Opt
                : trait::Var<Opt>
                , trait::EqualityComparison<Opt> {
            Opt() = default;
            Opt(int x)
                    : x(x) {
            }

            BOOST_HANA_DEFINE_STRUCT(Opt, (std::optional<int>, x));
        };

        Variant const expected(VariantMap{{"x", Variant(1)}});
        REQUIRE(Opt(1) == fromVariant<Opt>(expected));
    }

    Variant::Map const hobby_var{{"id", Variant(1)}, {"description", Variant("Hack")}};

    Variant::Map person_var{{"name", Variant("Alecu")},
                            {"age", Variant(25)},
                            {"hobby", Variant(hobby_var)}};

    Hobby const hobby{1, std::string("Hack")};

    Person person{"Alecu", 25, hobby};

    SECTION("Check fromVariant") {
        REQUIRE(person == Person::fromVariant(Variant(person_var)));
    }

    SECTION("Check toVariant") {
        REQUIRE(Person::toVariant(person) == Variant(person_var));
    }

    SECTION("Check updateVar") {
        Variant::Map person_var{{"age", Variant(26)}};

        person.updateVar(Variant(person_var));

        Person const person_updated{"Alecu", 26, hobby};

        REQUIRE(person_updated == person);

        person_var["no"] = Variant(1);
        REQUIRE_NOTHROW(person.updateVar(Variant(person_var)));
    }

    SECTION("Check updateVar with allow_additional_properties=false") {
        PersonNoAdditionalProperties person{"Name", 25, hobby};
        PersonNoAdditionalProperties const person_updated{"Name", 26, hobby};
        Variant::Map person_var{{"age", Variant(26)}};
        person.updateVar(Variant(person_var));
        REQUIRE(person_updated == person);
        person_var["no"] = Variant(1);
        REQUIRE_THROWS_WITH(person.updateVar(Variant(person_var)), "'no' is unknown");
    }

    SECTION("Check updateVar with nested struct") {
        struct Parent
                : trait::UpdateFromVar<Parent>
                , trait::EqualityComparison<Parent> {
            Parent()
                    : name("a")
                    , age(30) {
            }
            BOOST_HANA_DEFINE_STRUCT(Parent, (std::string, name), (int, age));
        };

        struct Person
                : trait::UpdateFromVar<Person>
                , trait::EqualityComparison<Person> {
            Person()
                    : age(9) {
            }
            BOOST_HANA_DEFINE_STRUCT(Person, (int, age), (Parent, parent));
        };

        auto const var = Variant::fromJson(R"(
            {
                "age": 10,
                "parent": {
                    "name": "b"
                }
            })");

        Person person;
        person.parent.age = 99;

        Person person_expected;
        person_expected.parent.age = 99;
        person_expected.age = 10;
        person_expected.parent.name = "b";

        person.updateVar(Variant(var));
        REQUIRE(person == person_expected);
    }

    SECTION("Check updateOpt") {
        OptPerson opt;
        opt.age = 27;

        person.updateOpt(opt);

        Person const person_updated{"Alecu", 27, hobby};

        REQUIRE(person_updated == person);
    }

    SECTION("Check no field") {
        person_var.erase("name");
        REQUIRE_THROWS_AS(Person::fromVariant(Variant(person_var)), std::logic_error);
    }

    Hobby hobby2{2, "Barista"};

    Variant const hobby2_var{
            Variant::Map{{"id", Variant(2)}, {"description", Variant("Barista")}}};

    PersonWithVector const person_ex{"P", std::vector<Hobby>{hobby, hobby2}};

    Variant person_ex_var{Variant::Map{
            std::make_pair("name", Variant("P")),
            std::make_pair("hobbies",
                           Variant(Variant::Vec{Variant(hobby_var), hobby2_var}))}};

    SECTION("Check struct with vector") {
        REQUIRE(person_ex == PersonWithVector::fromVariant(person_ex_var));
        REQUIRE(person_ex_var == PersonWithVector::toVariant(person_ex));
    }

    SECTION("Check dict") {
        Dict const expected{5, {{"1", 1}, {"2", 2}}};

        Variant const tmp{
                Variant::Map{{"x", Variant(5)},
                             {"map", Variant({{"1", Variant(1)}, {"2", Variant(2)}})}}};

        REQUIRE(expected == Dict::fromVariant(tmp));
        REQUIRE(tmp == Dict::toVariant(expected));
    }

    SECTION("rename") {
        struct Rename
                : trait::Var<Rename>
                , trait::EqualityComparison<Rename> {
            Rename() = default;
            Rename(int x)
                    : x(x) {
            }
            constexpr static auto names() {
                return hana::make_map(hana::make_pair("x"_s, "y"));
            }
            BOOST_HANA_DEFINE_STRUCT(Rename, (int, x));
        };

        Variant expected(VariantMap{{"y", Variant(2)}});
        Variant wrong(VariantMap{{"z", Variant(2)}});
        REQUIRE(fromVariant<Rename>(expected) == Rename(2));
        REQUIRE(toVariant(Rename(2)) == expected);
        REQUIRE_THROWS_AS(fromVariant<Rename>(wrong), std::logic_error);
        REQUIRE_THROWS_WITH(fromVariant<Rename>(wrong), "'y' is required");
    }
}

namespace {

struct PersonD
        : trait::Var<PersonD>
        , trait::EqualityComparison<PersonD> {
    PersonD() {
    }

    PersonD(std::string const& name, int age, Hobby const& hobby)
            : name(name)
            , age(age)
            , hobby(hobby) {
    }

    PersonD(std::string const& name, Hobby const& hobby)
            : name(name)
            , hobby(hobby) {
    }

    static auto defaults() {
        return hana::make_map(hana::make_pair("name"_s, "Efendi"s));
    }

    std::string name;
    std::optional<int> age;
    Hobby hobby;
};

struct Pol : trait::VarPolicy {
    static auto constexpr serialize_default_value = false;
    static auto constexpr empty_container_not_required = true;
};

struct Pol2 : trait::VarPolicy {
    static auto constexpr empty_container_not_required = true;
};

struct Pol3 : trait::VarPolicy {
    static auto constexpr from_variant = [](auto& x, Variant const& var) {
        x = yenxo::fromString<std::remove_reference_t<decltype(x)>>(var.str());
    };
    static auto constexpr to_variant = [](Variant& var, auto&& x) {
        var = Variant(
                yenxo::toString(std::forward<std::remove_reference_t<decltype(x)>>(x)));
    };
};

struct PersonE : trait::Var<PersonE, Pol> {
    static constexpr auto defaults() {
        return hana::make_map(hana::make_pair("i"_s, 2));
    }

    PersonE() = default;
    std::vector<int> cont;
    int i{0};
};

struct PersonE2 : trait::Var<PersonE2, Pol2> {
    static constexpr auto defaults() {
        return hana::make_map(hana::make_pair("i"_s, 2));
    }

    PersonE2()
            : i(0) {
    }

    BOOST_HANA_DEFINE_STRUCT(PersonE2,
                             (std::vector<int>, cont),
                             (int, i),
                             (std::string, s));
};

struct St3
        : trait::Var<St3>
        , trait::EqualityComparison<St3> {
    St3() = default;
    St3(int x)
            : x(x) {
    }

    constexpr static auto names() {
        return hana::make_map(hana::make_pair("x"_s, "y"));
    }

    BOOST_HANA_DEFINE_STRUCT(St3, (int, x));
};

struct S1 {
    S1() = default;
    explicit S1(std::string const& str)
            : v(str) {
    }
    explicit operator std::string const &() const noexcept {
        return v;
    }
    bool operator==(S1 const& rhs) const noexcept {
        return v == rhs.v;
    }
    std::string v;
};

struct StrStruct
        : trait::Var<StrStruct, Pol3>
        , trait::EqualityComparison<StrStruct> {
    StrStruct() = default;
    explicit StrStruct(std::string const& str)
            : str(str) {
    }
    BOOST_HANA_DEFINE_STRUCT(StrStruct, (S1, str));
};

struct CamelCase {
    template <class T, class S>
    std::string operator()(boost::hana::basic_type<T>, S name) const {
        std::string renamed = boost::hana::to<char const*>(name);
        assert(renamed.size());
        renamed[0] = char(std::tolower(renamed[0]));
        for (size_t i = 0; i < renamed.size();) {
            if (renamed[i] == '_' && i + 1 < renamed.size()) {
                renamed[i + 1] = char(toupper(renamed[i + 1]));
                renamed.erase(i, 1);
            } else {
                ++i;
            }
        }
        return renamed;
    }
};

struct CamelCasePolicy : trait::VarPolicy {
    static constexpr CamelCase rename{};
};

struct AutoCamelCase
        : trait::Var<AutoCamelCase, CamelCasePolicy>
        , trait::EqualityComparison<AutoCamelCase> {
    BOOST_HANA_DEFINE_STRUCT(AutoCamelCase, (std::string, hello_world_2_boo));
};

struct AdditionalProp
        : trait::Var<AdditionalProp, AllowAdditionalPropertiesPolicy>
        , trait::EqualityComparison<AdditionalProp> {
    constexpr static auto names() {
        return hana::make_map(hana::make_pair("y"_s, "z"));
    }
    BOOST_HANA_DEFINE_STRUCT(AdditionalProp, (int, x), (int, y));
};

} // namespace

BOOST_HANA_ADAPT_STRUCT(PersonD, name, age, hobby);
BOOST_HANA_ADAPT_STRUCT(PersonE, cont, i);

TEST_CASE("Check trait::Var", "[variant_traits]") {
    Variant::Map const hobby_var{{"id", Variant(1)}, {"description", Variant("Hack")}};

    Variant::Map person_var{{"name", Variant("Alecu")},
                            {"age", Variant(16)},
                            {"hobby", Variant(hobby_var)}};

    Hobby const hobby{1, std::string("Hack")};

    PersonD person{"Alecu", 16, hobby};

    SECTION("Check toVariant with default value (should yenxo)") {
        person.name = "Efendi";
        person_var["name"] = Variant("Efendi");
        REQUIRE(Variant(person) == Variant(person_var));
    }

    SECTION("Check toVariant with uninitialized age") {
        person_var.erase("age");
        person.age.reset();
        REQUIRE(PersonD::toVariant(person) == Variant(person_var));
    }

    SECTION("Check toVariant with initialized age") {
        REQUIRE(PersonD::toVariant(person) == Variant(person_var));
    }

    SECTION("Check fromVariant with no name (default value is provided)") {
        person_var.erase("name");
        auto const actual = PersonD::fromVariant(Variant(person_var));
        REQUIRE(actual == PersonD{"Efendi", 16, hobby});
    }

    SECTION("Check fromVariant with no age (no default value, but type is optional)") {
        person_var.erase("age");
        auto const actual = PersonD::fromVariant(Variant(person_var));
        REQUIRE(actual == PersonD{"Alecu", hobby});
    }

    SECTION("Check fromVariant with no hobby (no default value)") {
        person_var.erase("hobby");
        REQUIRE_THROWS_AS(PersonD::fromVariant(Variant(person_var)), std::logic_error);
    }

    SECTION("Check from_variant policy parameter") {
        Variant const var(VariantMap{{"str", Variant("1")}});
        REQUIRE(fromVariant<StrStruct>(var) == StrStruct("1"));
        REQUIRE(var == toVariant(StrStruct("1")));
    }

    SECTION("Check toVariant policy redefinition") {
        PersonE p1;
        p1.i = 2;
        REQUIRE(Variant(p1) == Variant(VariantMap{}));

        PersonE p2;
        p2.i = 0;
        p2.cont.push_back(1);
        VariantMap exp{{"i", Variant(0)}, {"cont", Variant(VariantVec{Variant(1)})}};
        REQUIRE(Variant(p2) == Variant(exp));

        PersonE2 p3;
        p3.i = 2;
        REQUIRE(Variant(p3)
                == Variant(VariantMap{{"i", Variant(2)}, {"s", Variant("")}}));
    }

    SECTION("default rename") {
        Variant expected(VariantMap{{"y", Variant(2)}});
        Variant wrong(VariantMap{{"z", Variant(2)}});
        REQUIRE(fromVariant<St3>(expected) == St3(2));
        REQUIRE(toVariant(St3(2)) == expected);
        REQUIRE_THROWS_AS(fromVariant<St3>(wrong), std::logic_error);
        REQUIRE_THROWS_WITH(fromVariant<St3>(wrong), "'y' is required");
    }

    SECTION("rename policy") {
        Variant var(VariantMap{{"helloWorld2Boo", Variant("")}});
        AutoCamelCase st;
        REQUIRE(toVariant(st) == var);
        var.modifyMap().begin()->second = Variant("a");
        st.hello_world_2_boo = "a";
        REQUIRE(fromVariant<AutoCamelCase>(var) == st);
    }

    SECTION("additional prop policy") {
        Variant var(VariantMap{{"x", Variant(1)}, {"z", Variant(2)}});

        AdditionalProp expected;
        expected.x = 1;
        expected.y = 2;

        AdditionalProp p;
        REQUIRE_NOTHROW(fromVariant2(p, var));
        REQUIRE(expected == p);

        var.modifyMap()["u"] = Variant(3);
        REQUIRE_THROWS_AS(fromVariant2(p, var), std::logic_error);
        REQUIRE_THROWS_WITH(fromVariant2(p, var), "'u' is unknown");
    }
}

namespace {

struct Car : trait::Var<Car> {
    Car(std::string const& name, int wheels)
            : name(name)
            , wheels(wheels) {
    }
    Car() = default;

    std::string name;
    int wheels{0};
};

} // namespace

BOOST_HANA_ADAPT_STRUCT(Car, name, wheels);

TEST_CASE("Check trait::Var fails", "[variant_traits]") {
    Variant car_var{Variant::Map{{"name", Variant("saab")}, {"wheels", Variant("4")}}};
    REQUIRE_THROWS_MATCHES(
            Car::fromVariant(car_var),
            VariantBadType,
            ExceptionIs<VariantBadType>("expected 'int32', actual 'string'", "/wheels"));
    REQUIRE(hana::equal(int(1), int(1)));
}

namespace {

struct TagPolicy : trait::VarPolicy {
    static constexpr auto tag = "a tag"_s;
};

struct Tagged : trait::Var<Tagged, TagPolicy> {
    Tagged() = default;
    explicit Tagged(int x)
            : value(x) {
    }
    BOOST_HANA_DEFINE_STRUCT(Tagged, (int, value));
};

} // namespace

TEST_CASE("Check Policy::Tag", "[variant_traits]") {
    Variant var(VariantMap{{"__tag", Variant("a tag")}, {"value", Variant(10)}});

    SECTION("ok") {
        Tagged const val(10);
        REQUIRE(toVariant(Tagged(10)) == var);
        REQUIRE(val.value == fromVariant<Tagged>(var).value);
    }

    SECTION("fail") {
        var.modifyMap().at("__tag") = Variant("foo");
        REQUIRE_THROWS_MATCHES(fromVariant<Tagged>(var),
                               VariantBadType,
                               ExceptionIs<VariantBadType>(
                                       "'foo' is not of type 'a tag literal'", "/__tag"));
    }
}

ext: cpp

max_stars_repo_name: nicktrandafil/serialize

max_issues_repo_name: nicktrandafil/rproject

max_forks_repo_name: nicktrandafil/rproject


text:
#include <boost/filesystem.hpp>
#include <boost/dll.hpp>
#include <fmt/format.h>
#include <iostream>

using namespace std;
namespace fs = boost::filesystem;
using boost::dll::program_location;

class args {
public:
    explicit args(int argc, const char **argv) :
        _argc(argc - 1),
        _argv(argv + 1) {}

    const char *const *begin() const { return _argv; }

    const char *const *end() const { return _argv + _argc; }

private:
    const int _argc;
    const char **_argv;
};

int main(int argc, const char **argv) {
    if (argc < 2) {
        string program_name = program_location().stem().string();
        cerr << fmt::format(
            "usage: {} <filename> [<filename>, ...]",
            program_name
        ) << endl;
        return EXIT_FAILURE;
    }

    ofstream ofs("resources.cpp");
    ofs << "#include <map>" << endl;
    ofs << "#include <vector>" << endl;
    ofs << "#include <string>" << endl;
    ofs << endl;
    ofs << "using namespace std;" << endl;
    ofs << endl;
    ofs << "map<string, vector<unsigned char>> resources{" << endl;

    for (const char *each : args(argc, argv)) {
        fs::path filepath(fs::canonical(fs::path(each)));
        string filename = filepath.filename().string();
        ofs << fmt::format("{{\"{0}\", {{", filename) << endl;

        ifstream ifs(filepath.string(), ios::binary);
        ifs.unsetf(ios::skipws);
        ifs.seekg(0, ios::end);
        streampos pos = ifs.tellg();
        ifs.seekg(0, ios::beg);

        vector<unsigned char> data;
        data.reserve((size_t) pos);
        data.insert(data.begin(),
            istream_iterator<unsigned char>(ifs),
            istream_iterator<unsigned char>()
        );

        unsigned int count = 0;
        for (auto &byte : data) {
            count = (count + 1) % 10;
            ofs << fmt::format("0x{:0=2x}, ", byte);
            if (count == 0) {
                ofs << endl;
            }
        }

        ofs << "}}," << endl;
    }

    ofs << "};" << endl;
    return EXIT_SUCCESS;
}

max_stars_repo_name: syncaide/backend

max_issues_repo_name: syncaide/backend

max_forks_repo_name: syncaide/backend


text:
//=============================================================================
// Copyright (c) 2015-2018 glywk
// https://github.com/glywk
//
// 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/foreach.hpp>
#include <boost/property_tree/properties_parser.hpp>
#include <boost/property_tree/ptree.hpp>
#include <exception>
#include <iostream>
#include <set>
#include <string>

namespace pt = boost::property_tree;

struct configuration {
  void load(const std::string &filename);
  pt::ptree tree;
};

void configuration::load(const std::string &filename) {
  // Parse the properties into the property tree.
  pt::read_properties(filename, tree);
}

/*!
 * the main function simply loads the given file into boost::property_tree structure.
 */
int main(int argc, char *argv[]) {
  try {
    // read input from the given file
    std::string filename(1 == argc ? "full.properties" : argv[1]);
    configuration c;
    c.load(filename);
    for (auto property : c.tree) {
      std::cout << property.first << "=" << property.second.data() << std::endl;
    }
  } catch (std::exception &e) {
    std::cout << "Error: " << e.what() << "\n";
  }
  return 0;
}

ext: cc


text:
#include "Fractal/External.h"

#include "Fractal/Geometry.h"
#include "Fractal/Utilities.h"
#include <boost/multi_array.hpp>

namespace
{
    const int width = 128;
    const int height = 128;
    const int supersample = 1;

    class DLA
    {
    public:
        DLA(Magick::Image& image)
          : m_width(image.size().width()),
            m_height(image.size().height()),
            m_max_density(0),
            m_densities(boost::extents[m_height][m_width])
        {
            m_centre(0) = m_width / 2;
            m_centre(1) = m_height / 2;
        }

        virtual ~DLA()
        {
        }

        void Grow(const unsigned int max_density)
        {
            {
                Fractal::iVector2 origin;
                origin(0) = 0;
                origin(1) = 0;
                Plot(origin, max_density);
            }
            std::vector<unsigned int> seed_radii(max_density + 1, 5);
            while (seed_radii[0] + 10 < std::min(m_width, m_height) / 2) {
                const double seed_angle = Fractal::Utilities::Random() * M_PI * 2;
                const unsigned int density = Fractal::Utilities::Random(1, max_density);

                Fractal::iVector2 point;
                point(0) = static_cast<unsigned int>(cos(seed_angle) * seed_radii[density]);
                point(1) = static_cast<unsigned int>(sin(seed_angle) * seed_radii[density]);
                //std::cout << "New point: " << point(0) << ", " << point(1) << std::endl;
                while (Radius(point) < seed_radii[density] + 5) {
                    //std::cout << "(" << point(0) << ", " << point(1) << ")\t";
                    switch(RandomDirection()) {
                        case 0:
                            point(0) -= 1;
                            break;
                        case 1:
                            point(0) += 1;
                            break;
                        case 2:
                            point(1) -= 1;
                            break;
                        case 3:
                            point(1) += 1;
                            break;
                        default:
                            assert(false);
                    }
                    if (Touching(point, density)) {
                        Plot(point, density);
                        for (unsigned int i = 0; i <= density; i++) {
                            seed_radii[i] = std::max(Radius(point) + 5, seed_radii[i]);
                        }
                        break;
                    }
               }
                //std::cout << std::endl;
            }
        }

        void Render(Magick::Image& image)
        {
            assert(image.size().width() == m_width);
            assert(image.size().height() == m_height);
            std::cout << m_max_density << std::endl;

            for (unsigned int x = 0; x < m_width; x++) {
                for (unsigned int y = 0; y < m_height; y++) {
                    //std::cout << "(" << m_densities[x][y];
                    const double v = static_cast<double>(m_densities[x][y]) / m_max_density;
                    //std::cout << ", " << v << ")\t";
                    image.pixelColor( x, y, Magick::ColorGray(v) );
                }
            }
        }

    private:
        const int RandomDirection(void)
        {
        }

        const bool Touching(const Fractal::iVector2& point, const unsigned int density)
        {
            const Fractal::iVector2 real_point = point + m_centre;
            if (m_densities[real_point(0) - 1][real_point(1)] >= density) {
                return true;
            }
            if (m_densities[real_point(0) + 1][real_point(1)] >= density) {
                return true;
            }
            if (m_densities[real_point(0)][real_point(1) - 1] >= density) {
                return true;
            }
            if (m_densities[real_point(0)][real_point(1) + 1] >= density) {
                return true;
            }
            return false;
        }

        const unsigned int Radius(const Fractal::iVector2& point)
        {
            return static_cast<unsigned int>(sqrt(point(0) * point(0) + point(1) * point(1)));
        }

        void Plot(const Fractal::iVector2& point, const unsigned int density)
        {
            m_max_density = std::max(m_max_density, density);
            //std::cout << point(0) << "\t" << point(1) << std::endl;
            //std::cout << ".";
            const Fractal::iVector2 real_point = point + m_centre;
            m_densities[real_point(0)][real_point(1)] = std::max(m_densities[real_point(0)][real_point(1)], density);
        }

        const unsigned int m_width;
        const unsigned int m_height;
        unsigned int m_max_density;
        Fractal::iVector2 m_centre;
        boost::multi_array<unsigned int, 2> m_densities;

        unsigned int m_random_data;
        unsigned int m_random_bits;
    };

    void ProduceDLAFractal(Magick::Image& image)
    {
        DLA dla(image);
        dla.Grow(100);
        dla.Render(image);
    }
}

int main(int argc, char* argv[])
{
    std::ios::sync_with_stdio(false);

    Magick::Image image(Magick::Geometry(width * supersample, height * supersample), Magick::ColorRGB(0.0, 0.0, 0.0));

    ProduceDLAFractal(image);

    image.scale(Magick::Geometry(width, height));
    image.write("images/dla_image.bmp");

    return 0;
}

max_stars_repo_name: pauldoo/scratch

max_issues_repo_name: pauldoo/scratch

max_forks_repo_name: pauldoo/scratch