Exemplo n.º 1
0
static void _BubbleSort(Array<CIMKeyBinding>& x)
{
    Uint32 n = x.size();

    //
    //  If the key is a reference, the keys in the reference must also be
    //  sorted
    //
    for (Uint32 k = 0; k < n ; k++)
        if (x[k].getType () == CIMKeyBinding::REFERENCE)
        {
            CIMObjectPath tmp (x[k].getValue ());
            Array <CIMKeyBinding> keyBindings = tmp.getKeyBindings ();
            _BubbleSort (keyBindings);
            tmp.setKeyBindings (keyBindings);
            x[k].setValue (tmp.toString ());
        }

    if (n < 2)
        return;

    for (Uint32 i = 0; i < n - 1; i++)
    {
        for (Uint32 j = 0; j < n - 1; j++)
        {
            if (String::compareNoCase(x[j].getName().getString(),
                                      x[j+1].getName().getString()) > 0)
            {
                CIMKeyBinding t = x[j];
                x[j] = x[j+1];
                x[j+1] = t;
            }
        }
    }
}
Exemplo n.º 2
0
/*********************************************************************
*
*       _Sort
*
* Purpose:
*   Sorts the contents of the LISTVIEW by using the qsort algorithm.
*   The compare function is called for each compare operation with valid
*   pointers to cell data of the specified column.
*/
static int _Sort(LISTVIEW_Handle hObj) {
    WM_HMEM hSortArray;
    SORT_OBJECT SortObject;
    int NumItems, NumItemsReq, i, Sel;
    SortObject.pObj = LISTVIEW_H2P(hObj);
    if (((SortObject.pObj->IsPresorted) && (SortObject.pObj->IsSorted)) || (SortObject.pObj->hSort == 0)) {
        return 0;
    }
    SortObject.pSort = (LISTVIEW_SORT *)GUI_ALLOC_h2p(SortObject.pObj->hSort);
    NumItemsReq = SortObject.pObj->RowArray.NumItems;
    NumItems    = SortObject.pSort->SortArrayNumItems;
    Sel = _GetSelUnsorted(SortObject.pObj);
    /* Adjust number of items in sort array */
    if (NumItems != NumItemsReq) {
        if (!SortObject.pSort->hSortArray) {
            hSortArray = GUI_ALLOC_AllocZero(sizeof(SORT_TYPE) * NumItemsReq);
        } else {
            hSortArray = GUI_ALLOC_Realloc(SortObject.pSort->hSortArray, sizeof(SORT_TYPE) * NumItemsReq);
        }
        if (!hSortArray) {
            return 1;
        }
        SortObject.pObj = LISTVIEW_H2P(hObj);
        SortObject.pSort = (LISTVIEW_SORT *)GUI_ALLOC_h2p(SortObject.pObj->hSort);
        SortObject.pSort->hSortArray = hSortArray;
    }
    SortObject.paSortArray = (SORT_TYPE *)GUI_ALLOC_h2p(SortObject.pSort->hSortArray);
    if (SortObject.pObj->IsPresorted) {
        /* Add new indices */
        if (NumItems < NumItemsReq) {
            SortObject.pObj->ReverseSort = 0; /* Reverse sort only allowed if listview is presorted and no rows are added */
            for (i = NumItems; i < NumItemsReq; i++) {
                *(SortObject.paSortArray + i) = i;
            }
        }
    } else {
        SortObject.pObj->ReverseSort = 0; /* Reverse sort only allowed if listview is presorted */
        /* Fill with indices if not presorted */
        for (i = 0; i < NumItemsReq; i++) {
            *(SortObject.paSortArray + i) = i;
        }
    }
    SortObject.pSort->SortArrayNumItems = NumItemsReq;
    /* Sort only if more than one item is available */
    if (NumItemsReq > 1) {
        if (SortObject.pObj->ReverseSort) {
            _Reverse(&SortObject);
        } else {
            _BubbleSort(0, NumItemsReq - 1, &SortObject);
        }
        _SetSelUnsorted(hObj, SortObject.pObj, Sel);
    }
    SortObject.pObj->IsPresorted = 1;
    SortObject.pObj->IsSorted    = 1;
    HEADER_SetDirIndicator(SortObject.pObj->hHeader, SortObject.pObj->SortIndex, SortObject.pSort->Reverse);
    return 0;
}
Exemplo n.º 3
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)
        {
            throw MalformedObjectNameException(objectName);
        }

        *equalsign = 0;

        if (!CIMName::legal(p))
            throw MalformedObjectNameException(objectName);

        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++;

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

                    if ((*p != '\\') && (*p != '"'))
                    {
                        throw MalformedObjectNameException(objectName);
                    }
                }

                valueString.append(*p++);
            }

            if (*p++ != '"')
                throw MalformedObjectNameException(objectName);

            /*
                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;

            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)))
                throw MalformedObjectNameException(objectName);

            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;
            }

            Sint64 x;

            if (!XmlReader::stringToSignedInteger(p, x))
                throw MalformedObjectNameException(objectName);

            valueString.assign(p, n);

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

            p = p + n;
        }

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

        if (*p)
        {
            if (*p++ != ',')
            {
                throw MalformedObjectNameException(objectName);
            }
        }
    }

    _BubbleSort(keyBindings);
}
Exemplo n.º 4
0
void CIMObjectPath::setKeyBindings(const Array<CIMKeyBinding>& keyBindings)
{
    _rep->_keyBindings = keyBindings;
    _BubbleSort(_rep->_keyBindings);
}