Example #1
0
// ****************************************************************************
unsigned long cHashedString::CalculateHash(const cString & strIdent)
{
	if(strIdent.IsEmpty())
	{
		return 0;
	}
	// largest prime smaller than 65536
	unsigned long lBASE = 65521L;
	
	// lMAX is the largest n such that // 255n(n+1)/2 + (n+1)(BASE-1) <= 2^32-1
	unsigned int lMAX = 5522;

	unsigned int s1 = 0;
	unsigned int s2 = 0;

	int i = 0;
	unsigned int length = strIdent.GetLength();
	while(length > 0)
	{
		int k = length < lMAX ? length : lMAX;
		length -= k;
		while(--k >= 0)
		{
			s1 += (unsigned int)(tolower(strIdent[i++]) & 0XFF);
			s2 += s1;
		}
		s1 %= lBASE;
		s2 %= lBASE;
	}
	return ((s2 << 16) | s1);
}
Example #2
0
bool cTimeAndDate::SetTimeZone(cString tz, bool isUTC, bool tostdout, cString external_exec) {
	cTimeAndDate *now;
	cExec exec;
	if(geteuid()==0) {
		now=new cTimeAndDate;
		now->SetUTC(isUTC);
		now->SetTimezone(tz);
		ofstream fout;
		if(tostdout) {
			if(!now->ApplyTimeZone(cout)) return false;
		} else {
			if(!cExec::CopyFile("/usr/share/zoneinfo/"+tz,"/etc/localtime")) {
				return false;
			}
			fout.open("/etc/sysconfig/clock");
			if(!now->ApplyTimeZone(fout)) {
				return false;
			}
			fout.close();
		}
		delete now;
	} else if(external_exec!="") {
		if(!external_exec.Contains(tz)) external_exec+=" -timezone "+tz;
		if(isUTC || external_exec.Contains("isUTC")) external_exec+=" -isUTC";
		if(!exec.ForkExecFG(external_exec)) {
			cerr<<"failed to exec: "<<external_exec<<endl;
			return false;
		}
	} else {
		cerr<<"not root, but no external_exec defined either"<<endl;
		return false;
	}
	return true;
}
Example #3
0
// ********** File IO **************** //
bool cStringList::FromFile(const cString & fname) {
	if(fname.Contains('*')) return false;
	#ifndef WIN32
	if(!FileExists(fname)) return false;
	struct stat buf;
	stat(fname,&buf);
	ifstream infile(fname);
	
	if(fname.Contains("/proc") || buf.st_size==0) {
		if(!FromFile(infile)) { infile.close(); return false; }
	} else {
		if(!FromFile(infile,buf.st_size)) { infile.close(); return false; }
	}
	infile.close();
	
	
	if((*this)[-1]=="" && Length()!=0) used--;
	#else
	FILE* fptr=fopen(fname,"r");
	FromFile(fptr);
	fclose(fptr);
	#endif
	
	return true;
}
// Verifies that directory exists.
// Returns success if the directory exists and is readable (failure may mean
// it's busy or permissions denied on win32)
//-----------------------------------------------------------------------------
CPUTResult CPUTFileSystem::DoesDirectoryExist(const cString &path)
{
#ifdef CPUT_OS_ANDROID
    // On Android, all files are in the APK and are compressed.
    // We do not have access to the standard file system, so
    // all files need streaming from memory through the android asset manager
    AAssetManager* assetManager = CPUTWindowAndroid::GetAppState()->activity->assetManager;
    
    AAssetDir* AssetDir = AAssetManager_openDir(assetManager, path.c_str());
    if (AssetDir)
        return CPUT_SUCCESS;
#else
    struct stat fileAttributes;
    
    int result = stat(path.c_str(), &fileAttributes);
    if (result == -1) {
        DEBUG_ERROR(strerror(errno));
        result = CPUT_ERROR; 
    }
	
    if (S_ISDIR(fileAttributes.st_mode)) {
        return CPUT_SUCCESS;
    }
#endif
    return CPUT_ERROR;
}
static void AssignStr(cString &dest, const char *start, const char *end, _locale_t locale)
{
	dest.clear();
	if (end <= start)
    {
		return;
    }

	static const int NBUF = 64;
	wchar_t buf[NBUF];
	int nb = 0;

	size_t len = end - start;
	size_t initial = len + 1; // assume most characters are 1-byte
	dest.reserve(initial);

	const char *p = start;
	while (p < end)
	{
		int len = _mbtowc_l(&buf[nb++], p, end - p, locale);
		if (len < 1)
        {
			break;
        }

		p += len;
		if (p >= end || nb >= NBUF)
		{
			dest.append(buf, nb);
			nb = 0;
		}
	}
}
CPUTFileSystem::CPUTandroidifstream::CPUTandroidifstream(const cString &fileName, std::ios_base::openmode mode) : iCPUTifstream(fileName, mode)
{
    mpAsset = NULL;
    mpAssetDir = NULL;
    mbEOF = true;
    
    // Extract the file and dir
    int length = fileName.length();
    int index = fileName.find_last_of("\\/");
    cString file = fileName.substr(index + 1, (length - 1 - index));
    cString dir  = fileName.substr(0, index);
    
    // On Android, all files are in the APK and are compressed.
    // We do not have access to the standard file system, so
    // all files need streaming from memory through the android asset manager
    AAssetManager* assetManager = CPUTWindowAndroid::GetAppState()->activity->assetManager;
    
    mpAssetDir = AAssetManager_openDir(assetManager, dir.c_str());
    if (!mpAssetDir)
        DEBUG_PRINT("Failed to load asset Dir");
    
    const char* assetFileName = NULL;
    while ((assetFileName = AAssetDir_getNextFileName(mpAssetDir)) != NULL) 
    {
        if (strcmp(file.c_str(), assetFileName) == 0)
        {
            // For some reason we need to pass in the fully pathed filename here, rather than the relative filename
            // that we have just been given. This feels like a bug in Android!
            mpAsset = AAssetManager_open(assetManager, fileName.c_str()/*assetFileName*/, AASSET_MODE_STREAMING);
            if (mpAsset)
                mbEOF = false;
            return;
        }
    }
}
Example #7
0
void FileList_R(cStringList &mylist, cString fullpath, bool usedirs) {
	cStringList split;
//	cerr<<"fullpath="<<fullpath<<endl;
	if(fullpath.Contains('*')) 
		split.FromString(fullpath,"*.");
	else
		split.FromString(fullpath,".");
	FileList_R(mylist,fullpath.ChopRt('/'),fullpath.ChopAllLf('/'),usedirs);
}
Example #8
0
void FileList_1(cStringList &mylist, cString fullpath, bool usedirs) {
	cStringList split;
	if(fullpath.Contains('*')) 
		split.FromString(fullpath,"*.");
	else
		split.FromString(fullpath,".");
		
	FileList_1(mylist,fullpath.ChopRt('/'),fullpath.ChopAllLf('/'),usedirs);
}
Example #9
0
cString cString::pad(const cString& object,
                     uint number,
                     character padding)
{
    if (object.length() >= number)
        return object;

    return object + dup(" ", number - object.length());
}
CPUTKey MapKey(cString strKey)
{
    for(int i = 0; i < KEY_NUM_KEYS; i++)
    {
        if( 0 == strKey.compare(CPUTKeyMap[i].name))
            return CPUTKeyMap[i].value;
    }
    DEBUG_PRINT(_L("Unknown Key: %s"), strKey.c_str());
    return KEY_NUM_KEYS;
}
Example #11
0
//Converts a string day into it's number
int cTimeAndDate::Day2Number(cString day,int st) {
	day=day.ToUpper();
	if(day.Contains("SUN")) return ((0-st)+7)%7;
	if(day.Contains("MON")) return ((1-st)+7)%7;
	if(day.Contains("TUE")) return ((2-st)+7)%7;
	if(day.Contains("WED")) return ((3-st)+7)%7;
	if(day.Contains("THU")) return ((4-st)+7)%7;
	if(day.Contains("FRI")) return ((5-st)+7)%7;
	if(day.Contains("SAT")) return ((6-st)+7)%7;
	return -1;
}
//
// This function parses configuration options from a text string. Removes any previous
// options stored in the configuration list.
//
void CommandParser::ParseConfigurationOptions(cString arguments, cString delimiter)
{
	CleanConfigurationOptions();

	std::vector<cString> argumentList;

	size_t pos;
	size_t nextPos = arguments.find_first_of(delimiter, 0);

	//
	// Break out parameters from command line
	//
	while (nextPos != std::string::npos) {
		pos = nextPos + 1;
		nextPos = arguments.find_first_of(delimiter, pos);
		argumentList.push_back(arguments.substr(pos, nextPos - pos));
	}

	//
	// Remove leading spaces from arguments.
	//
	for (std::vector<cString>::iterator it = argumentList.begin(); it != argumentList.end(); it++) {
		std::string::size_type pos = it->find_first_not_of(' ');
		if (pos != std::string::npos) {
			it->erase(0, pos);
		}
	}

	//
	// Remove trailing spaces from arguments
	//
	for (std::vector<cString>::iterator it = argumentList.begin(); it != argumentList.end(); it++) {
		std::string::size_type pos = it->find_last_not_of(' ');
		if (pos != std::string::npos) {
			it->erase(pos + 1);
		}
	}

	//
	// Split the values from the parameter name
	//
	cString arg;
	for (std::vector<cString>::iterator it = argumentList.begin(); it != argumentList.end(); it++) {
		arg = *it;
		pos = arg.find_first_of(_L(":"), 0);
		if (pos != cString::npos) {
			m_ArgumentMap.insert(std::make_pair(arg.substr(0, pos), arg.substr(pos + 1, std::string::npos)));
		} else {
			m_ArgumentMap.insert(std::make_pair(arg.substr(0, pos), _L("")));
		}
	}

	return;
}
Example #13
0
uint cString::rfind(const cString& string,
                    uint startIndex) const
{
    uint i  = startIndex;
    uint ln = length();
    uint on = string.length();

    // Incase of empty string. Always match
    if (on == 0)
    {
        return startIndex;
    }

    // If the current string is empty, search failed.
    if (ln == 0)
        return 0;

    // If this string doesn't have at least the number of characters 'string'
    // has, the search will probably failed. Returns the length of this string.
    if (ln < on)
        return ln;

    // Set the postion to the end of the string
    if (i >= ln - on)
        i = ln - on;

    bool shouldExit = false;
    do
    {
        /* Try to find a match */
        if (m_buffer->getBuffer()[i] == string.m_buffer->getBuffer()[0])
        {
            /* Scan the reset of the string */
            uint j;
            for (j = i + 1;
                 ((j < ln) && (j < i + on) && (string.m_buffer->getBuffer()[j - i] == m_buffer->getBuffer()[j]));
                 j++)
            {
                /* Match is ok */
            }
            if (j == i + string.length())
                return i;
        }
        // Since i is uint...
        if (i == 0)
            shouldExit = true;
        else
            i--;
    } while (!shouldExit);

    return ln;
}
Example #14
0
/*int cStringList::FromMem(struct memfile &f) {
	int len;
	int bytes=0;
	bytes+=memread(f,&len,sizeof(int));
	cString temp="";
	char * tempchar=NULL;
	for(int i=0; i<len; i++) {
		tempchar=(char*)f.start;
		tempchar+=f.offset;
		temp=tempchar;
		
		bytes+=temp.Length()+1;
		f.offset+=temp.Length()+1;
		(*this)+=temp;
		temp="";
	}
	if((*this)[-1]=="" && Length()!=0) used--;
	return bytes;
}
*/
void cStringList::FromString(const cString &strng, cString delim) {
	if(delim.Length()==1) return FromString(strng,delim[0]);
	delete [] Array;
	Array=NULL;
	allocated=0;
	used=0;	
	Resize(500);
		
	cString substrng=delim;
	cString temp;
	used=1;
	for(int i=0; i<strng.Length(); ) FromString_innerloop(strng,delim,substrng, i);
}
Example #15
0
void cStringList::FromString_innerloop(const cString & strng, cString delim, cString &substrng, int & i) {
	int s=strng.Length();
	for(int j=0; j<delim.Length() && i+j<strng.Length(); j++) substrng[j]=strng[i+j];
	if(substrng!=delim && i<s) {
		if(used+1>allocated) {
			Resize(allocated+500);
		}
		Array[used-1]+=strng[i];
		i++;
	} else {
		used++;
		i+=substrng.Length();
	}
}
tVoid DriverFilter::getManeuverFromString(const cString &name, Maneuver &maneuver)
{
	if (name.Compare("left") == 0)
	{
		maneuver = MANEUVER_LEFT;
	}
	else if (name.Compare("right") == 0)
	{
		maneuver = MANEUVER_RIGHT;
	}
	else if (name.Compare("straight") == 0)
	{
		maneuver = MANEUVER_STRAIGHT;
	}
	else if (name.Compare("parallel_parking") == 0)
	{
		maneuver = MANEUVER_PARALLEL_PARKING;
	}
	else if (name.Compare("cross_parking") == 0)
	{
		maneuver = MANEUVER_CROSS_PARKING;
	}
	else if (name.Compare("pull_out_right") == 0)
	{
		maneuver = MANEUVER_PULL_OUT_RIGHT;
	}
	else if (name.Compare("pull_out_left") == 0)
	{
		maneuver = MANEUVER_PULL_OUT_LEFT;
	}
	else
	{
		LOG_INFO(cString::Format("Unbekannter Befehl: %s", name.GetPtr()));
	}
}
Example #17
0
bool cFile::isFileExist(const cString& filename)
{
    WIN32_FIND_DATA findData;
    HANDLE hFind = FindFirstFile(OS_CSTRING(filename.getBuffer()), &findData);
    if (hFind == INVALID_HANDLE_VALUE)
        return false;
    FindClose(hFind);

    // If filename contains * or ? character this prevent any problems.
    if ((filename.find("*") == filename.length()) &&
        (filename.find("?") == filename.length()))
        return true;
    return false;
}
void CPUTGUIElement::SetText(cString string)
{
    DEBUG_PRINT(_L("GUIElement SetText: %s"), string.c_str());
    mText = string;
    if(mpFont && mpTextMaterial)
    {
        DEBUG_PRINT(_L("\t have font and material"));
        if(!mpTextMesh)
        {
#ifdef CPUT_FOR_DX11
            mpTextMesh = new CPUTMeshDX11();
#else
            mpTextMesh = new CPUTMeshOGL();
#endif
        }
        unsigned int numCharacters = (unsigned int) string.size();
        unsigned int numVertices = numCharacters * 6;
        CPUTGUIVertex* pVB = new CPUTGUIVertex[numVertices];

        CPUTBufferElementInfo pGUIVertex[3] = {
            { "POSITION", 0, 0, CPUT_F32, 3, 3*sizeof(float), 0 },            
            { "TEXCOORD", 0, 1, CPUT_F32, 2, 2*sizeof(float), 3*sizeof(float)},
            { "COLOR",    0, 2, CPUT_F32, 4, 4*sizeof(float), 5*sizeof(float)},
        };
        mpFont->LayoutText(NULL, &mTextWidth, &mTextHeight, mText, 0, 0);
        mTextX = (mWidth-mTextWidth)/2;
        mTextY = (mHeight-mTextHeight)/2;
        mpFont->LayoutText(pVB, &mTextWidth, &mTextHeight, mText, 0, 0);
        mpTextMesh->CreateNativeResources(NULL, 1, 3, pGUIVertex, numVertices, pVB, NULL, 0, NULL);
        
#ifdef CPUT_FOR_DX11
        mpTextMesh->SetMeshTopology(CPUT_TOPOLOGY_INDEXED_TRIANGLE_LIST);
        
        D3D11_INPUT_ELEMENT_DESC layout[] =
        {
            { "POSITION", 0, DXGI_FORMAT_R32G32B32_FLOAT, 0, 0, D3D11_INPUT_PER_VERTEX_DATA, 0 },            
            { "TEXCOORD", 0, DXGI_FORMAT_R32G32_FLOAT, 0, 12, D3D11_INPUT_PER_VERTEX_DATA, 0 },
            { "COLOR", 0, DXGI_FORMAT_R32G32B32A32_FLOAT, 0, 20, D3D11_INPUT_PER_VERTEX_DATA, 0 },
        };
        UINT numElements = ARRAYSIZE( layout );
        ID3DBlob* pBlob = ((CPUTMaterialEffectDX11*)mpTextMaterial->GetMaterialEffects()[0])->GetVertexShader()->GetBlob();
        
        CPUT_DX11::GetDevice()->CreateInputLayout( layout, numElements, pBlob->GetBufferPointer(), pBlob->GetBufferSize(), &mpVertexLayout );
        CPUTSetDebugName( mpVertexLayout, "CPUT GUI InputLayout object");
#else
#endif
        SAFE_DELETE_ARRAY(pVB);
    }
}
// Read the entire contents of a file and return a pointer/size to it
//-----------------------------------------------------------------------------
CPUTResult CPUTFileSystem::ReadFileContents(const cString &fileName, UINT *pSizeInBytes, void **ppData, bool bAddTerminator, bool bLoadAsBinary)
{
    FILE *pFile = NULL;

    errno_t err;
    if (bLoadAsBinary) {
#if defined (UNICODE) || defined(_UNICODE)
        err = _wfopen_s(&pFile, fileName.c_str(), _L("rb"));
#else
        err = fopen_s(&pFile, fileName.c_str(), "rb");
#endif
    } else {
#if defined (UNICODE) || defined(_UNICODE)
        err = _wfopen_s(&pFile, fileName.c_str(), _L("r"));
#else
        err = fopen_s(&pFile, fileName.c_str(), "r");
#endif
    }

    if(0 == err)
    {
        // get file size
        fseek(pFile, 0, SEEK_END);
        *pSizeInBytes = ftell(pFile);
        fseek (pFile, 0, SEEK_SET);

        // allocate buffer
        *ppData = (void*) new char[*pSizeInBytes];
        ASSERT( *ppData, _L("Out of memory") );

        // read it all in
        UINT numBytesRead = (UINT) fread(*ppData, sizeof(char), *pSizeInBytes, pFile);
        if (bAddTerminator)
        {
            ((char *)(*ppData))[numBytesRead++] = '\0';
            (*pSizeInBytes)++;
        }
        //fixme - this isn't doing what it appears to be doing. counts off for Windows...
        //ASSERT( numBytesRead == *pSizeInBytes, _L("File read byte count mismatch.") );
        UNREFERENCED_PARAMETER(numBytesRead);

        // close and return
        fclose(pFile);
        return CPUT_SUCCESS;
    }

    // some kind of file error, translate the error code and return it
    return TranslateFileError(err);
}
Example #20
0
//-----------------------------------------------------------------------------
void CPUTSetDebugName( void *pResource, cString name )
{
#ifdef _DEBUG
    char pCharString[CPUT_MAX_STRING_LENGTH];
    const wchar_t *pWideString = name.c_str();
    UINT ii;
    UINT length = min( (UINT)name.length(), (CPUT_MAX_STRING_LENGTH-1));
    for(ii=0; ii<length; ii++)
    {
        pCharString[ii] = (char)pWideString[ii];
    }
    pCharString[ii] = 0; // Force NULL termination
    ((ID3D11DeviceChild*)pResource)->SetPrivateData( WKPDID_D3DDebugObjectName, (UINT)name.length(), pCharString );
#endif // _DEBUG
}
int GetEventValue(StringMap eventMap[], cString event)
{
    int i = 0; 
    while(eventMap[i].value > 0)
    {
        if(event.compare(eventMap[i].key) == 0)
        {
            DEBUG_PRINT(_L("Found Event: %s\n"), event.c_str());
            return eventMap[i].value;

        }
        i++;
    }
    return -1;
}
Example #22
0
//  *******************************************************************************************************************
const weak_ptr<IXMLNode> cXMLNode::VAddElement(const cString & ElementName, const cString & ElementValue)
{
	const shared_ptr<cXMLNode> pNode(DEBUG_NEW cXMLNode());
	pNode->m_pElement = m_pDoc->NewElement(ElementName.GetData());
	pNode->m_pDoc = m_pDoc;

	if (!ElementValue.IsEmpty())
	{
		XMLText * pText = m_pDoc->NewText(ElementValue.GetData());
		pNode->m_pElement->InsertEndChild(pText);
	}

	m_pElement->LinkEndChild(pNode->m_pElement);
	m_ChildNodes.push_back(pNode);
	return pNode;
}
// Retrieve specified pixel shader
//-----------------------------------------------------------------------------
CPUTResult CPUTAssetLibraryDX11::GetPixelShader(
    const cString        &name,
    ID3D11Device         *pD3dDevice,
    const cString        &shaderMain,
    const cString        &shaderProfile,
    CPUTPixelShaderDX11 **ppPixelShader,
    bool                  nameIsFullPathAndFilename
)
{
    CPUTResult result = CPUT_SUCCESS;
    cString finalName;
    if( name.at(0) == '$' )
    {
        finalName = name;
    } else
    {
        // Resolve name to absolute path
        CPUTOSServices *pServices = CPUTOSServices::GetOSServices();
        pServices->ResolveAbsolutePathAndFilename( nameIsFullPathAndFilename? name : (mShaderDirectoryName + name), &finalName);
    }

    // see if the shader is already in the library
    void *pShader = FindPixelShader(finalName + shaderMain + shaderProfile, true);
    if(NULL!=pShader)
    {
        *ppPixelShader = (CPUTPixelShaderDX11*) pShader;
        (*ppPixelShader)->AddRef();
        return result;
    }
    *ppPixelShader = CPUTPixelShaderDX11::CreatePixelShader( finalName, pD3dDevice, shaderMain, shaderProfile );

    return result;
}
Example #24
0
void cSockAddrIn::getAllHostsName(const cString& name,
                                  cList<cSockAddrIn>& lists,
                                  WORD port /* = 0 */)
{
    socketInitSingleton::GetHandle().init();
    cSockAddrIn ret; // The new constructor INET addressed
    ret.sin_family = AF_INET;
    ret.sin_port   = htons(port);

    lists.removeAll();

    // Lock the mutex
    cLock lock(g_getHostByNameLock);

    /* Invoke the 'gethostname' function call */
    /* Recieve a list of all address          */
    cSArray<char> asciiName = name.getASCIIstring();
    hostent * addr = gethostbyname(asciiName.getBuffer());

    for (unsigned int i = 0; ((DWORD *)addr->h_addr_list[i] != NULL) ; i++)
    {
        /* Get the address */
        #ifndef XSTL_LINUX
            ret.sin_addr.S_un.S_addr = *((DWORD *)(addr->h_addr_list[i])); // Return the first address
        #else
            ret.sin_addr.s_addr = *((DWORD *)(addr->h_addr_list[i])); // Return the first address
        #endif

        /* Fill with new valid address */
        lists.append(ret);
    }
}
//-----------------------------------------------------------------------------
void CPUTAssetLibrary::AddAsset(const cString &name, void *pAsset, CPUTAssetListEntry **pHead)
{
    // convert string to lowercase
    cString lowercaseName = name;
    std::transform(lowercaseName.begin(), lowercaseName.end(), lowercaseName.begin(), ::tolower);

    // Do we already have one by this name?
    CPUTAssetListEntry *pTail = *pHead;
    // TODO:  Save explicit tail pointer instead of iterating to find the null.
    for( CPUTAssetListEntry *pCur=*pHead; NULL!=pCur; pCur=pCur->pNext )
    {
        // Assert that we haven't added one with this name
        ASSERT( 0 != _wcsicmp( pCur->name.data(), name.data() ), _L("Warning: asset ")+name+_L(" already exists") );
        pTail = pCur;
    }
    CPUTAssetListEntry **pDest = pTail ? &pTail->pNext : pHead;
    *pDest = new CPUTAssetListEntry();
    (*pDest)->hash = CPUTComputeHash(name);
    (*pDest)->name = name;
    (*pDest)->pData = pAsset;
    (*pDest)->pNext = NULL;

    // TODO: Our assets are not yet all derived from CPUTRenderNode.
    // TODO: For now, rely on caller performing the AddRef() as it knows the assets type.
    ((CPUTRefCount*)pAsset)->AddRef();
}
Example #26
0
void cException::whereExceptionOccured(cString& ret)
{
    // XXX: NOT PORTABLE!
    ret = m_atFile;
    ret.concat(":");
    ret+= cString(m_atLine, 10, 10);
}
//-----------------------------------------------------------------------------
CPUTResult CPUTTextureDX11::CreateNativeTexture(
    ID3D11Device *pD3dDevice,
    const cString &fileName,
    ID3D11ShaderResourceView **ppShaderResourceView,
    ID3D11Resource **ppTexture,
    bool ForceLoadAsSRGB)
{
    HRESULT hr;

    hr = DirectX::CreateDDSTextureFromFileEx(
        pD3dDevice,
        fileName.c_str(),
        0,//maxsize
        D3D11_USAGE_DEFAULT,
        D3D11_BIND_SHADER_RESOURCE,
        0,
        0,
        ForceLoadAsSRGB,
        ppTexture,
        ppShaderResourceView);
	if( FAILED( hr ) )
	{
		ASSERT( false, _L("Failed to load texture: ") + fileName )
		return CPUT_TEXTURE_LOAD_ERROR;
	}

    CPUTSetDebugName( *ppTexture, fileName );
    CPUTSetDebugName( *ppShaderResourceView, fileName );

    return CPUT_SUCCESS;
}
Example #28
0
cSockAddrIn cSockAddrIn::getHostByName(const cString& name, WORD port /* = 0 */)
{
    socketInitSingleton::GetHandle().init();
    cSockAddrIn ret;

    ret.sin_family = AF_INET;
    ret.sin_port = htons(port);

    // Lock the mutex
    cLock lock(g_getHostByNameLock);

    // Query the address.
    cSArray<char> asciiName = name.getASCIIstring();
    hostent* addr = gethostbyname(asciiName.getBuffer());

    // Return the first address of the hostent struct.
    #if defined(XSTL_WINDOWS) || defined (XSTL_CE)
        // Windows ordering.
        ret.sin_addr.S_un.S_addr = *((DWORD *)(addr->h_addr_list[0]));
    #else
    #ifdef XSTL_LINUX
        // Linux version
        ret.sin_addr.s_addr = *((DWORD *)(addr->h_addr_list[0]));
    #else
        #error "Add platform functionalty here!";
    #endif
    #endif

    return ret;
}
Example #29
0
//  *******************************************************************************************************************
void cString::Insert(const int index, const cString & text)
{
    if (index >= 0 && index <= GetLength())
    {
        m_str.insert(index, text.GetData());
    }
}
Example #30
0
cRoadSigns::cRoadSigns(cString filename,RoadSign enumGiven , tInt minHessian, tInt shapeIdentifier) : m_detector(minHessian,20) //setting parameters of detector minHessian and nOctaves
{
	//m_image = imread(filename, CV_LOAD_IMAGE_GRAYSCALE );	
	m_enumSign = enumGiven;
	m_shapeIdentifier = shapeIdentifier;
	if (std::ifstream(filename.GetPtr()))
	{
		m_image = imread(filename.GetPtr(), CV_LOAD_IMAGE_COLOR);
		//blur(m_image,m_image,cvSize(9,9));
		m_minHessian = minHessian;
#if defined(WIN32)
		//setting parameters of detector
		m_detector.set("hessianThreshold",minHessian);
		m_detector.set("nOctaves",20);
#endif

		m_detector.detect( m_image, m_keypoints );
		
		if (m_keypoints.size() == 0)
			{
			m_state=tFalse;
			return;
			}
		//remove keypoints which are near to border
		tInt borderSize = m_image.cols/4;	 	 
		m_keypoints.erase( remove_if(m_keypoints.begin(), m_keypoints.end(),
								   RoiPredicatePic((tFloat32)borderSize, (tFloat32)borderSize,
												(tFloat32)(m_image.cols - borderSize),
												(tFloat32)(m_image.rows - borderSize))),
						 m_keypoints.end() );
	
		m_extractor.compute( m_image, m_keypoints, m_descriptors );

		if (m_descriptors.total() == 0)
			{
			m_state=tFalse;
			return;
			}

		//drawKeypoints( m_image, m_keypoints, m_image, Scalar::all(-1), DrawMatchesFlags::DEFAULT );

		m_state = tTrue;
	}
	else
		m_state=tFalse;
}