void StokesPreconditioner::vmult (Vector<double> &dst,
		const Vector<double> &src) const
{


	int n_dof_v = Ax->n();
	int n_dof_p = Q->n();
	Vector<double> d0(n_dof_v);
	Vector<double> d1(n_dof_v);
	Vector<double> s0(n_dof_v);
	Vector<double> s1(n_dof_v);

	for (int i = 0; i < n_dof_v; ++i)
		s0(i) = src(i);
	for (int i = 0; i < n_dof_v; ++i)
		s1(i) = src(n_dof_v + i);
	for (int i = 0; i < n_dof_p; ++i)
		dst(2 * n_dof_v + i) = src(2 * n_dof_v + i) / (*Q).diag_element(i);

	AMGx.solve(d0, s0, 1e-8, 1, 1);

	AMGy.solve(d1, s1, 1e-8, 1, 1);

	for (int i = 0; i < n_dof_v; ++i)
		dst(i) = d0(i);
	for (int i = 0; i < n_dof_v; ++i)
		dst(n_dof_v + i) = d1(i);
};
static void
test_disconnect_equal()
{
  boost::signals2::signal<void ()> s0;

  connections[0] = s0.connect(remove_connection(0));
  connections[1] = s0.connect(remove_connection(1));
  connections[2] = s0.connect(remove_connection(2));
  connections[3] = s0.connect(remove_connection(3));

  std::cout << "Deleting 2" << std::endl;

  test_output = "";
  s0(); std::cout << std::endl;
  BOOST_CHECK(test_output == "0123");

#if BOOST_WORKAROUND(BOOST_MSVC, <= 1300)
  connections[2].disconnect();
#else
  s0.disconnect(remove_connection(2));
#endif

  test_output = "";
  s0(); std::cout << std::endl;
  BOOST_CHECK(test_output == "013");
}
Exemple #3
0
void checkPolyline(const vector<T3DPointD> &p)
{
	int ret;

	if (p.size() < 3)
		return;

	TPointD p1;
	TPointD p2;

	int pointSize = (int)p.size() - 1;

	for (int i = 0; i < pointSize; i++) {
		for (int j = i + 1; j < pointSize; j++) {
			vector<DoublePair> res;

			p1 = TPointD(p[i].x, p[i].y);
			p2 = TPointD(p[i + 1].x, p[i + 1].y);

			TSegment s0(p1, p2);

			p1 = TPointD(p[j].x, p[j].y);
			p2 = TPointD(p[j + 1].x, p[j + 1].y);

			TSegment s1(p1, p2);

			ret = intersect(s0, s1, res);
			if (ret)
				assert(
					(ret == 1) &&
					(areAlmostEqual(res[0].first, 1) ||
					 areAlmostEqual(res[0].first, 0)) &&
					(areAlmostEqual(res[0].second, 1) ||
					 areAlmostEqual(res[0].second, 0)));
		}
	}

	p1 = TPointD(p.back().x, p.back().y);
	p2 = TPointD(p[0].x, p[0].y);

	TSegment s0(p1, p2);

	for (int j = 0; j < pointSize; j++) {
		vector<DoublePair> res;

		p1 = TPointD(p[j].x, p[j].y);
		p2 = TPointD(p[j + 1].x, p[j + 1].y);
		TSegment s1(p1, p2);

		ret = intersect(s0, s1, res);
		if (ret)
			assert(
				(ret == 1) &&
				(areAlmostEqual(res[0].first, 1) ||
				 areAlmostEqual(res[0].first, 0)) &&
				(areAlmostEqual(res[0].second, 1) ||
				 areAlmostEqual(res[0].second, 0)));
	}
}
Exemple #4
0
void CAstar::Astar(CAstarNode*& result)
{
	CAstarNode s0(m_hgevStart,0,CalculateH(m_hgevStart),NULL);

	//open表中插入起点
	m_vOpenList.push_back(s0);

	make_heap(m_vOpenList.begin(),m_vOpenList.end());
//	CAstarNode* min;

	while(!m_vOpenList.empty())
	{
		//pop出堆顶节点
		pop_heap(m_vOpenList.begin(),m_vOpenList.end(),cmpAstarNode);
		result = new CAstarNode(m_vOpenList.back().m_hgevCoordinate,m_vOpenList.back().m_nG,
			m_vOpenList.back().m_nH, m_vOpenList.back().m_pParent);
		//若节点是目标节点,则返回
		if(result->m_hgevCoordinate == m_hgevGoal)
		{
		//	memcpy(result,&min,sizeof(CAstarNode));
			return ;
		}

		m_vOpenList.pop_back();	
	//	make_heap(m_vOpenList.begin(),m_vOpenList.end());
		//扩展该节点
		ExtendNode(result);
	//	make_heap(m_vOpenList.begin(),m_vOpenList.end());
		m_vClosedList.push_back(*result);
	}
	result = NULL;
}
Exemple #5
0
    // Copy weak, access via shared
    void weak_1()
    {
        assert_ck(0, 0);

        {
            shared_test s0(test_behavior::init());
            assert_ck(1, 0);

            weak_test w0(s0);
            assert_ck(1, 0);

            auto w1(w0);
            assert_ck(1, 0);

            assert(!w0.expired());
            assert(w0.use_count() == 1);

            assert(!w1.expired());
            assert(w1.use_count() == 1);

            assert(w0.lock().get() == w1.lock().get());
        }

        assert_ck(1, 1);
    }
