Example #1
0
int String::search(int startOffset, const String &text) const
{
    assert(startOffset>=0);
    if (startOffset>=_length) return -1;
    //if (length==0) return -1;
    //assert(startOffset>=0 && startOffset<length);

    int textLen=text.getLength();
    const char *textBuf=&text.buf.getConst(0);

    if (startOffset+textLen>_length) return -1;

    int b=0; //text index
    for (int a=startOffset; a<_length; a++)
    {
        if (buf.getConst(a)==textBuf[b])
        {
            if (b==textLen-1)
            {
                int rv=a-b;
                return a-b;
            }
            b++;
        }
        else b=0;
    }
    return -1;
}
Example #2
0
    void BinaryFileInputStreamTest::SetUp()
    {
        mFile.open(WRITE_EXISTING_BINARY);

        int32_t intVal = 10;
        float_t floatVal = 20.f;
        String  stringVal = "Dies ist ein Text";
        uint32_t strlen = static_cast<uint32_t>(stringVal.getLength());

        mFile.write(reinterpret_cast<char_t*>(&intVal), sizeof(capu::int32_t));
        mFile.write(reinterpret_cast<char_t*>(&floatVal), sizeof(capu::float_t));
        mFile.write(reinterpret_cast<char_t*>(&strlen), sizeof(uint32_t));
        mFile.write(stringVal.c_str(), stringVal.getLength());

        mFile.close();
    }
