weak_ptr<TTrieNode> TStaticTemplateMatcher::moveto(weak_ptr<TTrieNode> node, char symbol) {
	if (node.lock() == sink)
		return weak_ptr<TTrieNode>(getroot());
	if (node.lock()->isEdge(symbol))
		return weak_ptr<TTrieNode>(node.lock()->next(symbol));
	return moveto(suf_link_move(node),symbol);
}
void FieldController::SwapCells(weak_ptr<CrystalController> wcell1, weak_ptr<CrystalController> wcell2)
{
	m_glow.lock()->SetEnabled(false);
	m_swapped1 = wcell1;
	m_swapped2 = wcell2;

	auto cell1 = wcell1.lock();
	auto cell2 = wcell2.lock();

	int x = cell1->m_cellX;
	int y = cell1->m_cellY;

	printf("swapping cells[x,y]: [%d,%d] and [%d,%d] \n", cell1->m_cellX, cell1->m_cellY, cell2->m_cellX, cell2->m_cellY);

	cell1->m_cellX = cell2->m_cellX;
	cell1->m_cellY = cell2->m_cellY;


	cell2->m_cellX = x;
	cell2->m_cellY = y;


	m_cells[cell1->m_cellY][cell1->m_cellX] = wcell1;
	m_cells[cell2->m_cellY][cell2->m_cellX] = wcell2;

}
static QGpgMEVerifyOpaqueJob::result_type verify_opaque( Context * ctx, QThread * thread, const weak_ptr<QIODevice> & signedData_, const weak_ptr<QIODevice> & plainText_ ) {

  const shared_ptr<QIODevice> plainText = plainText_.lock();
  const shared_ptr<QIODevice> signedData = signedData_.lock();

  const _detail::ToThreadMover ptMover( plainText,  thread );
  const _detail::ToThreadMover sdMover( signedData, thread );

  QGpgME::QIODeviceDataProvider in( signedData );
  const Data indata( &in );

  if ( !plainText ) {
    QGpgME::QByteArrayDataProvider out;
    Data outdata( &out );

    const VerificationResult res = ctx->verifyOpaqueSignature( indata, outdata );
    Error ae;
    const QString log = _detail::audit_log_as_html( ctx, ae );
    return make_tuple( res, out.data(), log, ae );
  } else {
    QGpgME::QIODeviceDataProvider out( plainText );
    Data outdata( &out );

    const VerificationResult res = ctx->verifyOpaqueSignature( indata, outdata );
    Error ae;
    const QString log = _detail::audit_log_as_html( ctx, ae );
    return make_tuple( res, QByteArray(), log, ae );
  }

}
Esempio n. 4
0
void pimpl<PortalsImporterJob>::run()
{
    m_result.reset();

    m_status = String::EMPTY;

    if(m_stream != nullptr)
    {
        shared_ptr<Portal> portal = m_portal.lock();
        if(portal == nullptr || m_stream == nullptr)
            return;

        m_status = "importing";

        m_serializer->setStopped(false);
        m_result = m_serializer->importStream(portal, m_stream);
        m_stream->close();
        m_stream.reset();
    }
    else
    {
        m_status = "download";

        shared_ptr<boost::asio::io_service> service = createAsioService();
        shared_ptr<TCPSocket> socket = Engine::instance()->createTCPSocket(service, true, true);
        shared_ptr<HttpClient> httpClient(OS_NEW HttpClient(service, socket));

        HttpUrl url(m_url.to_ascii());
        bool result = httpClient->perform(url);

        if(result)
        {
            shared_ptr<HttpResponse> response = httpClient->getResponse();

            //shared_ptr<HttpContent> responseContent = response->getContent();

            if(response->getStatusCode() == 200)
            {
                m_status = "importing";

                shared_ptr<MemFile> content(OS_NEW MemFile(response->getContent()->getContentPtr()));

                shared_ptr<Portal> portal = m_portal.lock();
                if(portal == nullptr)
                    return;

                m_serializer->setStopped(false);
                m_result = m_serializer->importStream(portal, content);
            }

            m_status = "completed";
        }
        else
        {
            m_status = "failed";
        }
    }

    //Engine::instance()->addBackgroundJob(shared_ptr<PortalsOptimizerJob>(OS_NEW PortalsOptimizerJob(Engine::instance()->peekBackgroundJobID(), portal)));
}
static bool __cdecl alphabeticalG3DLast(weak_ptr<Texture> const& elem1, weak_ptr<Texture> const& elem2) {
    const shared_ptr<Texture>& elem1Locked = elem1.lock();
    const shared_ptr<Texture>& elem2Locked = elem2.lock();

    if (isNull(elem1Locked)) {
        return true;
    } else if (isNull(elem2Locked)) {
        return false;
    } else {
        return alphabeticalIgnoringCaseG3DLastLessThan(elem1Locked->name(), elem2Locked->name());
    }
}
static bool __cdecl alphabeticalTextureLT(weak_ptr<Texture> const& elem1, weak_ptr<Texture> const& elem2) {
    const shared_ptr<Texture>& elem1Locked = elem1.lock();
    const shared_ptr<Texture>& elem2Locked = elem2.lock();

    if (isNull(elem1Locked)) {
        return true;
    } else if (isNull(elem2Locked)) {
        return false;
    } else {
        return elem1Locked->name() < elem2Locked->name();
    }
}
Esempio n. 7
0
    /**
     * Returns true if P is part of the parent chain from this pose.
     */
    bool isParentPose(const shared_ptr< const self >& P) const {
      if(Parent.expired()) {
	if(P)
	  return true;
	else
	  return false;
      } else {
	if(P)
	  return false;
	else if(P == Parent.lock())
          return true;
	else
	  return Parent.lock()->isParentPose(P);
      };
    };
