예제 #1
0
void fileInfo(TCHAR* fileName) {

	HANDLE h = CreateFile(fileName, GENERIC_READ, FILE_SHARE_READ, 0, OPEN_EXISTING, 0, 0);

	if (h != IHV)
	{
		DWORD dwSize = GetFileSize(h, 0);
		PBYTE buf = new BYTE[dwSize];
		DWORD dwCount;
		ReadFile(h, buf, dwSize, &dwCount, 0);
		CloseHandle(h);

		BOOL isUnicode = IsUnicode(buf);
		_tprintf(_T("FileName: %s\nFileSize: %d\nFileEncoding %s\n"), fileName, dwSize, (isUnicode ? _T("UNICODE") : _T("ANSI")));
		if (isUnicode)
		{
			wchar_t* buf_wc = (wchar_t*)buf;
			buf_wc++;
			countStrings(buf_wc, dwSize / 2 - 1);
			delete[] --buf_wc;
		}
		else
		{
			char* buf_c = (char *)buf;
			countStrings(buf_c, dwSize);
			delete[] buf_c;
		}
		printf("\n");
	}
}
예제 #2
0
TextArray::TextArray (Text const &i00,
                      Text const &i01,
                      Text const &i02,
                      Text const &i03) throw()
:	Base (countStrings (i00, i01, i02, i03), false)
{
    Text *thisArray = this->getArray();
    
    if (i00.length() > 0) thisArray[ 0] = i00; else return;
    if (i01.length() > 0) thisArray[ 1] = i01; else return;
    if (i02.length() > 0) thisArray[ 2] = i02; else return;
    if (i03.length() > 0) thisArray[ 3] = i03; else return;
}
예제 #3
0
TextArray::TextArray (Text const &i00,
                      Text const &i01,
                      Text const &i02,
                      Text const &i03,
                      Text const &i04,
                      Text const &i05,
                      Text const &i06,
                      Text const &i07) throw()
:   Base (countStrings (i00, i01, i02, i03, i04, i05, i06, i07), false)
{
    Text *thisArray = this->getArray();
    
    if (i00.length() > 0) thisArray[ 0] = i00; else return;
    if (i01.length() > 0) thisArray[ 1] = i01; else return;
    if (i02.length() > 0) thisArray[ 2] = i02; else return;
    if (i03.length() > 0) thisArray[ 3] = i03; else return;
    if (i04.length() > 0) thisArray[ 4] = i04; else return;
    if (i05.length() > 0) thisArray[ 5] = i05; else return;
    if (i06.length() > 0) thisArray[ 6] = i06; else return;
    if (i07.length() > 0) thisArray[ 7] = i07; else return;
}
예제 #4
0
TextArray::TextArray (Text const &i00,
                      Text const &i01,
                      Text const &i02,
                      Text const &i03,
                      Text const &i04,
                      Text const &i05,
                      Text const &i06,
                      Text const &i07,
                      Text const &i08,
                      Text const &i09,
                      Text const &i10,
                      Text const &i11,
                      Text const &i12,
                      Text const &i13,
                      Text const &i14,
                      Text const &i15) throw()
