Пример #1
0
int QStringListEx::findFirstDifference
(
    void
)
    const
{
    int    length     = getMinLength();
    bool   difference = false;
    int    offset;

    for ( offset = 0; offset < length; offset++ )
    {
        QChar reference = at( 0 )[ offset ];

        foreach ( QString const & string, *this )
        {
            if ( string[ offset ] != reference )
            {
                difference = true;
                break;
            }
        }

        if ( difference )
        {
            break;
        }
    }

    return offset;
}
Пример #2
0
//
// Check facet among self
//         check common facets
//         check Additional Facet Constraint
//
void AbstractStringValidator::inspectFacet(MemoryManager* const manager)
{

    int thisFacetsDefined = getFacetsDefined();

    if (!thisFacetsDefined)
        return;

    // check 4.3.1.c1 error: length & (maxLength | minLength)
    if ((thisFacetsDefined & DatatypeValidator::FACET_LENGTH) != 0)
    {
        if ((thisFacetsDefined & DatatypeValidator::FACET_MAXLENGTH) != 0)
            ThrowXMLwithMemMgr(InvalidDatatypeFacetException, XMLExcepts::FACET_Len_maxLen, manager);
        else if (((thisFacetsDefined & DatatypeValidator::FACET_MINLENGTH) != 0))
            ThrowXMLwithMemMgr(InvalidDatatypeFacetException, XMLExcepts::FACET_Len_minLen, manager);
    }

    // check 4.3.2.c1 must: minLength <= maxLength
    if ((thisFacetsDefined & (DatatypeValidator::FACET_MINLENGTH
        |DatatypeValidator::FACET_MAXLENGTH)) != 0)
    {
        int thisMinLength = getMinLength();
        int thisMaxLength = getMaxLength();
        if ( thisMinLength > thisMaxLength )
        {
            REPORT_FACET_ERROR(thisMaxLength
                             , thisMinLength
                             , XMLExcepts::FACET_maxLen_minLen
                             , manager)
        }
    }
Пример #3
0
int QStringListEx::findReverseFirstDifference
(
    void
)
    const
{
    int   length = getMinLength();
    int   offset = 0;

    if ( length > 0 )
    {
        bool difference = false;

        for ( offset = 1; offset <= length; offset++ )
        {
            QChar reference = at( 0 )[ at( 0 ).length() - offset ];

            foreach ( QString const & string, *this )
            {
                if ( string[ string.length() - offset ] != reference )
                {
                    difference = true;
                    break;
                }
            }

            if ( difference )
            {
                break;
            }
        }
    }
Пример #4
0
//
// here content is a list of items
//
void ListDatatypeValidator::checkContent(       BaseRefVectorOf<XMLCh>*       tokenVector
                                        , const XMLCh*                  const content
                                        ,       ValidationContext*      const context
                                        ,       bool                          asBase
                                        ,       MemoryManager*          const manager)
{
    DatatypeValidator* bv = getBaseValidator();

    if (bv->getType() == DatatypeValidator::List)
        ((ListDatatypeValidator*)bv)->checkContent(tokenVector, content, context, true, manager);
    else
    {   // the ultimate itemType DTV
        for (unsigned int i = 0; i < tokenVector->size(); i++)
            bv->validate(tokenVector->elementAt(i), context, manager);
    }

    int thisFacetsDefined = getFacetsDefined();

    // we check pattern first
    if ( (thisFacetsDefined & DatatypeValidator::FACET_PATTERN ) != 0 )
    {
        // lazy construction
        if (getRegex() == 0)
        {
            try {
                setRegex(new (fMemoryManager) RegularExpression(getPattern(), SchemaSymbols::fgRegEx_XOption, fMemoryManager));            	
            }
            catch (XMLException &e)
            {
                ThrowXMLwithMemMgr1(InvalidDatatypeValueException, XMLExcepts::RethrowError, e.getMessage(), manager);
            }
        }

        //check every item in the list as a whole
        if (getRegex()->matches(content, manager) == false)
        {
            ThrowXMLwithMemMgr2(InvalidDatatypeValueException
                    , XMLExcepts::VALUE_NotMatch_Pattern
                    , content
                    , getPattern()
                    , manager);
        }

    }

    // if this is a base validator, we only need to check pattern facet
    // all other facet were inherited by the derived type
    if (asBase)
        return;

    unsigned int tokenNumber = tokenVector->size();

    if (((thisFacetsDefined & DatatypeValidator::FACET_MAXLENGTH) != 0) &&
        (tokenNumber > getMaxLength()))
    {
        XMLCh value1[BUF_LEN+1];
        XMLCh value2[BUF_LEN+1];
        XMLString::binToText(tokenNumber, value1, BUF_LEN, 10, manager);
        XMLString::binToText(getMaxLength(), value2, BUF_LEN, 10, manager);

        ThrowXMLwithMemMgr3(InvalidDatatypeValueException
                , XMLExcepts::VALUE_GT_maxLen
                , getContent()
                , value1
                , value2
                , manager);
    }

    if (((thisFacetsDefined & DatatypeValidator::FACET_MINLENGTH) != 0) &&
        (tokenNumber < getMinLength()))
    {
        XMLCh value1[BUF_LEN+1];
        XMLCh value2[BUF_LEN+1];
        XMLString::binToText(tokenNumber, value1, BUF_LEN, 10, manager);
        XMLString::binToText(getMinLength(), value2, BUF_LEN, 10, manager);

        ThrowXMLwithMemMgr3(InvalidDatatypeValueException
                , XMLExcepts::VALUE_LT_minLen
                , getContent()
                , value1
                , value2
                , manager);
    }

    if (((thisFacetsDefined & DatatypeValidator::FACET_LENGTH) != 0) &&
        (tokenNumber != AbstractStringValidator::getLength()))
    {
        XMLCh value1[BUF_LEN+1];
        XMLCh value2[BUF_LEN+1];
        XMLString::binToText(tokenNumber, value1, BUF_LEN, 10, manager);
        XMLString::binToText(AbstractStringValidator::getLength(), value2, BUF_LEN, 10, manager);

        ThrowXMLwithMemMgr3(InvalidDatatypeValueException
                , XMLExcepts::VALUE_NE_Len
                , getContent()
                , value1
                , value2
                , manager);
    }

    if ((thisFacetsDefined & DatatypeValidator::FACET_ENUMERATION) != 0 &&
        (getEnumeration() != 0))
    {
        int i;
        int enumLength = getEnumeration()->size();

        for ( i = 0; i < enumLength; i++)
        {
            //optimization: we do a lexical comparision first
            // this may be faster for string and its derived
            if (XMLString::equals(getEnumeration()->elementAt(i), getContent()))
                break; // a match found

            // do a value space check
            // this is needed for decimal (and probably other types
            // such as datetime related)
            // eg.
            // tokenVector = "1 2 3.0 4" vs enumeration = "1 2 3 4.0"
            //
            if (valueSpaceCheck(tokenVector, getEnumeration()->elementAt(i), manager))
                break;
        }

        if (i == enumLength)
            ThrowXMLwithMemMgr1(InvalidDatatypeValueException, XMLExcepts::VALUE_NotIn_Enumeration, getContent(), manager);

    } // enumeration

}
Graph * parseInputFile( const char * inputFile )
{
	FILE * fptr = NULL;
	int numUsers;
	float delta1;
	float delta2;
	float alpha;
	int queryId;
	int i = 0;
	Graph * graph1 = NULL;
	Graph * graph2 = NULL;
	User * userList = NULL;
	int id;
	int age;
	int gender;
	int maritalStatus;
	int race;
	int birthPlace;
	int language;
	int occupation;
	int income;

	//	Open file and check if successful
	fptr = fopen( inputFile, "r" );

	if( fptr == NULL )
	{
		printf( "ERROR!\nFile %s could not be opened!\n", inputFile );
		return 0;
	}

	//	Get lines
	fscanf( fptr, "%d,%f,%f,%d,%f", &numUsers, &delta1, &delta2, &queryId, &alpha );

	//	Allocate user List
	userList = malloc( sizeof(User) * numUsers );

	for( i = 0; i < numUsers; i++ )
	{
		//	Parse inputs
		fscanf( fptr, "%d,%d,%d,%d,%d,%d,%d,%d,%d",
				&id,
				&age,
				&gender,
				&maritalStatus,
				&race,
				&birthPlace,
				&language,
				&occupation,
				&income );

		//	Create user instance
		createUser( &userList[i], id, age, gender, maritalStatus, race,
				birthPlace, language, occupation, income );
	}

	//printUserList( userList, numUsers );

	graph1 = createGraph( userList, numUsers, delta1 );
	graph2 = createGraph( userList, numUsers, delta2 );

	/*
	int inputid;
	printf( "Enter user id for friends\n" );
	scanf( "%d", &inputid );
	while( inputid != 0 )
	{
		printFriendList( graph1, &(graph1 -> userList[ inputid - 1 ]) );
		printf( "Enter user id for friends\n" );
		scanf( "%d", &inputid );
	}

	int j;
	for( i = 0; i < numUsers; i ++ )
	{
		for( j = 0; j < numUsers; j++ )
		{
			printRelationBetween( graph1,
			&(graph1 -> userList[i]), &(graph1 -> userList[j]) );
		}
	}
	*/

	//  ~~~~~~~~~~~~~~~~~~~	QUERYS ~~~~~~~~~~~~~~~~~~~

	//	Dense Graph
	printf(  "Dense Graph : \n-------------\n" );
	printf(  "\n** Query1 **\n" );
	getMinLength( graph1, queryId );
	printf(  "\n** Query2 **\n" );
	getAllNode( graph1, queryId, alpha );
	printf(  "\n** Query3 **\n" );
	getFriends( graph1, queryId );
	printf(  "\n** Query4 **\n" );
	getFriendsOfFriends( graph1, queryId );
	printf(  "\n** Query5 **\n" );
	getAvgDegreeOfNode( graph1 );
	printf(  "\n** Query6 **\n" );
	getAvgDegreeOfSecondNode( graph1 );

	//	Sparse Graph
	printf(  "\nSparse Graph : \n-------------\n" );
	printf(  "\n** Query1 **\n" );
	getMinLength( graph2, queryId );
	printf(  "\n** Query2 **\n" );
	getAllNode( graph2, queryId, alpha );
	printf(  "\n** Query3 **\n" );
	getFriends( graph2, queryId );
	printf(  "\n** Query4 **\n" );
	getFriendsOfFriends( graph2, queryId );
	printf(  "\n** Query5 **\n" );
	getAvgDegreeOfNode( graph2 );
	printf(  "\n** Query6 **\n" );
	getAvgDegreeOfSecondNode( graph2 );

	//  ~~~~~~~~~~~~~~~~~~~	CLEAN UP  ~~~~~~~~~~~~~~~~~~~

	destroyUserList( userList );
	destroyGraph( graph1 );
	destroyGraph( graph2 );

	//	Close file
	fclose( fptr );
	return NULL;
}