void Test() {
  std::string str('x', 4);
  // CHECK-MESSAGES: [[@LINE-1]]:15: warning: constructor parameters are probably swapped [misc-string-constructor]
  std::wstring wstr(L'x', 4);
  // CHECK-MESSAGES: [[@LINE-1]]:16: warning: constructor parameters are probably swapped
  std::string s0(0, 'x');
  // CHECK-MESSAGES: [[@LINE-1]]:15: warning: constructor creating an empty string
  std::string s1(-4, 'x');
  // CHECK-MESSAGES: [[@LINE-1]]:15: warning: negative value used as length parameter
  std::string s2(0x1000000, 'x');
  // CHECK-MESSAGES: [[@LINE-1]]:15: warning: suspicious large length parameter
  
  std::string q0("test", 0);
  // CHECK-MESSAGES: [[@LINE-1]]:15: warning: constructor creating an empty string
  std::string q1(kText, -4);
  // CHECK-MESSAGES: [[@LINE-1]]:15: warning: negative value used as length parameter
  std::string q2("test", 200);
  // CHECK-MESSAGES: [[@LINE-1]]:15: warning: length is bigger then string literal size
  std::string q3(kText, 200);
  // CHECK-MESSAGES: [[@LINE-1]]:15: warning: length is bigger then string literal size
  std::string q4(kText2, 200);
  // CHECK-MESSAGES: [[@LINE-1]]:15: warning: length is bigger then string literal size
  std::string q5(kText3,  0x1000000);
  // CHECK-MESSAGES: [[@LINE-1]]:15: warning: suspicious large length parameter
}
Exemple #7
0
void test_2()
{
  // Test bounding_box() for Point_2
  Point_2 p0 (1, 2);
  Point_2 p1 (2, 1);

  std::vector<Point_2> pts;
  pts.push_back(p0);
  pts.push_back(p0);
  pts.push_back(p1);

  assert( CGAL::bounding_box(pts.begin(), pts.end())
          == K::Iso_rectangle_2(p0, p1));

#if 0 // Does not work yet
  // Test bounding_box() for Segment_2
  Segment_2 s0 (p0, p1);
  Segment_2 s1 (p0, p0);

  std::vector<Segment_2> segs;
  segs.push_back(s0);
  segs.push_back(s0);
  segs.push_back(s1);

  assert( CGAL::bounding_box(segs.begin(), segs.end())
          == K::Iso_rectangle_2(p0, p1));
#endif
}
Float SoftCylinderPairScore::evaluate_index(
    kernel::Model *m, const kernel::ParticleIndexPair &pip,
    DerivativeAccumulator *da) const {
  atom::Bond b[2] = {atom::Bond(m, pip[0]), atom::Bond(m, pip[1])};

  core::XYZR d[2][2] = {
      {core::XYZR(b[0].get_bonded(0)), core::XYZR(b[0].get_bonded(1))},
      {core::XYZR(b[1].get_bonded(0)), core::XYZR(b[1].get_bonded(1))}};
  algebra::Segment3D s0(d[0][0].get_coordinates(), d[0][1].get_coordinates());
  algebra::Segment3D s1(d[1][0].get_coordinates(), d[1][1].get_coordinates());
  algebra::Segment3D ss = algebra::get_shortest_segment(s0, s1);
  if (ss.get_length() < d[0][0].get_radius() + d[1][0].get_radius()) {
    double diff = d[0][0].get_radius() + d[1][0].get_radius() - ss.get_length();
    double score = .5 * k_ * square(diff);
    if (da) {
      double deriv = k_ * diff;
      algebra::Vector3D v = ss.get_point(1) - ss.get_point(0);
      algebra::Vector3D uv = v.get_unit_vector();
      algebra::Vector3D duv = deriv * uv;
      d[0][0].add_to_derivatives(-duv, *da);
      d[0][1].add_to_derivatives(-duv, *da);
      d[1][0].add_to_derivatives(duv, *da);
      d[1][1].add_to_derivatives(duv, *da);
    }
    return score;
  } else {
    return 0;
  }
}
Exemple #9
0
int main() {
  Direction d = D;
  Direction u = U;

  Shift s0(d, 1);
  Shift s1(d, 0);
  std::vector<Shift> shifts;
  s0.string_vec.push_back(0);
  s0.string_vec.push_back(1);
  s0.string_vec.push_back(0);
  s0.string_vec.push_back(3);

  s1.string_vec.push_back(0);
  s1.string_vec.push_back(1);
  s1.string_vec.push_back(0);
  s1.string_vec.push_back(3);

  if (s0 < s1) {
    std::cout << "s0 < s1\n";
  } else {
    std::cout << "s0 > s1\n";
  }

  shifts.push_back(s0);
  shifts.push_back(s1);
  std::sort(shifts.begin(), shifts.end());

  for (Shift s : shifts) {
    std::cout << "id: " << s.id << ", str: ";
    for (int i = 0; i < 4; i++) {
      std::cout << s.string_vec[i] << " ";
    }
    std::cout << "\n";
  }
}
Exemple #10
0
static void _BRSHA256Compress(uint32_t *r, uint32_t *x)
{
    static const uint32_t k[] = {
        0x428a2f98, 0x71374491, 0xb5c0fbcf, 0xe9b5dba5, 0x3956c25b, 0x59f111f1, 0x923f82a4, 0xab1c5ed5,
        0xd807aa98, 0x12835b01, 0x243185be, 0x550c7dc3, 0x72be5d74, 0x80deb1fe, 0x9bdc06a7, 0xc19bf174,
        0xe49b69c1, 0xefbe4786, 0x0fc19dc6, 0x240ca1cc, 0x2de92c6f, 0x4a7484aa, 0x5cb0a9dc, 0x76f988da,
        0x983e5152, 0xa831c66d, 0xb00327c8, 0xbf597fc7, 0xc6e00bf3, 0xd5a79147, 0x06ca6351, 0x14292967,
        0x27b70a85, 0x2e1b2138, 0x4d2c6dfc, 0x53380d13, 0x650a7354, 0x766a0abb, 0x81c2c92e, 0x92722c85,
        0xa2bfe8a1, 0xa81a664b, 0xc24b8b70, 0xc76c51a3, 0xd192e819, 0xd6990624, 0xf40e3585, 0x106aa070,
        0x19a4c116, 0x1e376c08, 0x2748774c, 0x34b0bcb5, 0x391c0cb3, 0x4ed8aa4a, 0x5b9cca4f, 0x682e6ff3,
        0x748f82ee, 0x78a5636f, 0x84c87814, 0x8cc70208, 0x90befffa, 0xa4506ceb, 0xbef9a3f7, 0xc67178f2
    };
    
    int i;
    uint32_t a = r[0], b = r[1], c = r[2], d = r[3], e = r[4], f = r[5], g = r[6], h = r[7], t1, t2, w[64];
    
    for (i = 0; i < 16; i++) w[i] = be32(x[i]);
    for (; i < 64; i++) w[i] = s3(w[i - 2]) + w[i - 7] + s2(w[i - 15]) + w[i - 16];
    
    for (i = 0; i < 64; i++) {
        t1 = h + s1(e) + ch(e, f, g) + k[i] + w[i];
        t2 = s0(a) + maj(a, b, c);
        h = g, g = f, f = e, e = d + t1, d = c, c = b, b = a, a = t1 + t2;
    }
    
    r[0] += a, r[1] += b, r[2] += c, r[3] += d, r[4] += e, r[5] += f, r[6] += g, r[7] += h;
    var_clean(&a, &b, &c, &d, &e, &f, &g, &h, &t1, &t2);
    mem_clean(w, sizeof(w));
}
PyObject* formula_s0(PyObject* self, PyObject* args)
{
  float a, b, c, d, e, f;
  if (!PyArg_ParseTuple(args, "ffffff", &a, &b, &c, &d, &e, &f))
		return NULL;
  return Py_BuildValue("f", s0(a,b,c,d,e,f));
}
int main()
{
	void h0(float, float);
	void e0(float, float);
	void s0(float, float);
	float a, b, c;
	printf("请输入a,b,c:");
	scanf("%f,%f,%f", &a, &b, &c);
	printf("方程为:%5.2fx*x+%5.2fx+%5.2f=0\n", a, b, c);
	Delta = b*b - 4 * a*c;
	printf("结果是:\n");
	if (Delta > 0)
	{
		h0(a, b);
		printf("x1=%f\nx2=%f\n", x1, x2);
	}
	else if (Delta < 0)
	{
		s0(a, b);
		printf("x1=%f+%fi\nx2=%f-%fi\n", m, n, m, n);
	}
	else
	{
		e0(a, b);
		printf("x1=x2=%f\n", x1);
	}
	return 0;
}
Exemple #13
0
int main()
{
	/* Value constructor */
	cv::Scalar s0(10); // (10,0,0,0)
	cv::Scalar s(0.5,1.25,2.75,3.0);

	std::cout << "s0(10) " << s0 << std::endl;
	std::cout << "s(0.5,1.25,2.75,3.0) " << s << std::endl;

	/* Element-wise mult */
	cv::Scalar prod = s.mul(cv::Scalar(6.5, 7.5, 8.5, 9.5));
	std::cout << "prod: " << prod << std::endl;
	
	/* (Quaternion) conjugation */
	std::cout << "s conj: " << s.conj() << std::endl;

	/* (Quaternion) real test */
	if (s0.isReal()) std::cout << s0 << " is real" << std::endl;
	else std::cout << s0 << " is not real." << std::endl;

	/* (Quaternion) real test */
	if (s.isReal()) std::cout << s << " is real" << std::endl;
	else std::cout << s << " is not real." << std::endl;

}
Exemple #14
0
void print_table(str s, const Ptable& T) {
	printf("%s", s.c_str()); printf("\n");
	int l = T.size();
	if (l==0) {
		printf("   ! Empty table\n");
		return;
	}
	int c = T[0].size();
	for (int i=0; i<l; i++) {
		if (T[i].size()!=c) {
			printf("   ! Table has different number of columns depending to the lines\n");
			return;
		}
	}
	str s0(" ",10);
	const char* space = s0.c_str();
	printf("%s", space);
	for (int j=0; j<c; j++) printf("%11d",j);
	printf("\n");
	for (int i=0; i<l; i++) {
		printf("%4d",i);
		for (int j=0; j<c; j++) printf("%11s",p2s(T[i][j]).c_str());
		printf("\n");
	}
	printf("\n");
}
Exemple #15
0
string parser::preprocess_input(istream &stream)
{
    streampos start = stream.tellg();
    stream.seekg(0, ios::end);
    streampos end = stream.tellg();
    size_t file_size = end - start;
    stream.seekg(start, ios::beg);
    char bom_test[3];
    static const char * BOM = "\xEF\xBB\xBF";
    stream.read(bom_test, 3u);
    if (strncmp(bom_test, BOM, 3u) == 0) {
        // Matched BOM, keep stream position to prevent its reading
        file_size -= 3u;
    }
    else {
        // Seek stream back
        stream.seekg(start, ios::beg);
    }
    char * buffer = new char[file_size + 1];
    stream.read(buffer, file_size);
    buffer[file_size] = '\0';
    string s0(buffer);
    delete[] buffer;
    string s1 = fix_corrupted_data(s0);
    return s1;
}
Exemple #16
0
    // Decrement weak count
    void weak_6()
    {
        assert_ck(0, 0);

        {
            shared_test s0(test_behavior::init());
            assert_ck(1, 0);

            assert(s0.use_count() == 1);

            weak_test w0(s0);

            assert(s0.use_count() == 1);
            assert(!w0.expired());

            {
                weak_test w1(w0);
                assert(s0.use_count() == 1);
                assert(!w0.expired());
                assert(!w1.expired());
            }

            assert(s0.use_count() == 1);
            assert(!w0.expired());
        }

        assert_ck(1, 1);
    }