Esempio n. 8
0
 /**
  * Returns this 2D pose relative to pose P.
  */
 self getPoseRelativeTo(const shared_ptr< const self >& P) const {
   if(!P)
     return getGlobalPose();
   if(isParentPose(P)) {
     if(Parent.lock() == P)
       return *this;
     else
       return Parent.lock()->getPoseRelativeTo(P) * (*this);
   } else if(P->isParentPose( rtti::rk_static_ptr_cast< const self >(mThis)))
     return ~(P->getPoseRelativeTo( rtti::rk_static_ptr_cast< const self >(mThis)));
   else if(Parent.expired())
     return (~(P->getGlobalPose())) * (*this);
   else
     return Parent.lock()->getPoseRelativeTo(P) * (*this);
 };
Esempio n. 9
0
uint32_t BusinessPool::DelTermSession(weak_ptr<TermSession> ts)
{
    shared_ptr<TermSession> sp_ts(ts.lock());
    if (!sp_ts) {
        logger_.Warn("[删除终端会话]******对应的终端会话不存在******");
        return 0;
    }

    CASession *cs = sp_ts->ca_session_;

    if (cs == NULL) {
        logger_.Warn("[删除终端会话]******对应的CA会话不存在******");
        return 0;
    }

    cs->Remove(sp_ts->Id());
    logger_.Warn("[删除终端会话][CAId:" SFMT64U "][TSId:0x" SFMT64X "]", cs->Id(), sp_ts->Id());

    CASessionMgr *cs_mgr = pool_relation_ca_session_mgr_[getIdByTermSessionId(sp_ts->Id())];
    cs_mgr->DetachTermSessionInfo(sp_ts->Id());

    uint32_t ret = cs->termCnt();

    //if no terminal session in ca session,
    // remove ca session.
    if (cs->termCnt() == 0) {
        logger_.Warn("[删除终端会话][CAId:" SFMT64U "][TSId:0x" SFMT64X "],CA会话中无终端,删除CA会话", cs->Id(), sp_ts->Id());
        CASessionMgr *cs_mgr = pool_relation_ca_session_mgr_[getIdByTermSessionId(sp_ts->Id())];
        cs_mgr->Detach(cs->Id());
        cs_mgr->Destory(cs);    
    }

    return ret;
}
Esempio n. 10
0
 void RemoveFromParent()
 {
     if( auto p = Parent.lock() )
     {
         p->RemoveChild( shared_from_this() );
     }
 }
