本文整理汇总了C++中shared_ptr类的典型用法代码示例。如果您正苦于以下问题:C++ shared_ptr类的具体用法?C++ shared_ptr怎么用?C++ shared_ptr使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了shared_ptr类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: addTag
void BooksDBUtil::addTag(shared_ptr<Book> book, shared_ptr<Tag> tag) {
if (book->addTag(tag)) {
BooksDB::Instance().saveTags(book);
}
}
示例2:
bool
PersistentRuleCriteria::ReadObject(shared_ptr<RuleCriteria> pRuleCriteria, shared_ptr<DALRecordset> pRS)
{
if (pRS->IsEOF())
return false;
pRuleCriteria->SetID(pRS->GetLongValue("criteriaid"));
pRuleCriteria->SetRuleID(pRS->GetLongValue("criteriaruleid"));
pRuleCriteria->SetMatchValue(pRS->GetStringValue("criteriamatchvalue"));
pRuleCriteria->SetPredefinedField((RuleCriteria::PredefinedField) pRS->GetLongValue("criteriapredefinedfield"));
pRuleCriteria->SetMatchType((RuleCriteria::MatchType) pRS->GetLongValue("criteriamatchtype"));
pRuleCriteria->SetHeaderField(pRS->GetStringValue("criteriaheadername"));
pRuleCriteria->SetUsePredefined(pRS->GetLongValue("criteriausepredefined") ? true : false);
return true;
}
示例3: feature_extraction_pipeline
int feature_extraction_pipeline(int argc, char** argv) {
::google::InitGoogleLogging(argv[0]);
const int num_required_args = 7;
if (argc < num_required_args) {
LOG(ERROR)<<
"This program takes in a trained network and an input data layer, and then"
" extract features of the input data produced by the net.\n"
"Usage: extract_features pretrained_net_param"
" feature_extraction_proto_file extract_feature_blob_name1[,name2,...]"
" save_feature_dataset_name1[,name2,...] num_mini_batches db_type"
" [CPU/GPU] [DEVICE_ID=0]\n"
"Note: you can extract multiple features in one pass by specifying"
" multiple feature blob names and dataset names seperated by ','."
" The names cannot contain white space characters and the number of blobs"
" and datasets must be equal.";
return 1;
}
int arg_pos = num_required_args;
arg_pos = num_required_args;
if (argc > arg_pos && strcmp(argv[arg_pos], "GPU") == 0) {
LOG(ERROR)<< "Using GPU";
uint device_id = 0;
if (argc > arg_pos + 1) {
device_id = atoi(argv[arg_pos + 1]);
CHECK_GE(device_id, 0);
}
LOG(ERROR) << "Using Device_id=" << device_id;
Caffe::SetDevice(device_id);
Caffe::set_mode(Caffe::GPU);
} else {
LOG(ERROR) << "Using CPU";
Caffe::set_mode(Caffe::CPU);
}
arg_pos = 0; // the name of the executable
std::string pretrained_binary_proto(argv[++arg_pos]);
// Expected prototxt contains at least one data layer such as
// the layer data_layer_name and one feature blob such as the
// fc7 top blob to extract features.
/*
layers {
name: "data_layer_name"
type: DATA
data_param {
source: "/path/to/your/images/to/extract/feature/images_leveldb"
mean_file: "/path/to/your/image_mean.binaryproto"
batch_size: 128
crop_size: 227
mirror: false
}
top: "data_blob_name"
top: "label_blob_name"
}
layers {
name: "drop7"
type: DROPOUT
dropout_param {
dropout_ratio: 0.5
}
bottom: "fc7"
top: "fc7"
}
*/
std::string feature_extraction_proto(argv[++arg_pos]);
shared_ptr<Net<Dtype> > feature_extraction_net(
new Net<Dtype>(feature_extraction_proto, caffe::TEST));
feature_extraction_net->CopyTrainedLayersFrom(pretrained_binary_proto);
std::string extract_feature_blob_names(argv[++arg_pos]);
std::vector<std::string> blob_names;
caffe::string_split(&blob_names, extract_feature_blob_names, ",");
std::string save_feature_dataset_names(argv[++arg_pos]);
std::vector<std::string> dataset_names;
caffe::string_split(&dataset_names, save_feature_dataset_names, ",");
CHECK_EQ(blob_names.size(), dataset_names.size()) <<
" the number of blob names and dataset names must be equal";
size_t num_features = blob_names.size();
for (size_t i = 0; i < num_features; i++) {
CHECK(feature_extraction_net->has_blob(blob_names[i]))
<< "Unknown feature blob name " << blob_names[i]
<< " in the network " << feature_extraction_proto;
}
int num_mini_batches = atoi(argv[++arg_pos]);
std::vector<shared_ptr<db::DB> > feature_dbs;
std::vector<shared_ptr<db::Transaction> > txns;
const char* db_type = argv[++arg_pos];
for (size_t i = 0; i < num_features; ++i) {
LOG(INFO)<< "Opening dataset " << dataset_names[i];
shared_ptr<db::DB> db(db::GetDB(db_type));
db->Open(dataset_names.at(i), db::NEW);
feature_dbs.push_back(db);
shared_ptr<db::Transaction> txn(db->NewTransaction());
txns.push_back(txn);
}
//.........这里部分代码省略.........
示例4: go
/*! Constitutive law */
void FCPM::go(shared_ptr<IGeom>& _geom, shared_ptr<IPhys>& _phys, Interaction* I){
const ScGeom& geom=*static_cast<ScGeom*>(_geom.get());
FreshConcretePhys& phys=*static_cast<FreshConcretePhys*>(_phys.get());
const int id1 = I->getId1();
const int id2 = I->getId2();
const BodyContainer& bodies = *scene->bodies;
const State& de1 = *static_cast<State*>(bodies[id1]->state.get());
const State& de2 = *static_cast<State*>(bodies[id2]->state.get());
//Calculation of the max penetretion and the radius of the overlap area
Sphere* s1=dynamic_cast<Sphere*>(bodies[id1]->shape.get());
Sphere* s2=dynamic_cast<Sphere*>(bodies[id2]->shape.get());
Real dist;
Real contactRadius;
Real OverlapRadius;
if (s1 and s2) {
phys.maxPenetration=s1->radius * phys.Penetration1 + s2->radius * phys.Penetration2;
dist = s1->radius + s2->radius - geom.penetrationDepth;
OverlapRadius = pow(((4 * pow(dist,2) * pow(s1->radius,2) - pow((pow(dist,2) - pow(s2->radius,2) + pow(s1->radius,2)),2)) / (4 * pow(dist,2))),(1.0/2.0));
//contactRadius = (pow(s1->radius,2) + pow(s2->radius,2))/(s1->radius + s2->radius);
contactRadius = s1->radius;
} else if (s1 and not(s2)) {
phys.maxPenetration=s1->radius * phys.Penetration1;
dist = s1->radius - geom.penetrationDepth;
OverlapRadius =pow((pow(s1->radius,2) - pow(dist,2)),(1.0/2.0));
contactRadius = s1->radius;
} else {
phys.maxPenetration=s2->radius * phys.Penetration2;
dist = s2->radius - geom.penetrationDepth;
OverlapRadius = pow((pow(s2->radius,2) - pow(dist,2)),(1.0/2.0));
contactRadius = s2->radius;
}
Vector3r& shearForce = phys.shearForce;
if (I->isFresh(scene)) shearForce=Vector3r(0,0,0);
const Real& dt = scene->dt;
shearForce = geom.rotate(shearForce);
// Handle periodicity.
const Vector3r shift2 = scene->isPeriodic ? scene->cell->intrShiftPos(I->cellDist): Vector3r::Zero();
const Vector3r shiftVel = scene->isPeriodic ? scene->cell->intrShiftVel(I->cellDist): Vector3r::Zero();
const Vector3r c1x = (geom.contactPoint - de1.pos);
const Vector3r c2x = (geom.contactPoint - de2.pos - shift2);
const Vector3r relativeVelocity = (de1.vel+de1.angVel.cross(c1x)) - (de2.vel+de2.angVel.cross(c2x)) + shiftVel;
const Real normalVelocity = geom.normal.dot(relativeVelocity);
const Vector3r shearVelocity = relativeVelocity-normalVelocity*geom.normal;
//Normal Force
Real OverlapArea;
Real MaxArea;
OverlapArea = 3.1415 * pow(OverlapRadius,2);
MaxArea = 3.1415 * pow(contactRadius,2);
Real Mult;
if(OverlapRadius < contactRadius){
Mult = OverlapArea / MaxArea;
}
else{
Mult = 1;
}
Real Fn;
if(geom.penetrationDepth>=0){
//Compression
if(normalVelocity>=0){
if (geom.penetrationDepth >= phys.maxPenetration){
Fn = phys.knI * (geom.penetrationDepth - phys.previousun) + phys.previousElasticN + phys.cnI * normalVelocity;
phys.previousElasticN += phys.knI * (geom.penetrationDepth - phys.previousun);
phys.normalForce = Fn * geom.normal;
phys.t = 0; phys.t2 = 0;
//phys.previousElasticTensionN = 0;
}
else{
Fn = Mult * phys.kn * (geom.penetrationDepth - phys.previousun) + Mult * phys.previousElasticN + phys.cn * normalVelocity;
phys.previousElasticN += Mult * phys.kn * (geom.penetrationDepth - phys.previousun);
phys.finalElasticN += Mult * phys.kn * (geom.penetrationDepth - phys.previousun);
phys.normalForce = Fn * geom.normal;
phys.t = 0; phys.t2 = 0;
//phys.previousElasticTensionN = 0;
}
}
//Tension
else if(normalVelocity<0){
if(phys.t == 0){
phys.maxNormalComp = - phys.finalElasticN;
//printf("------> %E \n", phys.maxNormalComp);
//.........这里部分代码省略.........
示例5: Push
void UI::Push(const shared_ptr<Panel> &panel)
{
panel->SetUI(this);
toPush.push_back(panel);
}
示例6: _addTagsToElement
void ServicesDbReader::_addTagsToElement(shared_ptr<Element> element)
{
bool ok;
Tags& tags = element->getTags();
if (tags.contains("hoot:status"))
{
QString statusStr = tags.get("hoot:status");
bool ok;
const int statusInt = statusStr.toInt(&ok);
Status status = static_cast<Status::Type>(statusInt);
if (ok && status.getEnum() >= Status::Invalid && status.getEnum() <= Status::Conflated)
{
element->setStatus(status);
}
else
{
LOG_WARN("Invalid status: " + statusStr + " for element with ID: " +
QString::number(element->getId()));
}
tags.remove("hoot:status");
}
if (tags.contains("type"))
{
Relation* r = dynamic_cast<Relation*>(element.get());
if (r)
{
r->setType(tags["type"]);
tags.remove("type");
}
}
if (tags.contains("error:circular"))
{
element->setCircularError(tags.get("error:circular").toDouble(&ok));
if (!ok)
{
try
{
double tv = tags.getLength("error:circular").value();
element->setCircularError(tv);
ok = true;
}
catch (const HootException& e)
{
ok = false;
}
if (!ok)
{
LOG_WARN("Error parsing error:circular.");
}
}
tags.remove("error:circular");
}
else if (tags.contains("accuracy"))
{
element->setCircularError(tags.get("accuracy").toDouble(&ok));
if (!ok)
{
try
{
double tv = tags.getLength("accuracy").value();
element->setCircularError(tv);
ok = true;
}
catch (const HootException& e)
{
ok = false;
}
if (!ok)
{
LOG_WARN("Error parsing accuracy.");
}
}
tags.remove("accuracy");
}
}
示例7: UIFrame
ContainerFrame::ContainerFrame(const Point& pos, shared_ptr<ResourceCtl> res, const std::string& title, shared_ptr<Inventory> inv)
: UIFrame(pos, inv->getSize().modMul(INVENTORY_ICON_SIZE).modAdd(20, 20), res, title) {
_inv = inv;
_contArea = make_shared<ContainerArea>(Point(10, 10 + _titleHeight), _inv->getSize(), this);
}
示例8: LOG_DEBUG
void ServicesDbReader::_readBounded(shared_ptr<OsmMap> map, const ElementType& elementType)
{
LOG_DEBUG("IN ServicesDbReader::readBounded(,)...");
long long lastId = LLONG_MIN;
shared_ptr<Element> element;
QStringList tags;
bool firstElement = true;
QStringList bboxParts = _bbox.split(",");
double minLat = bboxParts[1].toDouble();
double minLon = bboxParts[0].toDouble();
double maxLat = bboxParts[3].toDouble();
double maxLon = bboxParts[2].toDouble();
// determine is Services or Osm Api DB
ServicesDb::DbType connectionType = _database.getDatabaseType();
// contact the DB and select all
shared_ptr<QSqlQuery> elementResultsIterator = _database.selectBoundedElements(_osmElemId, elementType, _bbox);
// split the reading of Services and Osm Api DB upfront to avoid extra inefficiency of if-else calls
// inside the isActive loop
switch ( connectionType )
{
case ServicesDb::DBTYPE_SERVICES:
//need to check isActive, rather than next() here b/c resultToElement actually calls next() and
//it will always return an extra null node at the end, unfortunately (see comments in
//ServicesDb::resultToElement)
while (elementResultsIterator->isActive())
{
shared_ptr<Element> element =
_resultToElement(*elementResultsIterator, elementType, *map );
//this check is necessary due to an inefficiency in ServicesDb::resultToElement
if (element.get())
{
if (_status != Status::Invalid) { element->setStatus(_status); }
map->addElement(element);
}
}
break;
case ServicesDb::DBTYPE_OSMAPI:
// check if db active or not
assert(elementResultsIterator->isActive());
switch (elementType.getEnum())
{
///////////////////////////////////////////////////////////////////
// NODES
///////////////////////////////////////////////////////////////////
case ElementType::Node:
while( elementResultsIterator->next() )
{
long long id = elementResultsIterator->value(0).toLongLong();
if( lastId != id )
{
// process the complete element only after the first element created
if(!firstElement)
{
if(tags.size()>0)
{
element->setTags( ServicesDb::unescapeTags(tags.join(", ")) );
_addTagsToElement( element );
}
if (_status != Status::Invalid) { element->setStatus(_status); }
map->addElement(element);
tags.clear();
}
// extract the node contents except for the tags
element = _resultToNode_OsmApi(*elementResultsIterator, *map);
lastId = id;
firstElement = false;
}
// read the tag for as many rows as there are tags
// need to get into form "key1"=>"val1", "key2"=>"val2", ...
QString result = _database.extractTagFromRow_OsmApi(elementResultsIterator, elementType.getEnum());
if(result != "") tags << result;
}
// process the last complete element only if an element has been created
if(!firstElement)
{
if(tags.size()>0)
{
element->setTags( ServicesDb::unescapeTags(tags.join(", ")) );
_addTagsToElement( element );
}
if (_status != Status::Invalid) { element->setStatus(_status); }
map->addElement(element);
tags.clear();
}
break;
///////////////////////////////////////////////////////////////////
// WAYS
///////////////////////////////////////////////////////////////////
//.........这里部分代码省略.........
示例9: generateOrderFromCanceledOrder
//从撤单中生成新的报单
void Trader::generateOrderFromCanceledOrder(const shared_ptr<Order> &order){
shared_ptr<Order> newOrder = make_shared<Order>();
newOrder->moveToThread(QCoreApplication::instance()->thread());
newOrder->setInvestorId(order->getInvestorId());
newOrder->setStrategyId(order->getStrategyId());
newOrder->setInstructionId(order->getInstructionId());
newOrder->setInstrumentId(order->getInstrumentId());
newOrder->setDirection(order->getDirection());
newOrder->setOpenCloseFlag(order->getOpenCloseFlag());
double price = order->getPrice();
//获得该合约的最小价格变动单位,如果买则买价增加,如果卖则卖价减小
auto instruments = BackgroundTrader::getInstance()->getInstruments();
auto &info = instruments[order->getInstrumentId()];
double minPrice = info->getMinimumUnit();
if (order->getDirection() == 'b'){
price += minPrice;
}
else{
price -= minPrice;
}
newOrder->setPrice(price);
newOrder->setOriginalVolume(order->getRestVolume());
newOrder->setTradedVolume(0);
newOrder->setRestVolume(newOrder->getOriginalVolume());
newOrder->setOpenCloseFlag(order->getOpenCloseFlag());
newOrder->setOrderStatus('a');
if (newOrder->getOpenCloseFlag() == '1'){
//当收到平仓字段时对合约进行判断,如果是上海期货的合约则自动平今
if (info->getExchangeId() == "SHFE"){
splitSHFEOrder(newOrder, "0"); //限价单标志0
return;
}
}
//执行指令
executeOrder(newOrder, "0");
}
示例10: removeAllTags
void BooksDBUtil::removeAllTags(shared_ptr<Book> book) {
book->removeAllTags();
}
示例11: cloneTag
void BooksDBUtil::cloneTag(shared_ptr<Book> book, shared_ptr<Tag> from, shared_ptr<Tag> to, bool includeSubTags) {
if (book->cloneTag(from, to, includeSubTags)) {
BooksDB::Instance().saveTags(book);
}
}
示例12: print_trigger_effs
void print_trigger_effs(const shared_ptr<ProcessHistograms> & ph, const string & selection){
auto h = ph->get_histogram(selection, "lepton_trigger");
cout << "lepton trigger efficiency (w.r.t. offline lepton selection): " << h.histo->GetBinContent(2) / (h.histo->GetBinContent(1) + h.histo->GetBinContent(2)) << endl;
h = ph->get_histogram(selection, "lepton_triggermatch");
cout << "lepton trigger matching efficiency (after offline selection and trigger): " << h.histo->GetBinContent(2) / (h.histo->GetBinContent(1) + h.histo->GetBinContent(2))<< endl;
}
示例13: addElement
void UIFrame::addElement(shared_ptr<UIElement> el) {
el->setParent(this);
el->setZlevel(_zlevel + 1);
_elements.push_back(el);
}
示例14: dump_histo
void dump_histo(const shared_ptr<ProcessHistograms> & ph, const string & selection, const string & hname){
auto h = ph->get_histogram(selection, hname);
for(int i=1; i<=h.histo->GetNbinsX(); ++i){
cout << i << " (" << h.histo->GetXaxis()->GetBinLowEdge(i) << "--" << h.histo->GetXaxis()->GetBinUpEdge(i) << ")" << h.histo->GetBinContent(i) << endl;
}
}
示例15:
//----------
shared_ptr<NodeHost> Patch::addNewNode(shared_ptr<BaseFactory> factory, const ofRectangle & bounds) {
auto newNode = factory->makeUntyped();
newNode->init();
return this->addNode(newNode, bounds);
}