Exemple #17
0
int expandWord(unsigned int test[]) {
	int i;
	for(i=16;i<64;i++)
		test[i] = (s1(test[i-2])) + test[i-7] + (s0(test[i-15])) + test[i-16];

	return 0;
}
Exemple #18
0
static int parsePattern(std::wstring str, TilePattern* pat) {
	pat->rows.clear();
	pat->heights.clear();

	std::vector<std::wstring> rowStrings = std::vector<std::wstring>();
	tokenize(str, rowStrings, L"/");

	for (int i=0; i<rowStrings.size(); i++) {		
		std::vector<std::wstring> row = std::vector<std::wstring>();
		tokenize(rowStrings[i], row, L",");
		
		if (row.size() < 3)
			return FALSE;	

		double offset, height, width;
		std::wstringstream s0(row[0]);
		s0 >> offset;
		std::wstringstream s1(row[1]);
		s1 >> height;

		TileRow r = TileRow(offset);

		for (int j=2; j<row.size(); j++) {
			std::wstringstream sn(row[j]);
			sn >> width;

			r.tiles.push_back(width);
		}

		pat->rows.push_back(r);
		pat->heights.push_back((float)height);
	}

	return TRUE;
}
Exemple #19
0
void  HPoly
      (
           ActionSeg &             Act,
           ElFifo<Pt2dr> &   f,
           Pt2dr                   dir,
           REAL                    esp
      )
{
     REAL omax = -1e50;
     REAL omin =  1e50;

     SegComp s0 (Pt2dr(0,0),dir);

     for (INT k=0; k<f.nb() ; k++)
     {
          REAL ord = s0.ordonnee(f[k]);
          ElSetMax(omax,ord);
          ElSetMin(omin,ord);
     }
     
     for (REAL ord = round_up(omin/esp) *esp; ord<omax; ord += esp)
     {
          Pt2dr p0 = s0.from_rep_loc(Pt2dr(0.0,ord));
          ClipSeg(Act,f,Seg2d(p0,p0+s0.tangente()));
     }
      
}
Exemple #20
0
bool insert_test( )
{
  bool rc = true;

  std::string s0( "INSERTED" );
  std::string s1( "Hello, World!" );
  s1.insert( 2, s0 );
  if( s1 != "HeINSERTEDllo, World!" || s1.size( ) != 21 || INSANE( s1 ) ) {
    FAIL
  }

  std::string s2( "Hello, World!" );
  s2.insert( 0, s0 );
  if( s2 != "INSERTEDHello, World!" || s2.size( ) != 21 || INSANE( s2 ) ) {
    FAIL
  }

  std::string s3( "Hello, World!" );
  s3.insert( 13, s0 );
  if( s3 != "Hello, World!INSERTED" || s3.size( ) != 21 || INSANE( s3 ) ) {
    FAIL
  }

  std::string s4( "Hello, World!" );
  s4.insert( 0, s0, 2, 2 );
  if( s4 != "SEHello, World!" || s4.size( ) != 15 || INSANE( s4 ) ) {
    FAIL
  }

  std::string s5( "Hello, World!" );
  s5.insert( 0, s0, 2, 128 );
  if( s5 != "SERTEDHello, World!" || s5.size( ) != 19 || INSANE( s5 ) ) {
    FAIL
  }

  // Do multiple insertions to verify reallocations.
  // This should probably also be done for the other insert methods as well.
  std::string s6( "Hello" );
  char input = 'a';
  for( int i = 0; i < 10; ++i ) {
      std::string::iterator p = s6.insert( s6.begin( ), input );
      if( *p != input ) FAIL;
      if( s6.size( ) != 6 + i ) FAIL;
      if( INSANE( s6 ) ) FAIL;
      ++input;
  }
  if( s6 != "jihgfedcbaHello" ) FAIL;

  std::string s7( "Hello, World!" );
  s7.insert( s7.end( ), 3, 'z' );
  if( s7 != "Hello, World!zzz" || s7.size( ) != 16 || INSANE( s7 ) ) {
    FAIL
  }

  // Need to test other insert methods.

  return( rc );
}
int socketCreatePair(int* fd1, int* fd2) {
#ifndef _WIN32
    int fds[2];
    int ret = ::socketpair(AF_UNIX, SOCK_STREAM, 0, fds);

    if (!ret) {
        socketSetNonBlocking(fds[0]);
        socketSetNonBlocking(fds[1]);
        *fd1 = fds[0];
        *fd2 = fds[1];
    } else {
        DPLOG(ERROR) << "Could not create socket pair\n";
    }
    return ret;
#else /* _WIN32 */
    /* on Windows, select() only works with network sockets, which
     * means we absolutely cannot use Win32 PIPEs to implement
     * socket pairs with the current event loop implementation.
     * We're going to do like Cygwin: create a random pair
     * of localhost TCP sockets and connect them together
     */

    /* first, create the 'server' socket.
     * a port number of 0 means 'any port between 1024 and 5000.
     * see Winsock bind() documentation for details */
    ScopedSocket s0(socketTcpLoopbackServer(0));
    if (s0.get() < 0) {
        return -1;
    }

    // IMPORTANT: Keep the s0 socket in blocking mode, or the accept()
    // below may fail with WSAEWOULDBLOCK randomly.

    /* now connect a client socket to it, we first need to
     * extract the server socket's port number */
    int port = socketGetPort(s0.get());

    ScopedSocket s2(socketTcpLoopbackClient(port));
    if (!s2.valid()) {
        return -1;
    }

    /* we need to accept the connection on the server socket
     * this will create the second socket for the pair
     */
    ScopedSocket s1(socketAccept(s0.get()));
    if (!s1.valid()) {
        DPLOG(ERROR) << "Could not accept connection from server socket\n";
        return -1;
    }
    socketSetNonBlocking(s1.get());

    *fd1 = s1.release();
    *fd2 = s2.release();

    return 0;
#endif /* _WIN32 */
}
Exemple #22
0
 forceinline ExecStatus
 prop_mult_dom(Space& home, Propagator& p, View x0, View x1, View x2) {
   Region r(home);
   SupportValues<View,Region> s0(r,x0), s1(r,x1), s2(r,x2);
   while (s0()) {
     while (s1()) {
       if (s2.support(mll(s0.val(),s1.val()))) {
         s0.support(); s1.support();
       }
       ++s1;
     }
     s1.reset(); ++s0;
   }
   GECODE_ME_CHECK(s0.tell(home));
   GECODE_ME_CHECK(s1.tell(home));
   GECODE_ME_CHECK(s2.tell(home));
   return x0.assigned() && x1.assigned() ? home.ES_SUBSUMED(p) : ES_FIX;
 }
