int main() {
    HasPtr hp1("hello"), hp2("world"), *ph = new HasPtr("world");
    hp1 = hp2;
    hp1 = move(*ph);

    return 0;
}
void Test1()
{
	int a[] = { 10, 11, 13, 12, 16, 18, 15, 17, 14, 19 };
	Heap<int> hp1(a, sizeof(a) / sizeof(int));
	hp1.Push(20);
	cout << endl;
}
Exemple #3
0
void main(void)
{
  hp1();
  hp2();
  hp3();
  hp4();
}
void TestHasPtr()
{
    HasPtr hp1("Zhangsan");
    HasPtr hp2(hp1); // 拷贝构造函数
    HasPtr hp3;
    hp3 = hp1; // 拷贝赋值运算符
	// 我们在HasPtr中添加了一个重载的operator=(const std::string& rhs),使得这里可以直接将一个string赋给一个HasPtr对象
	// 而且它仅仅修改HasPtr的string成员*ps,int i成员和use成员不改变。
    hp2 = "Lisi";
    hp3 = "Wangwu";

    std::cout << "hp1: " << *hp1 << std::endl;
    std::cout << "hp2: " << *hp2 << std::endl;
    std::cout << "hp3: " << *hp3 << std::endl;
}
Exemple #5
0
uint64_t scenario2(uint64_t hoppingPeriod, uint64_t beaconningPeriod,
		       size_t /*beaconCount*/, float /*senseBW*/)
{
	uint64_t band_start = 2.3995e9;
	uint64_t band_end = 2.5125e9;

	float band1 = band_start + (rand_cmwc() % ((band_end - band_start) / 1000000)) * 1e6;
	float band2 = band_start + (rand_cmwc() % ((band_end - band_start) / 1000000)) * 1e6;

	/*std::cout << "Band1: " << band1 / 1e6;
	std::cout << ", Band2: " << band2 / 1e6 << std::endl;*/

	HoppingPattern hp1(1000e3, Band(band_start, band_end), 1.1e6, HoppingPattern::LINEAR, 1e3);
	hp1.addAvailableEntry(Band(band1, band1+1e6), 0.0, 0.4);
	hp1.addAvailableEntry(Band(band2, band2+1e6), 0.5, 0.4);
	CogNode n1(42, 0, 0, beaconningPeriod, hp1, 1);

	HoppingPattern hp2(60e6, Band(band_start, band_end), 1.1e6, HoppingPattern::RANDOM,
			   hoppingPeriod, 1e6);
	CogNode n2(43, 0, 0, 10e3, hp2, 1);

	CogNode *nodes[] = { &n1, &n2 };
	size_t nodesCount = sizeof(nodes) / sizeof(CogNode *);

	while (true) {
		uint64_t next = -1;

		for (size_t i = 0; i < nodesCount; i++) {
			uint64_t nodeNext = nodes[i]->usUntilNextOperation();
			if (nodeNext < next)
				next = nodeNext;
		}

		//std::cout << "next = " << next << std::endl;

		// FIXME? If a node jumps to a frequency, it won't be able to
		// receive a message until the next tick change. That's pretty
		// much what we get in real life though :s
		for (size_t i = 0; i < nodesCount; i++) {
			nodes[i]->addTicks(next);
			if (n2.hasNeighbour(42)) {
				return n2.ticksSinceStart();
			}
		}
	}

	//std::cout << std::endl;
}
Exemple #6
0
void
TrisetGrabber::checkIfGrabsMouse(int x, int y,
				 const Camera* const camera)
{
  m_lastX = x;
  m_lastY = y;

  Vec pos = camera->projectedCoordinatesOf(centroid());
  QPoint hp0(pos.x, pos.y);
  QPoint hp1(x, y);
  if ((hp0-hp1).manhattanLength() < 100)
    setGrabsMouse(true);
  else
    {
      setGrabsMouse(false);
      m_pressed = false;
    }
}
Exemple #7
0
void DrawTContact(QPainter *p,pigalePaint *paint)
  {GeometricGraph G(paint->GCP);
  Prop<Tpoint> hp1(G.Set(tvertex()),PROP_DRAW_POINT_1);
  Prop<Tpoint> hp2(G.Set(tvertex()),PROP_DRAW_POINT_2);
  Prop<Tpoint> vp1(G.Set(tvertex()),PROP_DRAW_POINT_3);
  Prop<Tpoint> vp2(G.Set(tvertex()),PROP_DRAW_POINT_4);
  Prop<Tpoint> postxt(G.Set(tvertex()),PROP_DRAW_POINT_5);
  Prop1<double> sizetext(G.Set(),PROP_DRAW_DBLE_1);
  tvertex v;	
  // Draw horizontals and verticals
  for(v = 1;v <= G.nv();v++)
      {if(hp1[v].x() > .0)paint->DrawSeg(p,hp1[v],hp2[v],Black);
      if(vp1[v].x() > .0)paint->DrawSeg(p,vp1[v],vp2[v],Black);
      }
  // Draw text
  p->setFont(QFont("sans",Min((int)(sizetext() * Min(paint->xscale,paint->yscale) + .5),13)));
  for(v=1; v <= G.nv();v++)
      paint->DrawText(p,postxt[v],v,G.vcolor[v],0);
  }
Exemple #8
0
void Surface :: CalcHesse (const Point<3> & point, Mat<3> & hesse) const
{
  double dx = 1e-5;
  Point<3> hp1, hp2;
  Vec<3> g1, g2;

  for (int i = 0; i < 3; i++)
    {
      hp1 = point;
      hp2 = point;

      hp1(i) += dx;
      hp2(i) -= dx;

      CalcGradient (hp1, g1);
      CalcGradient (hp2, g2);
      	
      for (int j = 0; j < 3; j++)
	hesse(i, j) = (g1(j) - g2(j)) / (2 * dx);
    }
}
Exemple #9
0
void
NetworkGrabber::checkIfGrabsMouse(int x, int y,
				 const Camera* const camera)
{
  m_lastX = x;
  m_lastY = y;

//  if (m_pressed)
//    {
//      // mouse button pressed so keep grabbing
//      setGrabsMouse(true);
//      return;
//    }
  
  Vec pos = camera->projectedCoordinatesOf(centroid());
  QPoint hp0(pos.x, pos.y);
  QPoint hp1(x, y);
  if ((hp0-hp1).manhattanLength() < 50)
    setGrabsMouse(true);
  else
    setGrabsMouse(false);
}
Exemple #10
0
void Test1()
{
	int a[] = {10,16,18,12,11,13,15,17,14,19};
	//Heap<int> hp(a,sizeof(a)/sizeof(a[0])); //默认建大堆
	Heap<int,Less<int> > hp1(a,sizeof(a)/sizeof(a[0])); //建小堆
}