Esempio n. 1
0
static void _Sort(Array<CIMKeyBinding>& x)
{
    CIMKeyBinding* data = (CIMKeyBinding*)x.getData();
    Uint32 size = x.size();

    //
    //  If the key is a reference, the keys in the reference must also be
    //  sorted
    //
    for (Uint32 k = 0; k < size; k++)
    {
        CIMKeyBinding& kb = data[k];

        if (kb.getType() == CIMKeyBinding::REFERENCE)
        {
            CIMObjectPath tmp(kb.getValue());
            Array<CIMKeyBinding> keyBindings = tmp.getKeyBindings();
            _Sort(keyBindings);
            tmp.setKeyBindings(keyBindings);
            kb.setValue(tmp.toString());
        }
    }

    if (size < 2)
        return;

    qsort((void*)data, size, sizeof(CIMKeyBinding), _compare);
}
/*********************************************************************
*
*       LISTVIEW_SetSelUnsorted
*
* Purpose:
*   If sorting is disabled, the behaviour is the same as LISTVIEW_SetSel().
*   It sets the 'visible' selection index.
*   If sorting is enabled, the function sets the 'unselected' index of the selected
*   the selected row.
*/
void LISTVIEW_SetSelUnsorted(LISTVIEW_Handle hObj, int Sel) {
    if (hObj) {
        LISTVIEW_Obj * pObj;
        WM_LOCK();
        pObj = LISTVIEW_H2P(hObj);
        _Sort(hObj);
        _SetSelUnsorted(hObj, pObj, Sel);
        WM_UNLOCK();
    }
}
/*********************************************************************
*
*       LISTVIEW_GetSelUnsorted
*
* Purpose:
*   If sorting is disabled, the behaviour is the same as LISTVIEW_GetSel().
*   It returns the 'visible' selection index.
*   If sorting is enabled, the function returns the 'unselected' index of
*   the selected row.
*/
int LISTVIEW_GetSelUnsorted(LISTVIEW_Handle hObj) {
    int r = -1;
    if (hObj) {
        LISTVIEW_Obj * pObj;
        WM_LOCK();
        pObj = LISTVIEW_H2P(hObj);
        _Sort(hObj);
        r = _GetSelUnsorted(pObj);
        WM_UNLOCK();
    }
    return r;
}
Esempio n. 4
0
void CIMObjectPath::set(
    const String& host,
    const CIMNamespaceName& nameSpace,
    const CIMName& className,
    const Array<CIMKeyBinding>& keyBindings)
{
    if ((host != String::EMPTY) && !CIMObjectPathRep::isValidHostname(host))
    {
        MessageLoaderParms mlParms(
            "Common.CIMObjectPath.INVALID_HOSTNAME",
            "$0, reason:\"invalid hostname\"",
            host);

        throw MalformedObjectNameException(mlParms);
    }

    _rep = _copyOnWriteCIMObjectPathRep(_rep);

    _rep->_host.assign(host);
    _rep->_nameSpace = nameSpace;
    _rep->_className = className;
    _rep->_keyBindings = keyBindings;
    _Sort(_rep->_keyBindings);
}
Esempio n. 5
0
//ÅÅÐò½Ó¿Úº¯Êý(bAsc=TRUEÉýÐò)
void SortList(CStringList &KeyList, CStringList &ValList, BOOL bAsc)
{
	int Count = KeyList.GetCount();

	_rec *r = new _rec[Count*sizeof(_rec)];

	POSITION posKey = KeyList.FindIndex(0);
	POSITION posVal = ValList.FindIndex(0);

	int i=0;
	while(posKey && posVal)
	{
		CString Key = KeyList.GetNext(posKey);
		CString Val = ValList.GetNext(posVal);
		r[i].key = Key;
		r[i].val = Val;		
		i++;
	}

	//ÅÅÐòº¯Êý
	_Sort(r,Count,bAsc);

	KeyList.RemoveAll();
	ValList.RemoveAll();

	for(int j=0; j<Count; j++)
	{
		CString s1 = r[j].key;
		CString s2 = r[j].val;

		KeyList.AddTail(r[j].key);
		ValList.AddTail(r[j].val);
	}

	delete[] r;
}
Esempio n. 6
0
void CIMObjectPath::setKeyBindings(const Array<CIMKeyBinding>& keyBindings)
{
    _rep = _copyOnWriteCIMObjectPathRep(_rep);
    _rep->_keyBindings = keyBindings;
    _Sort(_rep->_keyBindings);
}
Esempio n. 7
0
/**
    ATTN-RK: The DMTF specification for the string form of an
    object path makes it impossible for a parser to distinguish
    between a key values of String type and Reference type.

    Given the ambiguity, this implementation takes a guess at the
    type of a quoted key value.  If the value can be parsed into
    a CIMObjectPath with at least one key binding, the type is
    set to REFERENCE.  Otherwise, the type is set to STRING.
    Note: This algorithm appears to be in line with what the Sun
    WBEM Services implementation does.

    To be totally correct, it would be necessary to retrieve the
    class definition and look up the types of the key properties
    to determine how to interpret the key values.  This is clearly
    too inefficient for internal transformations between
    CIMObjectPaths and String values.
*/
void _parseKeyBindingPairs(
    const String& objectName,
    char*& p,
    Array<CIMKeyBinding>& keyBindings)
{
    // Get the key-value pairs:

    while (*p)
    {
        // Get key part:

        char* equalsign = strchr(p, '=');
        if (!equalsign)
        {
            MessageLoaderParms mlParms(
                "Common.CIMObjectPath.INVALID_KEYVALUEPAIR",
                "$0, reason:\"invalid key-value pair, missing equal sign\"",
                objectName);
            throw MalformedObjectNameException(mlParms);
        }

        *equalsign = 0;

        if (!CIMName::legal(p))
        {
            MessageLoaderParms mlParms(
                "Common.CIMObjectPath.INVALID_KEYNAME",
                "$0, reason:\"invalid key-value pair, invalid key name:$1\"",
                objectName,
                p);
            throw MalformedObjectNameException(mlParms);
        }

        CIMName keyName (p);

        // Get the value part:

        String valueString;
        p = equalsign + 1;
        CIMKeyBinding::Type type;

        if (*p == '"')
        {
            // Could be CIMKeyBinding::STRING or CIMKeyBinding::REFERENCE

            p++;

            Buffer keyValueUTF8(128);

            while (*p && *p != '"')
            {
                if (*p == '\\')
                {
                    p++;

                    if ((*p != '\\') && (*p != '"'))
                    {
                        MessageLoaderParms mlParms(
                            "Common.CIMObjectPath.INVALID_KEYVALUE",
                            "$0, reason:\"invalid key-value pair, "
                                "malformed value\"",
                            objectName);
                        throw MalformedObjectNameException(mlParms);
                    }
                }

                keyValueUTF8.append(*p++);
            }

            if (*p++ != '"')
            {
                MessageLoaderParms mlParms(
                    "Common.CIMObjectPath.INVALID_KEYVALUEPAIR_MISSINGQUOTE",
                    "$0, reason:\"invalid key-value pair, "
                        "missing quote in key value\"",
                    objectName);
                throw MalformedObjectNameException(mlParms);
            }

            // Convert the UTF-8 value to a UTF-16 String

            valueString.assign(
                (const char*)keyValueUTF8.getData(),
                keyValueUTF8.size());

            /*
                Guess at the type of this quoted key value.  If the value
                can be parsed into a CIMObjectPath with at least one key
                binding, the type is assumed to be a REFERENCE.  Otherwise,
                the type is set to STRING.  (See method header for details.)
             */
            type = CIMKeyBinding::STRING;

            /* Performance shortcut will check for
               equal sign instead of doing the full
               CIMObjectPath creation and exception handling
            */
            if (strchr(keyValueUTF8.getData(), '='))
            {
                // found an equal sign, high probability for a reference
                try
                {
                    CIMObjectPath testForPath(valueString);
                    if (testForPath.getKeyBindings().size() > 0)
                    {
                        // We've found a reference value!
                        type = CIMKeyBinding::REFERENCE;
                    }
                }
                catch (const Exception &)
                {
                    // Not a reference value; leave type as STRING
                }
            }
        }
        else if (toupper(*p) == 'T' || toupper(*p) == 'F')
        {
            type = CIMKeyBinding::BOOLEAN;

            char* r = p;
            Uint32 n = 0;

            while (*r && *r != ',')
            {
                *r = toupper(*r);
                r++;
                n++;
            }

            if (!(((strncmp(p, "TRUE", n) == 0) && n == 4) ||
                  ((strncmp(p, "FALSE", n) == 0) && n == 5)))
            {
                MessageLoaderParms mlParms(
                    "Common.CIMObjectPath.INVALID_BOOLVALUE",
                    "$0, reason:\"invalid key-value pair, "
                        "value should be TRUE or FALSE\"",
                    objectName);
                throw MalformedObjectNameException(mlParms);
            }

            valueString.assign(p, n);

            p = p + n;
        }
        else
        {
            type = CIMKeyBinding::NUMERIC;

            char* r = p;
            Uint32 n = 0;

            while (*r && *r != ',')
            {
                r++;
                n++;
            }

            Boolean isComma = false;
            if (*r)
            {
                *r = '\0';
                isComma = true;
            }

            if (*p == '-')
            {
                Sint64 x;
                if (!StringConversion::stringToSignedInteger(p, x))
                {
                    MessageLoaderParms mlParms(
                        "Common.CIMObjectPath.INVALID_NEGATIVNUMBER_VALUE",
                        "$0, reason:\"invalid key-value pair, "
                            "invalid negative number value $1\"",
                        objectName,
                        p);
                    throw MalformedObjectNameException(mlParms);
                }
            }
            else
            {
                Uint64 x;
                if (!StringConversion::stringToUnsignedInteger(p, x))
                {
                    MessageLoaderParms mlParms(
                        "Common.CIMObjectPath.INVALID_NEGATIVNUMBER_VALUE",
                        "$0, reason:\"invalid key-value pair, "
                            "invalid number value $1\"",
                        objectName,
                        p);
                    throw MalformedObjectNameException(mlParms);
                }
            }

            valueString.assign(p, n);

            if (isComma)
            {
                *r = ',';
            }

            p = p + n;
        }

        keyBindings.append(CIMKeyBinding(keyName.getString (), valueString,
            type));

        if (*p)
        {
            if (*p++ != ',')
            {
                MessageLoaderParms mlParms(
                    "Common.CIMObjectPath.INVALID_KEYVALUEPAIR_MISSCOMMA",
                    "$0, reason:\"invalid key-value pair, "
                        "next key-value pair has to start with comma\"",
                    objectName);
                throw MalformedObjectNameException(mlParms);
            }
        }
    }

    _Sort(keyBindings);
}
Esempio n. 8
0
const SdfPathVector &
Hd_SortedIds::GetIds()
{
    _Sort();
    return _ids;
}
Esempio n. 9
0
void MapGridCtrl::Sort(SortKey vertical, SortKey horizontal, bool vertical_direction, bool horizontal_direction)
{
	if (m_maps.empty())
		return;

	// Always start by sorting on name, to get duplicate maps together.
	SortKey keys[3] = {SortKey_Name, vertical, horizontal};
	bool dirs[3] = {false, vertical_direction, horizontal_direction};

	// This looks like common antipattern 'loop switch sequence', however here
	// it's the best way I found to prevent duplication of the switch statement,
	// which will probably require most (all?) changes and possibly grow big.

	for (int i = 0; i < 3; ++i) {
		// Do nothing if current sortkey is same as previous one.
		if (i > 0 && keys[i] == keys[i - 1] && dirs[i] == dirs[i - 1])
			continue;
		// Sort dimension i on sortkey keys[i].
		const bool d = dirs[i];
		switch (keys[i]) {
			case SortKey_Name:
				_Sort(i, _Compare(d, CompareName));
				break;
			case SortKey_TidalStrength:
				_Sort(i, _Compare(d, CompareTidalStrength));
				break;
			case SortKey_Gravity:
				_Sort(i, _Compare(d, CompareGravity));
				break;
			case SortKey_MaxMetal:
				_Sort(i, _Compare(d, CompareMaxMetal));
				break;
			case SortKey_ExtractorRadius:
				_Sort(i, _Compare(d, CompareExtractorRadius));
				break;
			case SortKey_MinWind:
				_Sort(i, _Compare(d, CompareMinWind));
				break;
			case SortKey_MaxWind:
				_Sort(i, _Compare(d, CompareMaxWind));
				break;
			case SortKey_Wind:
				_Sort(i, _Compare(d, CompareWind));
				break;
			case SortKey_Area:
				_Sort(i, _Compare(d, CompareArea));
				break;
			case SortKey_AspectRatio:
				_Sort(i, _Compare(d, CompareAspectRatio));
				break;
			case SortKey_PosCount:
				_Sort(i, _Compare(d, ComparePosCount));
				break;
			default:
				ASSERT_EXCEPTION(false, _T("unimplemented SortKey in MapGridCtrl::Sort"));
				break;
		}
	}
}