Exemple #23
0
QString QgsPgTableModel::layerURI( const QModelIndex &index, const QString &connInfo, bool useEstimatedMetadata )
{
  if ( !index.isValid() )
  {
    QgsDebugMsg( "invalid index" );
    return QString();
  }

  QgsWkbTypes::Type wkbType = ( QgsWkbTypes::Type ) itemFromIndex( index.sibling( index.row(), DbtmType ) )->data( Qt::UserRole + 2 ).toInt();
  if ( wkbType == QgsWkbTypes::Unknown )
  {
    QgsDebugMsg( "unknown geometry type" );
    // no geometry type selected
    return QString();
  }

  QStandardItem *pkItem = itemFromIndex( index.sibling( index.row(), DbtmPkCol ) );
  QSet<QString> s0( pkItem->data( Qt::UserRole + 1 ).toStringList().toSet() );
  QSet<QString> s1( pkItem->data( Qt::UserRole + 2 ).toStringList().toSet() );
  if ( !s0.isEmpty() && s0.intersect( s1 ).isEmpty() )
  {
    // no valid primary candidate selected
    QgsDebugMsg( "no pk candidate selected" );
    return QString();
  }

  QString schemaName = index.sibling( index.row(), DbtmSchema ).data( Qt::DisplayRole ).toString();
  QString tableName = index.sibling( index.row(), DbtmTable ).data( Qt::DisplayRole ).toString();

  QString geomColumnName;
  QString srid;
  if ( wkbType != QgsWkbTypes::NoGeometry )
  {
    geomColumnName = index.sibling( index.row(), DbtmGeomCol ).data( Qt::DisplayRole ).toString();

    srid = index.sibling( index.row(), DbtmSrid ).data( Qt::DisplayRole ).toString();
    bool ok;
    srid.toInt( &ok );
    if ( !ok )
    {
      QgsDebugMsg( "srid not numeric" );
      return QString();
    }
  }

  bool selectAtId = itemFromIndex( index.sibling( index.row(), DbtmSelectAtId ) )->checkState() == Qt::Checked;
  QString sql = index.sibling( index.row(), DbtmSql ).data( Qt::DisplayRole ).toString();

  QgsDataSourceUri uri( connInfo );

  QStringList cols;
  Q_FOREACH ( const QString &col, s1 )
  {
    cols << QgsPostgresConn::quotedIdentifier( col );
  }
static void
test_bloodbath()
{
  boost::signals2::signal<void ()> s0;

  connections[0] = s0.connect(remove_connection(0, 1));
  connections[1] = s0.connect(remove_connection(1, 1));
  connections[2] = s0.connect(remove_connection(2, 0));
  connections[3] = s0.connect(remove_connection(3, 2));

  std::cout << "0 removes 1, 2 removes 0, 3 removes 2" << std::endl;

  test_output = "";
  s0(); std::cout << std::endl;
  BOOST_CHECK(test_output == "023");

  test_output = "";
  s0(); std::cout << std::endl;
  BOOST_CHECK(test_output == "3");
}
/**
 * \brief Set position of controls for player's informations.
 * \param p The object containing all player's information controls.
 */
void ptb::frame_play_story::player_status_position_controls
( player_status& p )
{
  bear::engine::level_globals& glob =
    get_layer().get_level().get_globals();

  p.energy->set_size
    (p.component->get_size().x - 2 * get_margin(),
     (p.component->get_size().y - 4*get_margin()) / 3);
  p.energy->set_bottom_left( get_margin(), get_margin());

  bear::visual::sprite s0(glob.auto_sprite("gfx/ui/status/status.png", "plee"));
  p.lives_picture->set_size(s0.get_size());
  p.lives_picture->set_bottom_left
    ( get_margin(), p.energy->top() + get_margin());

  p.lives_text->set_size
    (p.component->get_size().x / 2 - p.lives_picture->width() - get_margin(),
     (p.component->get_size().y - 4*get_margin()) / 3);
  p.lives_text->set_top_left
    (p.lives_picture->right() + get_margin(), p.lives_picture->top());

  p.score_text->set_size
    (p.component->get_size().x / 2,
     (p.component->get_size().y - 4*get_margin()) / 3);
  p.score_text->set_bottom_left
    ( get_margin(), p.lives_picture->top()+get_margin());

  bear::visual::sprite s1(glob.get_image("gfx/ui/air-power.png"));
  p.air_power->set_size(s1.get_size());

  p.air_power->set_top_left
    (p.score_text->right() + get_margin(), p.score_text->top());

  p.fire_power->set_size(s1.get_size());
  p.fire_power->set_top_left
    (p.air_power->right() + get_margin(), p.score_text->top());

  p.water_power->set_size(s1.get_size());
  p.water_power->set_top_left
    (p.fire_power->right() + get_margin(), p.score_text->top());

  bear::visual::sprite s2
    (glob.auto_sprite("gfx/stone/stone.png", "default stone"));
  p.stone_picture->set_size(s2.get_size());
  p.stone_picture->set_bottom_left
    (p.lives_text->right() + get_margin(), p.lives_text->bottom());

  p.stone_text->set_size
    (p.component->get_size().x / 2,
     (p.component->get_size().y - 4*get_margin()) / 3);
  p.stone_text->set_top_left
    ( p.stone_picture->right() + get_margin(), p.stone_picture->top());
} // frame_play_story::player_status_position_controls
static void
test_remove_after()
{
  boost::signals2::signal<void ()> s0;

  connections[0] = s0.connect(remove_connection(0, 1));
  connections[1] = s0.connect(remove_connection(1));
  connections[2] = s0.connect(remove_connection(2));
  connections[3] = s0.connect(remove_connection(3));

  std::cout << "0 removes 1" << std::endl;

  test_output = "";
  s0(); std::cout << std::endl;
  BOOST_CHECK(test_output == "023");

  test_output = "";
  s0(); std::cout << std::endl;
  BOOST_CHECK(test_output == "023");

  s0.disconnect_all_slots();
  BOOST_CHECK(s0.empty());

  connections[0] = s0.connect(remove_connection(0));
  connections[1] = s0.connect(remove_connection(1, 3));
  connections[2] = s0.connect(remove_connection(2));
  connections[3] = s0.connect(remove_connection(3));

  std::cout << "1 removes 3" << std::endl;

  test_output = "";
  s0(); std::cout << std::endl;
  BOOST_CHECK(test_output == "012");

  test_output = "";
  s0(); std::cout << std::endl;
  BOOST_CHECK(test_output == "012");
}
static void
test_remove_prior()
{
  boost::signals2::signal<void ()> s0;

  connections[0] = s0.connect(remove_connection(0));
  connections[1] = s0.connect(remove_connection(1, 0));
  connections[2] = s0.connect(remove_connection(2));
  connections[3] = s0.connect(remove_connection(3));

  std::cout << "1 removes 0" << std::endl;

  test_output = "";
  s0(); std::cout << std::endl;
  BOOST_CHECK(test_output == "0123");

  test_output = "";
  s0(); std::cout << std::endl;
  BOOST_CHECK(test_output == "123");

  s0.disconnect_all_slots();
  BOOST_CHECK(s0.empty());

  connections[0] = s0.connect(remove_connection(0));
  connections[1] = s0.connect(remove_connection(1));
  connections[2] = s0.connect(remove_connection(2));
  connections[3] = s0.connect(remove_connection(3, 2));

  std::cout << "3 removes 2" << std::endl;

  test_output = "";
  s0(); std::cout << std::endl;
  BOOST_CHECK(test_output == "0123");

  test_output = "";
  s0(); std::cout << std::endl;
  BOOST_CHECK(test_output == "013");
}
 int maxProfit(vector<int>& prices) {
 	if(prices.size() <=1) return 0;
     vector<int> s0(prices.size(),0);
     vector<int> s1(prices.size(),0);
     vector<int> s2(prices.size(),0);
     s0[0] = 0;
     s1[0] = -prices[0];
     s2[0] = 0;
     for(int i =1;i<prices.size();i++){
     	s0[i] = max(s2[i-1],s0[i-1]);
     	s1[i] = max(s0[i-1]-prices[i],s1[i-1]);
     	s2[i] = s1[i-1] + prices[i];
     }
     return max(s0[prices.size()-1],s2[prices.size()-1]);
 }
Exemple #29
0
void PatternMatcher::buildTransitions( const text::Transition & transition, const patterns::Pattern & pattern, const patterns::Alternative & alt, const Context & context, TransitionList & results ) const {
	if ( const AnnotationMatcher * curMatcher = dynamic_cast<const AnnotationMatcher *>( &alt.getMatcher( 0 ) ) ) {
		if ( !curMatcher->matchTransition( transition, Context() ) )
			return;

		PatternMatchState s0( pattern, alt, transition.start );
		PatternMatchState state( s0, const_cast<text::Transition*>( &transition ), true );

		processCompoundPattern( state, results );
	} else {
		PatternMatchState s0( pattern, alt, transition.start );
		const AnnotationChainMatcher & chainMatcher = dynamic_cast<const AnnotationChainMatcher &>( alt.getMatcher( 0 ) );

		ChainList chains; // Список цепочек

		chainMatcher.buildChains( transition, s0.context, chains ); // Заполняем список цепочек

		// TODO Optimize: Необходимо отдельно рассмотреть случай пустой цепи
		for ( uint i = 0, sz = chains.size(); i < sz; ++ i ) {
			PatternMatchState state( s0, chains[i].first, chains[i].second, i == sz - 1 );
			processCompoundPattern( state, results );
		}
	}
}
Exemple #30
0
    // Use count
    void weak_2()
    {
        assert_ck(0, 0);

        {
            shared_test s0(test_behavior::init());
            assert_ck(1, 0);

            weak_test w0(s0);
            assert_ck(1, 0);

            assert(w0.use_count() == 1);
        }

        assert_ck(1, 1);
    }