Esempio n. 11
0
	void MyFather() {
		auto father = father_.lock();
		if (father)
			cout << father->name_ << " is MyFather\n"; 
		else
			cout << "father is gone\n";
	}
Esempio n. 12
0
void VRPhysicsManager::updatePhysics( weak_ptr<VRThread>  wthread) {
    if (dynamicsWorld == 0) return;
    long long dt,t0,t1,t2,t3;
    auto thread = wthread.lock();
    if (thread == 0) return;
    t0 = thread->t_last;
    t1 = getTime();
    thread->t_last = t1;
    dt = t1-t0;

    {
        MLock lock(mtx);
        prepareObjects();
        for (auto f : updateFktsPre) (*f)(0);
        dynamicsWorld->stepSimulation(1e-6*dt, 30);
        for (auto f : updateFktsPost) (*f)(0);
    }

    t2 = getTime();
    dt = t2-t1;

    //sleep up to 500 fps
    if (dt < PHYSICS_THREAD_TIMESTEP_MS * 1000) this_thread::sleep_for(chrono::microseconds(PHYSICS_THREAD_TIMESTEP_MS * 1000 -dt));
    t3 = getTime();

    MLock lock(mtx);
    fps = 1e6/(t3-t1);

}
Esempio n. 13
0
static CDisplayPtr GetGlobalDisplay()
{
  static weak_ptr<CDisplay> display_global;

  CDisplayPtr display(display_global.lock());
  if(display)
  {
    if(display->lost())
    {
      CLog::Log(LOGERROR, "VAAPI - vaapi display is in lost state");
      display.reset();
    }    
    return display;
  }

  VADisplay disp;
  disp = vaGetDisplayGLX(g_Windowing.GetDisplay());

  int major_version, minor_version;
  VAStatus res = vaInitialize(disp, &major_version, &minor_version);

  if(res != VA_STATUS_SUCCESS)
  {
    CLog::Log(LOGERROR, "VAAPI - unable to initialize display %d - %s", res, vaErrorStr(res));
    return display;
  }

  CLog::Log(LOGDEBUG, "VAAPI - initialize version %d.%d", major_version, minor_version);
  display = CDisplayPtr(new CDisplay(disp));
  display_global = display;
  return display;
}
Esempio n. 14
0
Factory::Factory(weak_ptr<RootObject> root)
{
    _root = root;
    if (!root.expired() && root.lock()->getType() == "scene")
        _isScene = true;

    registerObjects();
}
Esempio n. 15
0
void TimeOutTimer::Add(weak_ptr<TermSession> ts)
{
	shared_ptr<TermSession> sp_ts(ts.lock());
	if (sp_ts) {
		MutexLock lock(mutex_);
		termsession_list_[sp_ts->Id()] = sp_ts;
	}
}
Esempio n. 16
0
void load( Archive& archive, int mode, const char* name, weak_ptr<Type>& object )
{
    SWEET_ASSERT( mode == MODE_REFERENCE );
    SWEET_ASSERT( object.lock() == ptr<Type>() );

    ObjectGuard<Archive> guard( archive, name, 0, MODE_REFERENCE );
    archive.reference( archive.get_address(), reinterpret_cast<void**>(&object), &resolver<weak_ptr<Type> >::resolve );
}
Esempio n. 17
0
  inline shared_ptr<System> MultiSystemAccess::getSystem2() const {
 
    if (mySystem2.expired()) {
       throw std::runtime_error("expired system2");
    }

    return mySystem2.lock();
  }
Esempio n. 18
0
 virtual void RK_CALL save(ReaK::serialization::oarchive& A, unsigned int) const {
   if(Parent.expired())
     A & RK_SERIAL_SAVE_WITH_ALIAS("Parent",shared_ptr<serialization::serializable>());
   else
     A & RK_SERIAL_SAVE_WITH_ALIAS("Parent",Parent.lock());
   A & RK_SERIAL_SAVE_WITH_NAME(Position)
     & RK_SERIAL_SAVE_WITH_NAME(Rotation);
 };
Esempio n. 19
0
    void show() {
        shared_ptr<Team> t = team.lock();
        if (!t) {
            cout << "Team not found" << endl;
            return;
        }

        cout << name << " in " << t->name << endl;
    }
