本文整理汇总了C++中std::unique_ptr::Allocate方法的典型用法代码示例。如果您正苦于以下问题:C++ unique_ptr::Allocate方法的具体用法?C++ unique_ptr::Allocate怎么用?C++ unique_ptr::Allocate使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类std::unique_ptr
的用法示例。
在下文中一共展示了unique_ptr::Allocate方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: load
// Load Regions related to a provided SfM_Data View container
virtual bool load(
const SfM_Data & sfm_data,
const std::string & feat_directory,
std::unique_ptr<features::Image_describer>& image_describer)
{
C_Progress_display my_progress_bar( sfm_data.GetViews().size(),
std::cout, "\n- Regions Loading -\n");
// Read for each view the corresponding regions and store them
for (Views::const_iterator iter = sfm_data.GetViews().begin();
iter != sfm_data.GetViews().end(); ++iter, ++my_progress_bar)
{
const std::string sImageName = stlplus::create_filespec(sfm_data.s_root_path, iter->second.get()->s_Img_path);
const std::string basename = stlplus::basename_part(sImageName);
const std::string featFile = stlplus::create_filespec(feat_directory, basename, ".feat");
const std::string descFile = stlplus::create_filespec(feat_directory, basename, ".desc");
image_describer->Allocate(regions_per_view[iter->second.get()->id_view]);
if (!image_describer->Load(
regions_per_view[iter->second.get()->id_view].get(),
featFile,
descFile))
{
std::cerr << "Invalid regions files for the view: " << sImageName << std::endl;
return false;
}
}
return true;
}
示例2: CloneError
/**
* Construct an analog input.
*
* @param channel The channel number on the roboRIO to represent. 0-3 are
* on-board 4-7 are on the MXP port.
*/
AnalogInput::AnalogInput(uint32_t channel) {
std::stringstream buf;
buf << "Analog Input " << channel;
Resource::CreateResourceObject(inputs, kAnalogInputs);
if (!checkAnalogInputChannel(channel)) {
wpi_setWPIErrorWithContext(ChannelIndexOutOfRange, buf.str());
return;
}
if (inputs->Allocate(channel, buf.str()) ==
std::numeric_limits<uint32_t>::max()) {
CloneError(*inputs);
return;
}
m_channel = channel;
void *port = getPort(channel);
int32_t status = 0;
m_port = initializeAnalogInputPort(port, &status);
wpi_setErrorWithContext(status, getHALErrorMessage(status));
LiveWindow::GetInstance()->AddSensor("AnalogInput", channel, this);
HALReport(HALUsageReporting::kResourceType_AnalogChannel, channel);
}
示例3: CloneError
/**
* Relay constructor given a channel.
*
* This code initializes the relay and reserves all resources that need to be
* locked. Initially the relay is set to both lines at 0v.
* @param channel The channel number (0-3).
* @param direction The direction that the Relay object will control.
*/
Relay::Relay(uint32_t channel, Relay::Direction direction)
: m_channel(channel), m_direction(direction) {
std::stringstream buf;
Resource::CreateResourceObject(relayChannels,
dio_kNumSystems * kRelayChannels * 2);
if (!SensorBase::CheckRelayChannel(m_channel)) {
buf << "Relay Channel " << m_channel;
wpi_setWPIErrorWithContext(ChannelIndexOutOfRange, buf.str());
return;
}
if (m_direction == kBothDirections || m_direction == kForwardOnly) {
buf << "Forward Relay " << m_channel;
if (relayChannels->Allocate(m_channel * 2, buf.str()) == ~0ul) {
CloneError(*relayChannels);
return;
}
HALReport(HALUsageReporting::kResourceType_Relay, m_channel);
}
if (m_direction == kBothDirections || m_direction == kReverseOnly) {
buf << "Reverse Relay " << m_channel;
if (relayChannels->Allocate(m_channel * 2 + 1, buf.str()) == ~0ul) {
CloneError(*relayChannels);
return;
}
HALReport(HALUsageReporting::kResourceType_Relay, m_channel + 128);
}
int32_t status = 0;
setRelayForward(m_relay_ports[m_channel], false, &status);
setRelayReverse(m_relay_ports[m_channel], false, &status);
wpi_setErrorWithContext(status, getHALErrorMessage(status));
LiveWindow::GetInstance().AddActuator("Relay", 1, m_channel, this);
}
示例4: stream
bool SaveAndLoad
(
std::unique_ptr<Image_describer> & image_describer
)
{
const std::string sImage_describer = stlplus::create_filespec("./", "image_describer", "json");
{
std::ofstream stream(sImage_describer.c_str());
if (!stream.is_open())
return false;
try
{
cereal::JSONOutputArchive archive(stream);
archive(cereal::make_nvp("image_describer", image_describer));
auto regionsType = image_describer->Allocate();
archive(cereal::make_nvp("regions_type", regionsType));
}
catch (const cereal::Exception & e)
{
std::cerr << e.what() << std::endl
<< "Cannot dynamically allocate the Image_describer interface." << std::endl;
return false;
}
}
image_describer.reset();
{
// Dynamically load the image_describer from the file (will restore old used settings)
std::ifstream stream(sImage_describer.c_str());
if (!stream.is_open())
return false;
try
{
cereal::JSONInputArchive archive(stream);
archive(cereal::make_nvp("image_describer", image_describer));
}
catch (const cereal::Exception & e)
{
std::cerr << e.what() << std::endl
<< "Cannot dynamically allocate the Image_describer interface." << std::endl;
return false;
}
}
return true;
}