:	Base (countStrings (i00, i01, i02, i03, i04, i05, i06, i07,
                        i08, i09, i10, i11, i12, i13, i14, i15), false)
{
    Text *thisArray = this->getArray();
    
    if (i00.length() > 0) thisArray[ 0] = i00; else return;
    if (i01.length() > 0) thisArray[ 1] = i01; else return;
    if (i02.length() > 0) thisArray[ 2] = i02; else return;
    if (i03.length() > 0) thisArray[ 3] = i03; else return;
    if (i04.length() > 0) thisArray[ 4] = i04; else return;
    if (i05.length() > 0) thisArray[ 5] = i05; else return;
    if (i06.length() > 0) thisArray[ 6] = i06; else return;
    if (i07.length() > 0) thisArray[ 7] = i07; else return;
    if (i08.length() > 0) thisArray[ 8] = i08; else return;
    if (i09.length() > 0) thisArray[ 9] = i09; else return;
    if (i10.length() > 0) thisArray[10] = i10; else return;
    if (i11.length() > 0) thisArray[11] = i11; else return;
    if (i12.length() > 0) thisArray[12] = i12; else return;
    if (i13.length() > 0) thisArray[13] = i13; else return;
    if (i14.length() > 0) thisArray[14] = i14; else return;
    if (i15.length() > 0) thisArray[15] = i15; else return;
}
예제 #5
0
void
sortSubjectsBySimilarityToProbe (char *probe, ListOfStrings subjects, char *distanceMatrix, int *indices)
{
    int i, j, nDistances;
    DistanceMeasure *distances = NULL;
    DistanceMeasure *toSort = NULL;

    int nSubjects = countStrings (subjects);

    /* If we are using a distance matrix, then we load up the
    * list of distances from the probe image. This allows us
    * to lookup the distances from the probe quickly
    */
    if (distanceMatrix)
    {
        Tokenizer tok;
        FILE *f = fopen (makePath (distanceMatrix, probe), "r");
        void *distanceList = NULL;

        DEBUG_CHECK_1ARG (f, "Unable to open file %s in scores directory", makePath (distanceMatrix, probe));

        tokenizerInit (&tok, tokenizerStreamReader, f);
        while (!tokenizerEndOfFile (&tok))
        {
            DistanceMeasure m;
            m.subject = strdup (tokenizerGetWord (&tok));
            m.distance = atof (tokenizerGetWord (&tok));
            listAccumulate (&distanceList, &m, sizeof (DistanceMeasure));
        }
        fclose (f);
        distances = (DistanceMeasure*) listToArray (&distanceList, sizeof (DistanceMeasure), (size_t*)&nDistances);
    }

    /* Copy the list of names into the intermediate data structure that allows us to sort the
    * subjects by distance to the probe.
    */

    toSort = (DistanceMeasure*) malloc (nSubjects * sizeof (DistanceMeasure));

    for (j = 0; j < nSubjects; j++)
    {
        toSort[j].subject = subjects[j];
        toSort[j].distance = 0.0;
        toSort[j].index = j;
    }

    /* Read distances between probe and every other image in the subject list.
    * As a special case, a subject is said to be infinitely far away from him/herself.
    * Random scores are used when a distanceMatrix is not provided */

    for (j = 0; j < nSubjects; j++)
    {
        if (strcmp (subjects[j], probe) == 0) {

            /* Probe and subject are the same. Say they are far apart since
            * we don't want to treat an image and itself as being two replicates
            * of a person */

            toSort[j].distance = HUGE;

        } else if (distanceMatrix != NULL) {

            /* Look for the subject in the list of distances and return assign the 
            * score */

            toSort[j].distance = HUGE;

            for (i = 0; i < nDistances; ++i)
                if (strcmp (distances[i].subject, toSort[j].subject) == 0)
                    toSort[j].distance = distances[i].distance;

        } else {

            /* If we are not using a distance matrix, then choose
            * a random value */

            toSort[j].distance = ((double) rand()) / RAND_MAX;

        }
    }

    /* Now sort the list by similarity to the probe */

    qsort (toSort, nSubjects, sizeof (DistanceMeasure), distanceMeasureComparator);

    /* Copy the data back into the subject list or return the permuted indices */

    if (indices == NULL)
        for (j = 0; j < nSubjects; j++) {
            subjects[j] = toSort[j].subject;
        }
    else
        for (j = 0; j < nSubjects; j++) {
            indices[j] = toSort[j].index;
        } 

        /* Clean up */

        if (distanceMatrix)
        {
            for (i = 0; i < nDistances; ++i)
                free (distances[i].subject);
            free (distances);
        }

        free (toSort);
}
예제 #6
0
TextArray::TextArray (Text const &i00,
                      Text const &i01,
                      Text const &i02,
                      Text const &i03,
                      Text const &i04,
                      Text const &i05,
                      Text const &i06,
                      Text const &i07,
                      Text const &i08,
                      Text const &i09,
                      Text const &i10,
                      Text const &i11,
                      Text const &i12,
                      Text const &i13,
                      Text const &i14,
                      Text const &i15,
                      Text const &i16,
                      Text const &i17,
                      Text const &i18,
                      Text const &i19,
                      Text const &i20,
                      Text const &i21,
                      Text const &i22,
                      Text const &i23,
                      Text const &i24,
                      Text const &i25,
                      Text const &i26,
                      Text const &i27,
                      Text const &i28,
                      Text const &i29,
                      Text const &i30,
                      Text const &i31) throw()
:	Base (countStrings (i00, i01, i02, i03, i04, i05, i06, i07,
                        i08, i09, i10, i11, i12, i13, i14, i15,
                        i16, i17, i18, i19, i20, i21, i22, i23,
                        i24, i25, i26, i27, i28, i29, i30, i31), false)
{
    Text *thisArray = this->getArray();
    
    if (i00.length() > 0) thisArray[ 0] = i00; else return;
    if (i01.length() > 0) thisArray[ 1] = i01; else return;
    if (i02.length() > 0) thisArray[ 2] = i02; else return;
    if (i03.length() > 0) thisArray[ 3] = i03; else return;
    if (i04.length() > 0) thisArray[ 4] = i04; else return;
    if (i05.length() > 0) thisArray[ 5] = i05; else return;
    if (i06.length() > 0) thisArray[ 6] = i06; else return;
    if (i07.length() > 0) thisArray[ 7] = i07; else return;
    if (i08.length() > 0) thisArray[ 8] = i08; else return;
    if (i09.length() > 0) thisArray[ 9] = i09; else return;
    if (i10.length() > 0) thisArray[10] = i10; else return;
    if (i11.length() > 0) thisArray[11] = i11; else return;
    if (i12.length() > 0) thisArray[12] = i12; else return;
    if (i13.length() > 0) thisArray[13] = i13; else return;
    if (i14.length() > 0) thisArray[14] = i14; else return;
    if (i15.length() > 0) thisArray[15] = i15; else return;
    if (i16.length() > 0) thisArray[16] = i16; else return;
    if (i17.length() > 0) thisArray[17] = i17; else return;
    if (i18.length() > 0) thisArray[18] = i18; else return;
    if (i19.length() > 0) thisArray[19] = i19; else return;
    if (i20.length() > 0) thisArray[20] = i20; else return;
    if (i21.length() > 0) thisArray[21] = i21; else return;
    if (i22.length() > 0) thisArray[22] = i22; else return;
    if (i23.length() > 0) thisArray[23] = i23; else return;
    if (i24.length() > 0) thisArray[24] = i24; else return;
    if (i25.length() > 0) thisArray[25] = i25; else return;
    if (i26.length() > 0) thisArray[26] = i26; else return;
    if (i27.length() > 0) thisArray[27] = i27; else return;
    if (i28.length() > 0) thisArray[28] = i28; else return;
    if (i29.length() > 0) thisArray[29] = i29; else return;
    if (i30.length() > 0) thisArray[30] = i30; else return;
    if (i31.length() > 0) thisArray[31] = i31; else return;
}