本文整理汇总了C++中boost::shared_ptr类的典型用法代码示例。如果您正苦于以下问题:C++ shared_ptr类的具体用法?C++ shared_ptr怎么用?C++ shared_ptr使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了shared_ptr类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: BOOST_FOREACH
BOOST_FOREACH(boost::shared_ptr<count_writer_t> p_count_writer, mCellPopulationCountWriters)
{
p_count_writer->OpenOutputFile(rOutputFileHandler);
p_count_writer->WriteHeader(this);
}
示例2: assert
void ribi::gtst::ParticipantDialogStateChooseAction::RespondToTimedServerPush()
{
const int time_left = m_server->GetStates()->GetCurrentState()->GetTimeLeft();
//Update label_time_left
{
std::string text
= std::string("Time left: ")
+ std::to_string(time_left)
+ std::string(" seconds");
if (m_server->GetParameters()->GetChooseAction()->GetWait())
{
//Infinite time
text+=std::string(" (waiting for others)");
}
assert(ui.m_label_time_left);
ui.m_label_time_left->setText(text.c_str());
}
//Check if choice must be sent to the server
if (!m_server->GetParameters()->GetChooseAction()->GetWait()
&& time_left <= 0)
{
assert(GetDialog());
assert(GetDialog()->CanGetParticipant());
if (ui.m_button_choose_action->isEnabled())
{
//Let Participant choose a random action by time
const int selected = ui.m_group->selectedButtonIndex();
assert(ui.m_group->count() > 0);
const int action_index
= (selected == -1 //Did user select something?
? std::rand() % ui.m_group->count() //Take a random action
: selected);
assert(action_index > -1 && action_index < ui.m_group->count());
ui.m_group->setSelectedButtonIndex(action_index);
OnChooseActionClick();
}
}
if (!ui.m_button_choose_action->isEnabled())
{
assert(ui.m_group->selectedButtonIndex() != -1
&& "m_button_choose_action should only disable when an action is selected");
const std::vector<boost::shared_ptr<ChooseActionOption> >& options
= m_server->GetParameters()->GetChooseAction()->GetOptions();
assert(ui.m_group->selectedButtonIndex() < static_cast<int>(options.size()));
const boost::shared_ptr<ChooseActionOption> option
= options[ ui.m_group->selectedButtonIndex() ];
const std::string text
= option->GetMessageChoice()
+ std::string("\', waiting for the others...");
ui.m_label_status->setText(text.c_str());
}
else
{
ui.m_label_status->setText("Please choose an action.");
}
///Follow the server its tempo
RespondToParticipant();
}
示例3: locked_ptr
template<typename F, typename G> locked_ptr(boost::shared_ptr<T> pointer, F lock, G unlock):
boost::shared_ptr<T>(pointer.get(), unlock),
value(pointer)
{
lock();
};
示例4: CellsCreatorFactory
void ribi::TriangleMeshCreatorMenuDialog::TestDeep() noexcept
{
const bool verbose{false};
if (verbose) { TRACE("Trying out to build cells from the hardest testing templates"); }
{
using ribi::trim::Cell;
using ribi::trim::CellsCreator;
using ribi::trim::CellsCreatorFactory;
using ribi::trim::CreateVerticalFacesStrategy;
using ribi::trim::CreateVerticalFacesStrategies;
using ribi::trim::Dialog;
using ribi::trim::Template;
//This is the longest test by far
//const TestTimer test_timer(boost::lexical_cast<std::string>(__LINE__),__FILE__,1.0);
for (CreateVerticalFacesStrategy strategy: CreateVerticalFacesStrategies().GetAll())
{
const boost::shared_ptr<Template> my_template {
Template::CreateTest(3)
};
const int n_cell_layers = 2;
const boost::shared_ptr<CellsCreator> cells_creator{
CellsCreatorFactory().Create(
my_template,
n_cell_layers,
1.0 * boost::units::si::meter,
strategy,
verbose
)
};
const std::vector<boost::shared_ptr<Cell>> cells { cells_creator->GetCells() };
assert(cells.size() > 0);
}
}
if (verbose) { TRACE("Testing case 1"); }
TriangleMeshCreatorMenuDialog().Execute(
{
"TriangleMeshCreator",
"--layer_height", "1",
"--WKT", "POLYGON((1 1,-1 1,-1 -1,1 -1))",
"--strategy", "1",
"--n_layers", "1",
"--fraction", "0.75",
//"--show_mesh",
//"--verbose",
"--triangle_max_area", "10.0",
"--triangle_min_angle", "20.0",
"--profile"
}
);
if (verbose) { TRACE("Testing case 2"); }
TriangleMeshCreatorMenuDialog().Execute(
{
"TriangleMeshCreator",
"-z", "1",
"-w", "POLYGON((0 0,0 3,3 0)),POLYGON((1 1,0 2,2 0))",
"-s", "1",
"-n", "1",
"-f", "0.75",
//"-m",
//"-b",
"--triangle_area", "10.0",
"--triangle_quality", "20.0",
"--profile"
}
);
if (verbose) { TRACE("Testing case 3"); }
TriangleMeshCreatorMenuDialog().Execute(
{
"TriangleMeshCreator",
"-z", "1",
"-w", "POLYGON((10 10,10 -10,-10 -10,-10 10)),LINESTRING(5 5,5 -5,-5 -5,-5 5)",
"-s", "1",
"-n", "1",
"-f", "0.75",
//"-m",
//"-b",
"-r", "10.0",
"-q", "20.0",
"--profile"
}
);
if (verbose) { TRACE("Testing case 4"); }
TriangleMeshCreatorMenuDialog().Execute(
{
"TriangleMeshCreator",
"-z", "1",
"-w", "LINESTRING(5 5,5 -5,-5 -5,-5 5)",
"-s", "1",
"-n", "1",
"-f", "0.75",
//"-m",
//"-b",
"-r", "10.0",
"-q", "20.0",
"--profile"
}
);
//.........这里部分代码省略.........
示例5: throw
void VectorPort::onChildCreate(
const boost::shared_ptr<BaseVectorType::ChildType>& inCreatedChild) const throw (Error) {
inCreatedChild->setName(getName());
}
示例6:
Connection::Connection(boost::shared_ptr< Hive > hive)
: m_hive(hive), m_socket(hive->GetService()), m_io_strand(hive->GetService()), m_timer(hive->GetService()), m_receive_buffer_size(4096), m_timer_interval(1000), m_error_state(0)
{
}
示例7: OverlayPluginTestFixture
OverlayPluginTestFixture()
{
arrayPool = new NDArrayPool(100, 0);
expectedArrayCounter=0;
// Asyn manager doesn't like it if we try to reuse the same port name for multiple drivers
// (even if only one is ever instantiated at once), so we change it slightly for each test case.
std::string simport("simOVER1"), testport("OVER1");
uniqueAsynPortName(simport);
uniqueAsynPortName(testport);
// We need some upstream driver for our test plugin so that calls to connectArrayPort
// don't fail, but we can then ignore it and send arrays by calling processCallbacks directly.
driver = boost::shared_ptr<asynPortDriver>(new asynPortDriver(simport.c_str(),
1, 1,
asynGenericPointerMask,
asynGenericPointerMask,
0, 0, 0, 2000000));
// This is the plugin under test
Overlay = boost::shared_ptr<OverlayPluginWrapper>(new OverlayPluginWrapper(testport.c_str(),
50,
1,
simport.c_str(),
0,
8,
0,
0,
0,
1));
// This is the mock downstream plugin
downstream_plugin = new TestingPlugin(testport.c_str(), 0);
// Enable the plugin
Overlay->start(); // start the plugin thread although not required for this unittesting
Overlay->write(NDPluginDriverEnableCallbacksString, 1);
Overlay->write(NDPluginDriverBlockingCallbacksString, 1);
client = boost::shared_ptr<asynGenericPointerClient>(new asynGenericPointerClient(testport.c_str(), 0, NDArrayDataString));
client->registerInterruptUser(&Overlay_callback);
// Test a "normal" case
overlayTempCaseStr test1 = {0, 500, 500, 50, 50, 1, 1, 0, 255, 0, NDOverlayCross, NDOverlaySet, 2, {1024, 1024}, NDColorModeMono};
appendTestCase(&overlayTestCaseStrs, &test1);
// Test a case with size larger than array
overlayTempCaseStr test2 = {0, 500, 500, 5000, 5000, 1, 1, 0, 255, 0, NDOverlayEllipse, NDOverlaySet, 2, {1024, 1024}, NDColorModeMono};
appendTestCase(&overlayTestCaseStrs, &test2);
// Test a case with zero size
overlayTempCaseStr test3 = {0, 500, 500, 0, 0, 1, 1, 0, 255, 0, NDOverlayRectangle, NDOverlaySet, 2, {1024, 1024}, NDColorModeMono};
appendTestCase(&overlayTestCaseStrs, &test3);
// Test a case with negative position
overlayTempCaseStr test4 = {0, -500, -500, 50, 50, 1, 1, 0, 255, 0, NDOverlayCross, NDOverlaySet, 2, {1024, 1024}, NDColorModeMono};
appendTestCase(&overlayTestCaseStrs, &test4);
// Test a case with position larger than array size
overlayTempCaseStr test5 = {0, 1500, 1500, 50, 50, 1, 1, 0, 255, 0, NDOverlayEllipse, NDOverlaySet, 2, {1024, 1024}, NDColorModeMono};
appendTestCase(&overlayTestCaseStrs, &test5);
// Test an RGB1 case
overlayTempCaseStr test6 = {0, 500, 500, 50, 50, 1, 1, 0, 255, 0, NDOverlayRectangle, NDOverlaySet, 3, {3, 1024, 1024}, NDColorModeRGB1};
appendTestCase(&overlayTestCaseStrs, &test6);
// Test an case with very large width
overlayTempCaseStr test7 = {0, 500, 500, 50, 50, 5000, 5000, 0, 255, 0, NDOverlayCross, NDOverlaySet, 2, {1024, 1024}, NDColorModeMono};
appendTestCase(&overlayTestCaseStrs, &test7);
// Test an case with zero width
overlayTempCaseStr test8 = {0, 500, 500, 50, 50, 0, 0, 0, 255, 0, NDOverlayCross, NDOverlaySet, 2, {1024, 1024}, NDColorModeMono};
appendTestCase(&overlayTestCaseStrs, &test8);
// Test a "normal" case using address 1
overlayTempCaseStr test9 = {1, 500, 500, 50, 50, 1, 1, 0, 255, 0, NDOverlayCross, NDOverlaySet, 2, {1024, 1024}, NDColorModeMono};
appendTestCase(&overlayTestCaseStrs, &test9);
}
示例8: Add
void Add( const boost::shared_ptr<T>& prt )
{
if ( prt_.empty() )
prt->SetFocus();
prt_.push_back(prt);
}
示例9: print_fun
void print_fun(boost::shared_ptr<int> value)
{cout<<"fun : value is = "<<*value<<", use_count = "<<value.use_count()<<endl;}
示例10: writePartial
void OgrWriter::writePartial(const boost::shared_ptr<const hoot::Relation>& newRelation)
{
// Make sure all the elements in the relation are in the cache
const std::vector<RelationData::Entry>& relationEntries = newRelation->getMembers();
std::vector<RelationData::Entry>::const_iterator relationElementIter;
long nodeCount = 0;
long wayCount = 0;
long relationCount = 0;
for ( relationElementIter = relationEntries.begin();
relationElementIter != relationEntries.end();
relationElementIter++ )
{
switch ( relationElementIter->getElementId().getType().getEnum() )
{
case ElementType::Node:
nodeCount++;
if ( nodeCount > _currElementCacheCapacity )
{
LOG_FATAL("Relation ID " << newRelation->getId() <<
" contains more nodes than can fit in the cache (" << _currElementCacheCapacity<<
")");
throw HootException("Relation with too many nodes");
}
break;
case ElementType::Way:
wayCount++;
if ( wayCount > _currElementCacheCapacity)
{
LOG_FATAL("Relation ID " << newRelation->getId() <<
" contains more ways than can fit in the cache (" << _currElementCacheCapacity <<
")");
throw HootException("Relation with too many ways");
}
break;
case ElementType::Relation:
relationCount++;
if ( relationCount > _currElementCacheCapacity)
{
LOG_FATAL("Relation ID " << newRelation->getId() <<
" contains more relations than can fit in the cache (" << _currElementCacheCapacity <<
")");
throw HootException("Relation with too many relations");
}
break;
default:
throw HootException("Relation containus unknown type");
break;
}
if ( _elementCache->containsElement(relationElementIter->getElementId()) == false )
{
throw HootException("Relation element did not exist in cache");
}
}
// Add to the cache
ConstElementPtr constRelation(newRelation);
_elementCache->addElement(constRelation);
ElementProviderPtr cacheProvider(_elementCache);
_writePartial(cacheProvider, newRelation);
}
示例11:
cql::cql_message_query_impl_t::cql_message_query_impl_t(const boost::shared_ptr<cql_query_t>& query)
: _buffer(new std::vector<cql_byte_t>())
, _consistency(query->consistency())
, _query(query->query())
, _is_traced(query->is_traced())
{}
示例12: peek
void PeekProcessor::peek(boost::shared_ptr<TProtocol> in,
TType ftype,
int16_t fid) {
(void) fid;
in->skip(ftype);
}
示例13: DispatchAccept
void Acceptor::DispatchAccept(boost::shared_ptr< Connection > connection)
{
m_acceptor.async_accept(connection->GetSocket(), connection->GetStrand().wrap(boost::bind(&Acceptor::HandleAccept, shared_from_this(), _1, connection)));
}
示例14: compare_scans
void compare_scans(boost::shared_ptr<vector<line> > firstScan,
boost::shared_ptr<vector<line> > secondScan,
int rotation_prior_mean,
int& rotOut,
Vector2f translation_prior_mean,
Vector2f & translationOut)
{
int num_theta_entries = (2 * M_PI -
delta_theta*angle_increment)/(delta_theta*M_PI/180) + 1;
vector<float> theta = vector<float>(num_theta_entries);
for(double i = -M_PI, counter = 0; counter < num_theta_entries;
i+= delta_theta*M_PI/180, counter++) {
theta[counter] = i;
}
//Initial rotation estimation. This will vary depending on the
//lines being compared.
// Vector2f translation_prior_mean = previous_translation;
float translation_prior_sd = 0.5;
// float rotation_prior_mean = previous_est_rot;
float rotation_prior_sd = 15;
float rotation_posterior_sd = 4;
vector<float> rotation_prior (360,0);
vector<float> rotation_score (360,0);
float dist;
float sum1;
for (int i=0; i<360; i++)
{
dist = min(abs(i - rotation_prior_mean),abs(i-360-rotation_prior_mean));
rotation_prior[i] = exp(-pow(dist,2)/pow(rotation_prior_sd,2));
sum1 += rotation_prior[i];
}
for (int i=0; i<360; i++)
{
rotation_prior[i] /= sum1;
}
//for each pair of lines between the two scans, estimate the
// probability that they are from the same object. The more likely they
// are to be by an unmoved object, the more likely that the rotation of
// the was equal to the theta difference between the lines.
for (int i=0; i < firstScan->size(); i++)
{
for (int j=0; j < secondScan->size(); j++)
{
float dist;
float theta_diff = (delta_theta*(firstScan->at(i).theta_index -
secondScan->at(j).theta_index) );
if (theta_diff < 0) {
theta_diff += 360;
}
//if the lines are clearly not from the same source because the
// translation has moved too much for one frame, then do not use their
// relative angles to estimate the rotation.
float expected_rho_change;
expected_rho_change =
-(translation_prior_mean[0]*cos(theta[firstScan->at(i).theta_index]) +
translation_prior_mean(1)*sin(theta[firstScan->at(i).theta_index]) );
if(abs(firstScan->at(i).est_rho + expected_rho_change -
secondScan->at(j).est_rho) > rho_sanity_tolerance)
{
continue;
}
for (int k=0; k<360; k++)
{
dist = min(abs(k-theta_diff), abs(k-theta_diff-360));
rotation_score[k] = rotation_score[k] +
exp(-pow(dist,2)/pow(rotation_posterior_sd,2));
}
}
}
vector<float> rotation_prob(360,0);
for (int i=0; i<rotation_prob.size(); i++) {
rotation_prob[i] = rotation_prior[i]* rotation_score[i];
//rotation_prob[i] = rotation_score[i];
}
float max1 = 0;
for (int i=0; i<rotation_prob.size(); i++) {
if (rotation_prob[i]> max1) {
//.........这里部分代码省略.........
示例15: signalSessionAdded
void
SessionManager::addDataprocessor( boost::shared_ptr<Dataprocessor>& proc )
{
sessions_.push_back( Session( proc ) );
emit signalSessionAdded( proc.get() );
}