Exemplo n.º 1
0
void main()
{
  BinaryPredicateType<short, short>* nbpp;
  UnaryPredicateType<short>* nupp;
  UnaryFunctionType<short, short> uf(square);
  BinaryFunctionType<short, short, short> bf = add;
  UnaryPredicateType<short> up = even;
  BinaryPredicateType<short, short> bp = lesser;
  Negate<short> neg(up);
  Negate2<short, short> neg2(bp);
  Bind1st<short, short, short> bind1(bf, 26);
  Bind2nd<Boolean, short, short> bind2(bp, 35);
  Generator<short> gen(10);
  Incrementor<short> incr(25);
  Decrementor<short> decr(45);

  int val1, val2;
//  clrscr();

  nupp = &neg(up);
  nbpp = &neg2(bp);

  val1 = uf(5);
  val2 = bf(uf(6), 3);

  cout <<val1 <<"\t" <<val2 <<endl;

  val1++;
  cout <<up(val1) <<"\t" <<up(val2) <<endl;
  cout <<(*nupp)(val1) <<"\t" <<(*nupp)(val2) <<endl;
  val2++;
  val1++;
  cout <<up(val1) <<"\t" <<up(val2) <<endl;
  cout <<bp(val1, val2) <<"\t" <<bp(val2, val1) <<endl;
  cout <<(*nbpp)(val1, val2) <<"\t" <<(*nbpp)(val2, val1) <<endl;
  cout <<val1 <<"\t" <<val2 <<endl;

  cout <<bind1(val1) <<"\t" <<bind1(val2) <<endl;
  cout <<bind2(val1) <<"\t" <<bind2(val2) <<endl;

  cout <<gen() <<"\t";
  cout <<gen() <<endl;
  cout <<incr() <<"\t";
  cout <<incr() <<endl;
  cout <<decr() <<"\t";
  cout <<decr() <<endl;
}                       
Exemplo n.º 2
0
ServerSocket::ServerSocket(int port)
{
    if (!create())
    {
        std::cout << "create socket fail" << std::endl;

        throw SocketException("Could not create the socket");

        return;
    }
    
    if (!bind1(port))
    {
        std::cout << "could not bind to  port" << std::endl;
        return;
    }
    if (!listen())
    {
        std::cout << "could not listen to socket" << std::endl;
        return;
    }
}
Exemplo n.º 3
0
/*===========================================================================*/
void PolygonRenderer::exec( kvs::ObjectBase* object, kvs::Camera* camera, kvs::Light* light )
{
    kvs::PolygonObject* polygon = kvs::PolygonObject::DownCast( object );
    m_has_normal = polygon->normals().size() > 0;
    m_has_connection = polygon->numberOfConnections() > 0;
    if ( !m_has_normal ) setEnabledShading( false );

    BaseClass::startTimer();
    kvs::OpenGL::WithPushedAttrib p( GL_ALL_ATTRIB_BITS );
    kvs::OpenGL::Enable( GL_DEPTH_TEST );

    const size_t width = camera->windowWidth();
    const size_t height = camera->windowHeight();
    const bool window_created = m_width == 0 && m_height == 0;
    if ( window_created )
    {
        m_width = width;
        m_height = height;
        m_object = object;
        this->create_shader_program();
        this->create_buffer_object( polygon );
    }

    const bool window_resized = m_width != width || m_height != height;
    if ( window_resized )
    {
        m_width = width;
        m_height = height;
    }

    const bool object_changed = m_object != object;
    if ( object_changed )
    {
        m_object = object;
        m_shader_program.release();
        m_vbo.release();
        m_ibo.release();
        this->create_shader_program();
        this->create_buffer_object( polygon );
    }

    kvs::VertexBufferObject::Binder bind1( m_vbo );
    kvs::ProgramObject::Binder bind2( m_shader_program );
    {
        const kvs::Mat4 M = kvs::OpenGL::ModelViewMatrix();
        const kvs::Mat4 PM = kvs::OpenGL::ProjectionMatrix() * M;
        const kvs::Mat3 N = kvs::Mat3( M[0].xyz(), M[1].xyz(), M[2].xyz() );
        m_shader_program.setUniform( "ModelViewMatrix", M );
        m_shader_program.setUniform( "ModelViewProjectionMatrix", PM );
        m_shader_program.setUniform( "NormalMatrix", N );

        const size_t nconnections = polygon->numberOfConnections();
        const size_t nvertices = polygon->numberOfVertices();
        const size_t npolygons = nconnections == 0 ? nvertices / 3 : nconnections;
        const size_t coord_size = nvertices * 3 * sizeof( kvs::Real32 );
        const size_t color_size = nvertices * 4 * sizeof( kvs::UInt8 );

        KVS_GL_CALL( glPolygonMode( GL_FRONT_AND_BACK, GL_FILL ) );

        // Enable coords.
        KVS_GL_CALL( glEnableClientState( GL_VERTEX_ARRAY ) );
        KVS_GL_CALL( glVertexPointer( 3, GL_FLOAT, 0, (GLbyte*)NULL + 0 ) );

        // Enable colors.
        KVS_GL_CALL( glEnableClientState( GL_COLOR_ARRAY ) );
        KVS_GL_CALL( glColorPointer( 4, GL_UNSIGNED_BYTE, 0, (GLbyte*)NULL + coord_size ) );

        // Enable normals.
        if ( m_has_normal )
        {
            KVS_GL_CALL( glEnableClientState( GL_NORMAL_ARRAY ) );
            KVS_GL_CALL( glNormalPointer( GL_FLOAT, 0, (GLbyte*)NULL + coord_size + color_size ) );
        }

        // Draw triangles.
        if ( m_has_connection )
        {
            kvs::IndexBufferObject::Binder bind3( m_ibo );
            KVS_GL_CALL( glDrawElements( GL_TRIANGLES, 3 * npolygons, GL_UNSIGNED_INT, 0 ) );
        }
        else
        {
            KVS_GL_CALL( glDrawArrays( GL_TRIANGLES, 0, 3 * npolygons ) );
        }

        // Disable coords.
        KVS_GL_CALL( glDisableClientState( GL_VERTEX_ARRAY ) );

        // Disable colors.
        KVS_GL_CALL( glDisableClientState( GL_COLOR_ARRAY ) );

        // Disable normals.
        if ( m_has_normal )
        {
            KVS_GL_CALL( glDisableClientState( GL_NORMAL_ARRAY ) );
        }
    }

    BaseClass::stopTimer();
}