Example #3
0
// protected
void
FileOutputStreamTestCase::seek (void)
{
    File ff (TEST_FILE_NAME);
    if (ff.exists () == false)
        ff.create ();

    FileOutputStream fout (TEST_FILE_NAME, OPEN_MODE);
    String ss = "dflajdkjasldjfaksldjfsalkdjalksdjadflajdkjasldjfaksldjfsalkdjalksdjadflajdkjasldjfaksldjfsalkdjalksdjadflajdkjasldjfaksldjfsalkdjalksdjadflajdkjasldjfaksldjfsalkdjalksdja sd";
    fout.write ((unsigned char *)ss.getCStr (), ss.getLength ());
    fout.flush ();

    CPPUNIT_ASSERT_THROW (fout.seek (-1, BEGIN_ORIGIN), Exception);
    CPPUNIT_ASSERT (fout.seek (3, BEGIN_ORIGIN) == 3);
    CPPUNIT_ASSERT (fout.seek (21, BEGIN_ORIGIN) == 21);
    CPPUNIT_ASSERT (fout.seek (38, BEGIN_ORIGIN) == 38);

    CPPUNIT_ASSERT (fout.seek (-7, CURRENT_ORIGIN) == 31);
    CPPUNIT_ASSERT (fout.seek (2, CURRENT_ORIGIN) == 33);
    CPPUNIT_ASSERT_THROW (fout.seek (-73, CURRENT_ORIGIN), Exception);
    CPPUNIT_ASSERT (fout.seek (24, CURRENT_ORIGIN) == 57);
    CPPUNIT_ASSERT (fout.seek (24, CURRENT_ORIGIN) == 81);

    fout.close ();
}
Example #4
0
GLuint GLContext::Program::createGLShader(GLenum type, const String& typeStr, const String& source)
{
    GLuint shader = glCreateShader(type);
    const char* sourcePtr = source.getPtr();
    int sourceLen = source.getLength();
    glShaderSource(shader, 1, &sourcePtr, &sourceLen);
    glCompileShader(shader);

    GLint status = 0;
    glGetShaderiv(shader, GL_COMPILE_STATUS, &status);
    if (!status)
    {
        GLint infoLen = 0;
        glGetShaderiv(shader, GL_INFO_LOG_LENGTH, &infoLen);
        if (!infoLen)
            fail("glCompileShader(%s) failed!", typeStr.getPtr());

        Array<char> info(NULL, infoLen);
        info[0] = '\0';
        glGetShaderInfoLog(shader, infoLen, &infoLen, info.getPtr());
        fail("glCompileShader(%s) failed!\n\n%s", typeStr.getPtr(), info.getPtr());
    }

    GLContext::checkErrors();
    return shader;
}
void GUIText::setString(const String &textArg)
{
  if (textArg.getLength() && text != textArg)
  {
    text   = textArg;
    update = true;
  }
}
bool FW::restoreError(const String& old)
{
    bool had = hasError();
    Thread::getCurrent()->setUserData("error",
        (old.getLength()) ? new String(old) : NULL,
        (old.getLength()) ? deinitString : NULL);
    return had;
}
Example #7
0
App::App(void)
:   m_action        (Action_None),
    m_commonCtrl    (CommonControls::Feature_Default & ~CommonControls::Feature_RepaintOnF5),
    m_cullMode      (CullMode_None),

    m_mousePressed  (false),
    m_drawSkeleton  (true),
    m_drawAxes      (true),


    m_x             (0.0f),
    m_y             (0.0f),
    m_z             (0.0f),
    m_sliderChanged (false),
    m_jointChanged  (false),
    
    m_controlIndex  (0)
    
   
{
    m_window.setTitle("basis");
    m_window.addListener(this);
    m_window.addListener(&m_commonCtrl);

    String name = m_window.showFileLoadDialog("Load model");
    if (name.getLength())
        loadModel(name);

    // Make ui controls.
    for (unsigned i = 0; i < NUM_JOINTS; ++i)
    {
       m_controls.push_back(tuple<ModelerControl, 3>(  ModelerControl(&jointNames[i][0], -M_PI, M_PI, 0.1f, 0),
                                                       ModelerControl(&jointNames[i][0], -M_PI, M_PI, 0.1f, 0),
                                                       ModelerControl(&jointNames[i][0], -M_PI, M_PI, 0.1f, 0)));
    }

    updateUI();

    m_window.getGL()->swapBuffers();

    initRendering();

    m_camera.SetDistance( 2 );
    m_camera.SetCenter( Vec3f( 0.5, 0.5, 0.5 ) );
    
}
Example #8
0
String String::replace(XCHAR cFrom, XCHAR cTo) const
{
	if (!m_pString)
	{
		return String();
	}

	String ret = *this;
	int32 len = ret.getLength();
	for (int32 i=0; i < len; i++)
	{
		if (ret.m_pString[i] == cFrom)
			ret.m_pString[i] = cTo;
	}

	return ret;
}
Example #9
0
void GLContext::Program::init(
    const String& vertexSource,
    GLenum geomInputType, GLenum geomOutputType, int geomVerticesOut, const String& geometrySource,
    const String& fragmentSource)
{
    GLContext::staticInit();
    m_glProgram = glCreateProgram();

    // Setup vertex shader.

    m_glVertexShader = createGLShader(GL_VERTEX_SHADER, "GL_VERTEX_SHADER", vertexSource);
    glAttachShader(m_glProgram, m_glVertexShader);

    // Setup geometry shader (GL_ARB_geometry_shader4).

    if (geometrySource.getLength() == 0)
        m_glGeometryShader = 0;
    else
    {
        m_glGeometryShader = createGLShader(GL_GEOMETRY_SHADER_ARB, "GL_GEOMETRY_SHADER_ARB", geometrySource);
        glAttachShader(m_glProgram, m_glGeometryShader);

        if (!GL_FUNC_AVAILABLE(glProgramParameteriARB))
            fail("glProgramParameteriARB() not available!");
        glProgramParameteriARB(m_glProgram, GL_GEOMETRY_INPUT_TYPE_ARB, geomInputType);
        glProgramParameteriARB(m_glProgram, GL_GEOMETRY_OUTPUT_TYPE_ARB, geomOutputType);
        glProgramParameteriARB(m_glProgram, GL_GEOMETRY_VERTICES_OUT_ARB, geomVerticesOut);
    }

    // Setup fragment shader.

    m_glFragmentShader = createGLShader(GL_FRAGMENT_SHADER, "GL_FRAGMENT_SHADER", fragmentSource);
    glAttachShader(m_glProgram, m_glFragmentShader);

    // Link.

    linkGLProgram(m_glProgram);
}
Example #10
0
// protected
void
FileOutputStreamTestCase::getCurrentOffset (void)
{

    File ff (TEST_FILE_NAME);
    if (ff.exists () == false)
        ff.create ();

    FileOutputStream fout (TEST_FILE_NAME, OPEN_MODE);
    String ss = "dflajdkjasldjfaksldjfsalkdjalksdjadflajdkjasldjfaksldjfsalkdjalksdjadflajdkjasldjfaksldjfsalkdjalksdjadflajdkjasldjfaksldjfsalkdjalksdjadflajdkjasldjfaksldjfsalkdjalksdja sd";
    fout.write ((unsigned char *)ss.getCStr (), ss.getLength ());
    fout.flush ();

    fout.seek (3, BEGIN_ORIGIN) ;

    CPPUNIT_ASSERT (fout.getCurrentOffset ()== 3);

    fout.seek (3, CURRENT_ORIGIN) ;
    CPPUNIT_ASSERT (fout.getCurrentOffset ()== 6);

    fout.seek (-2, CURRENT_ORIGIN) ;
    CPPUNIT_ASSERT (fout.getCurrentOffset ()== 4);

}