Esempio n. 20
0
 static void decrease(weak_ptr<Battalion>& battalion, Soldier *soldier)
 {
   shared_ptr<Battalion> sp = battalion.lock();
   if (sp)
   {
     cout << soldier->getName() << "已经壮烈牺牲了!" << endl;
     sp->reduce();
   }
 }
Esempio n. 21
0
inline shared_ptr<vector<string>>
StrBlobPtr::check(size_t i, const string &msg) const {
    auto ret = wptr.lock();
    if (!ret)
        throw runtime_error("unbound StrBlobPtr");
    if (i >= ret->size())
        throw out_of_range(msg);
    return ret;
}
Esempio n. 22
0
shared_ptr<vector<string>> const_str_blob_ptr::check(vector<string>::size_type i,const string &msg)const
{
   shared_ptr<vector<string>> ret = wptr.lock();
   if(!ret)
       throw runtime_error("unbound const_str_blob_ptr");
   if(i > ret->size())
       throw out_of_range(msg);
   return ret;
}
Esempio n. 23
0
 /**
  * Returns this 2D pose relative to the global (null) coordinate system.
  */
 self getGlobalPose() const {
   if(!Parent.expired()) {
     self result = Parent.lock()->getGlobalPose();
     result.Position += result.Rotation * Position;
     result.Rotation *= Rotation;
     return result;
   } else
     return *this;
 };
Esempio n. 24
0
	/**
	 * Extracts the next timestamp from a Timer.
	 *
	 * Note: Caller must hold l_Mutex.
	 *
	 * @param wtimer Weak pointer to the timer.
	 * @returns The next timestamp
	 */
	double operator()(const weak_ptr<Timer>& wtimer)
	{
		Timer::Ptr timer = wtimer.lock();

		if (!timer)
			return 0;

		return timer->m_Next;
	}
Esempio n. 25
0
void useResource(weak_ptr<Simple>& weakSimple)
{
	auto resource = weakSimple.lock();
	if (resource) {
		cout << "Resource still alive." << endl;
	} else {
		cout << "Resource has been freed!" << endl;
	}
}
Esempio n. 26
0
void
AccessStrategy::afterRtoTimeout(weak_ptr<pit::Entry> pitWeak, weak_ptr<fib::Entry> fibWeak,
                                FaceId inFace, FaceId firstOutFace)
{
  shared_ptr<pit::Entry> pitEntry = pitWeak.lock();
  BOOST_ASSERT(pitEntry != nullptr);
  // pitEntry can't become nullptr, because RTO timer should be cancelled upon pitEntry destruction

  shared_ptr<fib::Entry> fibEntry = fibWeak.lock();
  if (fibEntry == nullptr) {
    NFD_LOG_DEBUG(pitEntry->getInterest() << " timeoutFrom " << firstOutFace << " fib-gone");
    return;
  }

  NFD_LOG_DEBUG(pitEntry->getInterest() << " timeoutFrom " << firstOutFace <<
                " multicast-except " << inFace << ',' << firstOutFace);
  this->multicast(pitEntry, fibEntry, {inFace, firstOutFace});
}
	/**
	 * The entry point of the thread that handles the client connection.
	 */
	void threadMain(const weak_ptr<Client> self) {
		vector<string> args;
		try {
			while (!this_thread::interruption_requested()) {
				try {
					if (!channel.read(args)) {
						// Client closed connection.
						break;
					}
				} catch (const SystemException &e) {
					P_TRACE(2, "Exception in ApplicationPoolServer client thread during "
						"reading of a message: " << e.what());
					break;
				}

				P_TRACE(4, "Client " << this << ": received message: " <<
					toString(args));
				
				if (args[0] == "get" && args.size() == 7) {
					processGet(args);
				} else if (args[0] == "close" && args.size() == 2) {
					processClose(args);
				} else if (args[0] == "clear" && args.size() == 1) {
					processClear(args);
				} else if (args[0] == "setMaxIdleTime" && args.size() == 2) {
					processSetMaxIdleTime(args);
				} else if (args[0] == "setMax" && args.size() == 2) {
					processSetMax(args);
				} else if (args[0] == "getActive" && args.size() == 1) {
					processGetActive(args);
				} else if (args[0] == "getCount" && args.size() == 1) {
					processGetCount(args);
				} else if (args[0] == "setMaxPerApp" && args.size() == 2) {
					processSetMaxPerApp(atoi(args[1]));
				} else if (args[0] == "getSpawnServerPid" && args.size() == 1) {
					processGetSpawnServerPid(args);
				} else {
					processUnknownMessage(args);
					break;
				}
				args.clear();
			}
		} catch (const boost::thread_interrupted &) {
			P_TRACE(2, "Client thread " << this << " interrupted.");
		} catch (const exception &e) {
			P_TRACE(2, "Uncaught exception in ApplicationPoolServer client thread:\n"
				<< "   message: " << toString(args) << "\n"
				<< "   exception: " << e.what());
		}
		
		mutex::scoped_lock l(server.lock);
		ClientPtr myself(self.lock());
		if (myself != NULL) {
			server.clients.erase(myself);
		}
	}
