本文整理匯總了C++中tr1::shared_ptr類的典型用法代碼示例。如果您正苦於以下問題:C++ shared_ptr類的具體用法?C++ shared_ptr怎麽用?C++ shared_ptr使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
在下文中一共展示了shared_ptr類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的C++代碼示例。
示例1: deinterlaced_image
// This method is required for all derived classes of EffectBase, and returns a
// modified openshot::Frame object
tr1::shared_ptr<Frame> Deinterlace::GetFrame(tr1::shared_ptr<Frame> frame, int frame_number)
{
// Get original size of frame's image
int original_width = frame->GetImage()->width();
int original_height = frame->GetImage()->height();
// Get the frame's image
tr1::shared_ptr<QImage> image = frame->GetImage();
const unsigned char* pixels = image->bits();
// Create a smaller, new image
QImage deinterlaced_image(image->width(), image->height() / 2, QImage::Format_RGBA8888);
const unsigned char* deinterlaced_pixels = deinterlaced_image.bits();
// Loop through the scanlines of the image (even or odd)
int start = 0;
if (isOdd)
start = 1;
for (int row = start; row < image->height(); row += 2) {
memcpy((unsigned char*)deinterlaced_pixels, pixels + (row * image->bytesPerLine()), image->bytesPerLine());
deinterlaced_pixels += image->bytesPerLine();
}
// Resize deinterlaced image back to original size, and update frame's image
image = tr1::shared_ptr<QImage>(new QImage(deinterlaced_image.scaled(original_width, original_height, Qt::IgnoreAspectRatio, Qt::FastTransformation)));
// Update image on frame
frame->AddImage(image);
// return the modified frame
return frame;
}
示例2:
unsigned long long CCachedAffairMap::Static_PushNewAffair_Pre(map<unsigned long long, tr1::shared_ptr<CCachedAffair> >& cachedMap, CCachedAffairMapLock &Lock
, tr1::shared_ptr<CCachedAffair> pCachedAffairItem, long nOutSeqId, int nOutCmdId, int nExpetedCmdId)//
{
if(((!!(pCachedAffairItem->m_fpOnGotData)) ^ (!!(pCachedAffairItem->m_fpOnAffairOverTime))))
{
//同時有,同時沒有才正確
return -2;
}
pCachedAffairItem->SetSequencePair(nOutSeqId);
pCachedAffairItem->SetCommandIdxPair(nOutCmdId,nExpetedCmdId);
//unsigned long long AffairId=0;
{
//縮小加鎖範圍
///AffairId = nOutSeqId;//JT_AMIOC_ADD(m_lastSeq,1);//使用外部的nOutSeqId,因為處理時可能涉及批量
//if(AffairId==0)
// AffairId = JT_AMIOC_ADD(m_lastSeq,1);
Lock.LockMap();
cachedMap[nOutSeqId] = pCachedAffairItem;
Lock.UnLockMap();
}
return nOutSeqId;
}
示例3: output
tr1::shared_ptr<AbstractNumber> E::divide(tr1::shared_ptr<AbstractNumber>number){
char newSign = '-';
if (getSign() == number->getSign())
{
newSign = '+';
}
if (number -> getName() == "E")
{
if (newSign == '+')
{
tr1::shared_ptr<AbstractNumber> output(new SmartInteger(1));
return output;
}
else
{
tr1::shared_ptr<AbstractNumber> output(new SmartInteger(-1));
return output;
}
}
else if (number -> getName() == "Exponent")
{
tr1::shared_ptr<Exponent> numExp = tr1::static_pointer_cast<Exponent>(number);
if (numExp -> getValue("base") -> getName() == "E")
{
tr1::shared_ptr<AbstractNumber> num(new SmartInteger(1));
tr1::shared_ptr<AbstractNumber> exp = number->getValue("power");
tr1::shared_ptr<AbstractNumber> exp2(new SmartInteger(-1));
tr1::shared_ptr<AbstractNumber> me(new E());
tr1::shared_ptr<AbstractNumber> ans2(new Exponent(me, exp -> add(exp2), newSign));
tr1::shared_ptr<AbstractNumber> output2(new MultExpression(num, ans2, '+'));
return output2;
}
}
else if(number->getName() == "MultExpression")
{
tr1::shared_ptr<MultExpression> MultE = tr1::static_pointer_cast<MultExpression>(number);
vector<tr1::shared_ptr<AbstractNumber> > MultENum = MultE->getNumerator();
vector<tr1::shared_ptr<AbstractNumber> > MultEDem = MultE->getDenominator();
if (MultEDem.size() == 0)
{
tr1::shared_ptr<AbstractNumber> one(new SmartInteger(1));
MultEDem.push_back(one);
}
tr1::shared_ptr<AbstractNumber> reversedMultE(new MultExpression(MultEDem, MultENum, number->getSign()));
return reversedMultE->multiply(shared_from_this());
}
tr1::shared_ptr<AbstractNumber> output2(new MultExpression(shared_from_this(), number, newSign));
return output2;
}
示例4: task
inline saga::task
dispatch_async (proxy * prxy,
TR1::shared_ptr <adaptor_selector_state> state,
void (Base::*sync_) (RetVal &, BOOST_PP_ENUM_PARAMS (K, FuncArg)),
saga::task (Base::*async_) ( BOOST_PP_ENUM_PARAMS (K, FuncArg)),
BOOST_PP_ENUM_BINARY_PARAMS (K, Arg, const & arg),
bool (Base::*prep_) (RetVal &, BOOST_PP_ENUM_PARAMS(K, FuncArg), saga::uuid) = NULL)
{
typedef void (Base::*sync_func )(RetVal&, BOOST_PP_ENUM_PARAMS(K, FuncArg));
typedef saga::task (Base::*async_func)( BOOST_PP_ENUM_PARAMS(K, FuncArg));
typedef bool (Base::*prep_func )(RetVal&, BOOST_PP_ENUM_PARAMS(K, FuncArg), saga::uuid);
void (Base::*sync )() = NULL;
saga::task (Base::*async)() = NULL;
bool (Base::*prep )() = NULL;
run_mode mode = Unknown;
TR1::shared_ptr<Base> c (
state->get_next_cpi (mode, &sync, &async, &prep));
// BOOST_ASSERT(NULL == sync || (sync_func) sync == sync_ );
// BOOST_ASSERT(NULL == async || (async_func) async == async_);
// BOOST_ASSERT(NULL == prep || (prep_func) prep == prep_ );
switch (mode) {
case Async_Sync:
BOOST_ASSERT(sync);
return async_sync(prxy, c, state, (sync_func)sync,
BOOST_PP_ENUM_PARAMS(K, arg), (prep_func)prep);
case Async_Async:
BOOST_ASSERT(async);
return async_async(c, state, (async_func)async,
BOOST_PP_ENUM_PARAMS(K, arg));
case Sync_Sync:
case Sync_Async:
BOOST_ASSERT(false);
break;
default:
break;
}
// no adaptor found (Invalid mode)!
SAGA_THROW_VERBATIM(c.get(),
std::string ("No adaptor implements method: ") + state->get_op_name(),
adaptors::NoAdaptor);
// this makes some compilers happy, but will never be called in fact
// (didn't you see the throw above?)
return saga::task(saga::task_base::Done);
}
示例5: r
// Multiplies number by this and returns the product
//
// Parameters:
// shared_ptr<AbstractNumber> number number being multiplied
//
// Returns:
// shared_ptr<AbstractNumber> resulting product of multiplication
tr1::shared_ptr<AbstractNumber> Exponent::multiply(tr1::shared_ptr<AbstractNumber> number){
// Checks for simplification if both exponents
number = number->simplify();
if(number->getName() == "Exponent"){
tr1::shared_ptr<Exponent> givenNumber = tr1::static_pointer_cast<Exponent>(number);
if(abs(givenNumber->getValue("base")->toDouble() - base->toDouble()) < 0.000001){
tr1::shared_ptr<AbstractNumber> r(new Exponent(base, power->add(givenNumber->getValue("power")), this->calcSign(number)));
return r;
}
else if (number->getName() == "Radical") {
if (abs(number->getValue("value")->toDouble() - base->toDouble()) < 0.000001 )
{
std::vector< tr1::shared_ptr<AbstractNumber> > SumVector;
tr1::shared_ptr<AbstractNumber> one(new SmartInteger(1));
tr1::shared_ptr<AbstractNumber> invertedRoot(new MultExpression(one, number->getValue("root")->noSign(), number->getValue("root")->getSign()));
SumVector.push_back(power);
SumVector.push_back(invertedRoot);
tr1::shared_ptr<AbstractNumber> power(new SumExpression(SumVector));
tr1::shared_ptr<AbstractNumber> output(new Exponent(number->getValue("value")->noSign(), power, sign));
return output;
}
}
else{
tr1::shared_ptr<AbstractNumber> me(new Exponent(base, power, sign));
tr1::shared_ptr<AbstractNumber> r(new MultExpression(me, number, this->calcSign(number)));
return r;
}
}
// Checks for simplification if number = base
// Adds 1 to exponent
else if(abs(number->toDouble() - base->toDouble()) < 0.000001 ){
tr1::shared_ptr<AbstractNumber> c(new SmartInteger(1));
tr1::shared_ptr<AbstractNumber> r(new Exponent(base, power->add(c), this->calcSign(number)));
return r;
}
else if(number->getName() == "SumExpression" || number->getName() == "MultExpression")
{
return number->multiply(shared_from_this());
}
vector< tr1::shared_ptr<AbstractNumber> > MultVector;
tr1::shared_ptr<AbstractNumber> me(new Exponent(base, power, sign));
MultVector.push_back(me);
MultVector.push_back(number);
tr1::shared_ptr<AbstractNumber> r(new MultExpression(MultVector, '+'));
return r;
}
示例6: sync_sync
inline saga::task
dispatch_sync (run_mode mode,
char const * name,
TR1::shared_ptr<v1_0::cpi> cpi_instance,
void (Base::*sync ) (RetVal &, BOOST_PP_ENUM_PARAMS (K, FuncArg)),
saga::task (Base::*async) ( BOOST_PP_ENUM_PARAMS (K, FuncArg)),
BOOST_PP_ENUM_BINARY_PARAMS (K, Arg, const & arg))
{
TR1::shared_ptr<Base> c = TR1::static_pointer_cast<Base>(cpi_instance);
switch (mode) {
case Sync_Sync:
return sync_sync(c, sync, BOOST_PP_ENUM_PARAMS(K, arg));
case Sync_Async:
return sync_async(c, async, BOOST_PP_ENUM_PARAMS(K, arg));
case Async_Sync:
case Async_Async:
BOOST_ASSERT(false);
break;
default:
break;
}
// no adaptor found (Invalid mode)!
SAGA_THROW_VERBATIM(cpi_instance.get(),
std::string ("No adaptor implements method: ") + name,
adaptors::NoAdaptor);
return saga::task(saga::task_base::Done);
}
示例7:
// This method is required for all derived classes of EffectBase, and returns a
// modified openshot::Frame object
tr1::shared_ptr<Frame> ChromaKey::GetFrame(tr1::shared_ptr<Frame> frame, int frame_number)
{
// Determine the current HSL (Hue, Saturation, Lightness) for the Chrome
int threshold = fuzz.GetInt(frame_number);
long mask_R = color.red.GetInt(frame_number);
long mask_G = color.green.GetInt(frame_number);
long mask_B = color.blue.GetInt(frame_number);
// Get source image's pixels
tr1::shared_ptr<QImage> image = frame->GetImage();
unsigned char *pixels = (unsigned char *) image->bits();
// Loop through pixels
for (int pixel = 0, byte_index=0; pixel < image->width() * image->height(); pixel++, byte_index+=4)
{
// Get the RGB values from the pixel
unsigned char R = pixels[byte_index];
unsigned char G = pixels[byte_index + 1];
unsigned char B = pixels[byte_index + 2];
unsigned char A = pixels[byte_index + 3];
// Get distance between mask color and pixel color
long distance = Color::GetDistance((long)R, (long)G, (long)B, mask_R, mask_G, mask_B);
// Alpha out the pixel (if color similar)
if (distance <= threshold)
// MATCHED - Make pixel transparent
pixels[byte_index + 3] = 0;
}
// return the modified frame
return frame;
}
示例8: vpath
bool
commit::isCommitPathEffective(Cstore& cs, const Cpath& pcomps,
tr1::shared_ptr<Ctemplate> def,
bool in_active, bool in_working)
{
if (in_active && in_working) {
// remain the same
return true;
}
if (!in_active && !in_working) {
// doesn't exist
return false;
}
// at this point, in_active corresponds to "being deleted"
if (def->isTagNode()) {
// special handling for tag nodes, which are never marked
vector<string> tvals;
// get tag values from active or working config
cs.cfgPathGetChildNodes(pcomps, tvals, in_active);
Cpath vpath(pcomps);
/* note that there should be at least 1 tag value since tag node
* cannot exist without tag value.
*/
for (size_t i = 0; i < tvals.size(); i++) {
vpath.push(tvals[i]);
if (in_active) {
// being deleted => all tag values are being deleted
if (!cs.cfgPathMarkedCommitted(vpath, true)) {
/* a tag value is not marked committed
* => a tag value has not been deleted
* => tag node has not been deleted
* => still effective
*/
return true;
}
} else {
// being added => all tag values are being added
if (cs.cfgPathMarkedCommitted(vpath, false)) {
/* a tag value is marked committed
* => a tag value has been added
* => tag node has been added
* => already effective
*/
return true;
}
}
vpath.pop();
}
// not effective
return false;
}
/* if not tag node, effectiveness corresponds to committed marking:
* if deleted (i.e., in_active), then !marked is effective
* otherwise (i.e., added), marked is effective
*/
bool marked = cs.cfgPathMarkedCommitted(pcomps, in_active);
return (in_active ? !marked : marked);
}
示例9: AddImage
// Add (or replace) pixel data to the frame (for only the odd or even lines)
void Frame::AddImage(tr1::shared_ptr<QImage> new_image, bool only_odd_lines)
{
// Ignore blank new_image
if (!new_image)
return;
// Check for blank source image
if (!image) {
// Replace the blank source image
AddImage(new_image);
} else {
// Ignore image of different sizes or formats
if (image == new_image || image->size() != image->size() || image->format() != image->format())
return;
// Get the frame's image
const unsigned char *pixels = image->bits();
const unsigned char *new_pixels = new_image->bits();
// Loop through the scanlines of the image (even or odd)
int start = 0;
if (only_odd_lines)
start = 1;
for (int row = start; row < image->height(); row += 2) {
memcpy((unsigned char *) pixels, new_pixels + (row * image->bytesPerLine()), image->bytesPerLine());
new_pixels += image->bytesPerLine();
}
// Update height and width
width = image->width();
height = image->height();
}
}
示例10: SendConsoleText
void ConsoleHandler::SendConsoleText(HANDLE hStdIn, const tr1::shared_ptr<wchar_t>& textBuffer)
{
wchar_t* pszText = textBuffer.get();
size_t textLen = wcslen(pszText);
size_t partLen = 512;
size_t parts = textLen/partLen;
size_t offset = 0;
for (size_t part = 0; part < parts+1; ++part)
{
size_t keyEventCount = 0;
if (part == parts)
{
// last part, modify part size
partLen = textLen - parts*partLen;
}
scoped_array<INPUT_RECORD> pKeyEvents(new INPUT_RECORD[partLen]);
::ZeroMemory(pKeyEvents.get(), sizeof(INPUT_RECORD)*partLen);
for (size_t i = 0; (i < partLen) && (offset < textLen); ++i, ++offset, ++keyEventCount)
{
if ((pszText[offset] == L'\r') || (pszText[offset] == L'\n'))
{
if ((pszText[offset] == L'\r') && (pszText[offset+1] == L'\n')) ++offset;
if (keyEventCount > 0)
{
DWORD dwTextWritten = 0;
::WriteConsoleInput(hStdIn, pKeyEvents.get(), static_cast<DWORD>(keyEventCount), &dwTextWritten);
}
::PostMessage(m_consoleParams->hwndConsoleWindow, WM_KEYDOWN, VK_RETURN, 0x001C0001);
::PostMessage(m_consoleParams->hwndConsoleWindow, WM_KEYUP, VK_RETURN, 0xC01C0001);
keyEventCount = static_cast<size_t>(-1);
partLen -= i;
i = static_cast<size_t>(-1);
}
else
{
pKeyEvents[i].EventType = KEY_EVENT;
pKeyEvents[i].Event.KeyEvent.bKeyDown = TRUE;
pKeyEvents[i].Event.KeyEvent.wRepeatCount = 1;
pKeyEvents[i].Event.KeyEvent.wVirtualKeyCode = LOBYTE(::VkKeyScan(pszText[offset]));
pKeyEvents[i].Event.KeyEvent.wVirtualScanCode = 0;
pKeyEvents[i].Event.KeyEvent.uChar.UnicodeChar = pszText[offset];
pKeyEvents[i].Event.KeyEvent.dwControlKeyState = 0;
}
}
if (keyEventCount > 0)
{
DWORD dwTextWritten = 0;
::WriteConsoleInput(hStdIn, pKeyEvents.get(), static_cast<DWORD>(keyEventCount), &dwTextWritten);
}
}
}
示例11:
inline saga::task
sync_async (TR1::shared_ptr <Cpi> cpi,
saga::task (Base::*async)(BOOST_PP_ENUM_PARAMS (K, FuncArg)),
BOOST_PP_ENUM_BINARY_PARAMS (K, Arg, const & arg))
{
return saga::detail::run_wait(
(cpi.get()->*async)(BOOST_PP_ENUM_PARAMS(K, arg)));
}
示例12: calcSign
// Returns char identifying sign resulting from multiplication or division of two numbers
//
// Returns:
// char '+' or '-'
char Exponent::calcSign(tr1::shared_ptr<AbstractNumber> number){
if(sign == number->getSign()){
return '+';
}
else{
return '-';
}
}
示例13: QImage
// Get pointer to QImage of frame
void Frame::AddMagickImage(tr1::shared_ptr<Magick::Image> new_image)
{
const int BPP = 4;
const std::size_t bufferSize = new_image->columns() * new_image->rows() * BPP;
/// Use realloc for fast memory allocation.
/// TODO: consider locking the buffer for mt safety
//qbuffer = reinterpret_cast<unsigned char*>(realloc(qbuffer, bufferSize));
qbuffer = new unsigned char[bufferSize]();
unsigned char *buffer = (unsigned char*)qbuffer;
// Iterate through the pixel packets, and load our own buffer
// Each color needs to be scaled to 8 bit (using the ImageMagick built-in ScaleQuantumToChar function)
int numcopied = 0;
Magick::PixelPacket *pixels = new_image->getPixels(0,0, new_image->columns(), new_image->rows());
for (int n = 0, i = 0; n < new_image->columns() * new_image->rows(); n += 1, i += 4) {
buffer[i+0] = MagickCore::ScaleQuantumToChar((Magick::Quantum) pixels[n].red);
buffer[i+1] = MagickCore::ScaleQuantumToChar((Magick::Quantum) pixels[n].green);
buffer[i+2] = MagickCore::ScaleQuantumToChar((Magick::Quantum) pixels[n].blue);
buffer[i+3] = 255 - MagickCore::ScaleQuantumToChar((Magick::Quantum) pixels[n].opacity);
numcopied+=4;
}
// Create QImage of frame data
image = tr1::shared_ptr<QImage>(new QImage(qbuffer, width, height, width * BPP, QImage::Format_RGBA8888, (QImageCleanupFunction) &cleanUpBuffer, (void*) qbuffer));
// Update height and width
width = image->width();
height = image->height();
}
示例14:
int AdaBoost2::create_one_weak_classifier(tr1::shared_ptr<WeakClassifier> wc)
{
// tr1::shared_ptr<WeakClassifier> wc(new WeakClassifier(feature_type));
uint64 feature_type;
wc->feature_type(feature_type);
m_all_weak_classifiers.insert(pair<uint64, tr1::shared_ptr<WeakClassifier> >(feature_type, wc));
return 0;
}
示例15: two
tr1::shared_ptr<AbstractNumber> E::add(tr1::shared_ptr<AbstractNumber>number){
if (number -> getName() == "E")
{
if (number -> getSign() == '+' && getSign() == '+')
{
vector<tr1::shared_ptr<AbstractNumber> > M;
tr1::shared_ptr<AbstractNumber> two(new SmartInteger(2));
M.push_back(two);
M.push_back(shared_from_this());
tr1::shared_ptr<AbstractNumber> output(new MultExpression(M, '+'));
return output;
}
else if (number -> getSign() == '-' && getSign() == '-')
{
vector<tr1::shared_ptr<AbstractNumber> > N;
tr1::shared_ptr<AbstractNumber> twoN(new SmartInteger(-2));
N.push_back(twoN);
tr1::shared_ptr<AbstractNumber> me(new E());
N.push_back(me);
tr1::shared_ptr<AbstractNumber> output1(new MultExpression(N, '+'));
return output1;
}
else
{
tr1::shared_ptr<AbstractNumber> zero(new SmartInteger(0));
return zero;
}
}
else if(number->getName() == "MultExpression" || number->getName() == "SumExpression")
{
return number->add(shared_from_this());
}
vector<tr1::shared_ptr<AbstractNumber> > N;
N.push_back(number);
N.push_back(shared_from_this());
tr1::shared_ptr<AbstractNumber> output1(new SumExpression(N));
return output1;
}