Esempio n. 28
0
static CDisplayPtr GetGlobalDisplay()
{
  static weak_ptr<CDisplay> display_global;

  CDisplayPtr display(display_global.lock());
  if(display)
  {
    if(display->lost())
    {
      CLog::Log(LOGERROR, "VAAPI - vaapi display is in lost state");
      display.reset();
    }    
    return display;
  }

  VADisplay disp;
  disp = vaGetDisplayGLX(g_Windowing.GetDisplay());

  int major_version, minor_version;
  VAStatus res = vaInitialize(disp, &major_version, &minor_version);

  CLog::Log(LOGDEBUG, "VAAPI - initialize version %d.%d", major_version, minor_version);

  if(res != VA_STATUS_SUCCESS)
  {
    CLog::Log(LOGERROR, "VAAPI - unable to initialize display %d - %s", res, vaErrorStr(res));
    return display;
  }

  const char* vendor = vaQueryVendorString(disp);
  CLog::Log(LOGDEBUG, "VAAPI - vendor: %s", vendor);

  bool deinterlace = true;
  int major, minor, micro;
  bool support_4k = true;
  if(sscanf(vendor,  "Intel i965 driver - %d.%d.%d", &major, &minor, &micro) == 3)
  {
    /* older version will crash and burn */
    if(compare_version(major, minor, micro, 1, 0, 17) < 0)
    {
      CLog::Log(LOGDEBUG, "VAAPI - deinterlace not support on this intel driver version");
      deinterlace = false;
    }
    // do the same check for 4K decoding: version < 1.2.0 (stable) and 1.0.21 (staging)
    // cannot decode 4K and will crash the GPU
    if((compare_version(major, minor, micro, 1, 2, 0) < 0) && (compare_version(major, minor, micro, 1, 0, 21) < 0))
    {
      support_4k = false;
    }
  }

  display = CDisplayPtr(new CDisplay(disp, deinterlace));
  display->support_4k(support_4k);
  display_global = display;
  return display;
}
Esempio n. 29
0
void ofxWidget::setFocus(bool focus_) {

	if (focus_ == isActivated())
		return;

	// callback previous widget telling it that it 
	// loses focus
	if (auto previousElementInFocus = sFocusedWidget.lock())
		if (previousElementInFocus->onFocusLeave)
			previousElementInFocus->onFocusLeave();

	sFocusedWidget = mThis;

	// callback this widget telling it that it 
	// receives focus
	if (auto nextFocusedWidget = sFocusedWidget.lock())
		if (nextFocusedWidget->onFocusEnter)
			nextFocusedWidget->onFocusEnter();
}
Esempio n. 30
0
void choice::set_selected(weak_ptr<choice_item> value)
{
   auto old_selected = m_selected.lock();
   auto new_selected = value.lock();

   if (value.lock() != old_selected)
   {
      if (old_selected)
         old_selected->set_pressed(false);

      m_selected = value;
      if (new_selected)
         new_selected->set_pressed(true);

      auto s = sink().lock();
      if (s)
         s->action(selected());
   }
}