Beispiel #1
0
void Essai2()
{
  cout << "----- 2. Test du template ListeTriee avec des Personnes ------------------------" << endl;
  cout << "Creation  d'une Liste triee..." << endl;
  SortedList<Person> liste;
  liste.display();
  cout << endl;

  cout << "On insere quelques personnes..." << endl;
  liste.add(Person("Starzak","Richard"));
  liste.add(Person("Vilvens","Claude"));
  liste.add(Person("Mercenier","Denys"));
  liste.add(Person("Wagner","Jean-Marc"));
  liste.add(Person("Starzak","Luc"));
  liste.add(Person("Charlet","Christophe"));
  liste.add(Person("Moitroux","Cecile"));
  liste.display();
  cout << "La liste contient " << liste.size() << " elements." << endl;
  cout << endl;
}
Beispiel #2
0
void Essai1()
{
  cout << "----- 1. Test du template ListeTriee avec des entiers ------------------------" << endl;
  cout << "Creation  d'une Liste triee..." << endl;
  SortedList<int> liste;
  liste.display();                                       // --> ()
  cout << endl;

  cout << "On insere 3,-2,5,-1,0 et -8..." << endl;
  liste.add(3);
  liste.add(-2);
  liste.add(5);
  liste.add(-1);
  liste.add(0);
  liste.add(-8);
  liste.display();                                       // --> (-8 -2 -1 0 3 5)
  cout << "La liste contient " << liste.size() << " elements." << endl;
  cout << endl;
}
Beispiel #3
0
void TextureTracker::dumpMemoryUsage(String8 &log) {

    log.appendFormat("\nTextureTracker:\n");

    int sum = 0;
    SortedList<String8> list;
    size_t count = mMemoryList.size();
    for (size_t i = 0; i < count; i++) {
        const String8& current = mMemoryList.itemAt(i).mName;
        size_t tmp = list.size();
        bool found = false;
        for (size_t j = 0; j < tmp; j++) {
            if (current == list.itemAt(j)) {
                found = true;
                break;
            }
        }
        if (!found) {
            list.add(current);
        }
    }
    size_t tmp = list.size();

    for (size_t i = 0; i < tmp; i++) {
        const String8& current = list.itemAt(i);
        String8 tmpString;
        int tmpsum = 0;
        for (size_t j = 0; j < count; j++) {
            const TextureEntry& entry = mMemoryList.itemAt(j);
            if (entry.mName == current) {
                String8 format;
                String8 type;
                char s[64];

                switch (entry.mFormat) {
                case GL_RGBA:
                    format = String8("GL_RGBA");
                    break;
                case GL_RGB:
                    format = String8("GL_RGB");
                    break;
                case GL_ALPHA:
                    format = String8("GL_ALPHA");
                    break;
                case GL_LUMINANCE:
                    format = String8("GL_LUMINANCE");
                    break;
                case GL_LUMINANCE_ALPHA:
                    format = String8("GL_LUMINANCE_ALPHA");
                    break;
                default:
                    sprintf(s, "0x%x", entry.mFormat);
                    format = String8(s);
                    break;
                }

                switch (entry.mType) {
                case GL_UNSIGNED_BYTE:
                    type = String8("GL_UNSIGNED_BYTE");
                    break;
                case GL_UNSIGNED_SHORT_4_4_4_4:
                    type = String8("GL_UNSIGNED_SHORT_4_4_4_4");
                    break;
                case GL_UNSIGNED_SHORT_5_5_5_1:
                    type = String8("GL_UNSIGNED_SHORT_5_5_5_1");
                    break;
                case GL_UNSIGNED_SHORT_5_6_5:
                    type = String8("GL_UNSIGNED_SHORT_5_6_5");
                    break;
                case GL_FLOAT:
                    type = String8("GL_FLOAT");
                    break;
                default:
                    sprintf(s, "0x%x", entry.mType);
                    type = String8(s);
                    break;
                }

                tmpString.appendFormat("        %d (%d, %d) (%s, %s) %d <%s> %s\n", entry.mId, entry.mWidth,
                                       entry.mHeight, format.string(), type.string(), entry.mMemory,
                                       entry.mPurpose.string(), entry.mGhost ? "g" : "");
                tmpsum += entry.mMemory;
            }
        }

        sum += tmpsum;
        log.appendFormat("%s: %d bytes, %.2f KB, %.2f MB\n", current.string(), tmpsum, tmpsum / 1024.0f, tmpsum / 1048576.0f);
        log.append(tmpString);
        log.append("\n");
    }


    int rss = load3dUsage();
    log.appendFormat("\nTotal monitored:\n  %d bytes, %.2f KB, %.2f MB\n", sum, sum / 1024.0f, sum / 1048576.0f);
//     log.appendFormat("Physical allocated:\n  %d bytes, %.2f KB, %.2f MB\n", rss, rss / 1024.0f, rss / 1048576.0f);
//     log.appendFormat("Coverage rate:\n  %.2f %%\n", 100 * ((float)sum) / rss);


}
void inheritanceClassDemo()
{
    ListItem *item;

    /* Lets see how the items are created. Please use step into the
     * see how the next instruction creates an element.
     */
    IntListItem intItem0(0);

    /* Now lets see it create a different type of item. Please use
     * step into the see this go to the FloatListItem constructor.
     */
    FloatListItem floatItem0(1.0);

    /* Now we will start adding items to lists. We will create one
     * list that may contain either Integers or Floats.
     */
    List    linkedList;

    /* Let's start adding to the list. Items will be added to the end
     * of the list.
     */
    linkedList.add(intItem0);
    linkedList.add(intItem1);
    linkedList.add(intItem2);
    linkedList.add(floatItem0);
    linkedList.add(floatItem1);
    linkedList.add(floatItem2);

    /* Display the contents of the linked list. Notice a mixture of integers
     * and floating numbers are inserted into the list. The "displayValue"
     * function for these items will be resolved at runtime since "item" is a
     * pointer to the base class ListItem.
     */

    for (item = linkedList.getFirst();
	 item != 0;
	 item = item->getNext())
    {
        item->displayValue();
    }

    /* Remove the items from the list.
     */
    while (linkedList.getFirst() != 0)
    {
        linkedList.remove(*(linkedList.getFirst()));
    }

    /* If you stepped into during the adds, you would have seen how
     * that the member function "add" for List was called. Now we will
     * create another list that is sorted using SortedList which
     * derives from List, but changes the add function to sort the
     * list.
     *
     * NOTE: We will be using the overridded member function "compare"
     *       in the ListItem for each of the derived classes
     *       "IntListItem" and "FloatListItem". Since these cannot be
     *       compared between each other we will create two classes;
     *       one for integers and one for floats.
     */
    SortedList  intList;
    SortedList  floatList;

    /* Add the first items. Please step into the next instructions to
     * see how the "compare" member function get called for
     * IntListItem and FloatListItem. Also notice how the "add" member
     * function get called in the SortedList Class.
     */
    intList.add(intItem1);
    floatList.add(floatItem1);

    /* Now lets add something to the front of the list.
     */
    intList.add(intItem0);
    floatList.add(floatItem0);

    /* Now to the end of the list.
     */
    intList.add(intItem3);
    floatList.add(floatItem3);

    /* Now in the middle.
     */
    intList.add(intItem2);
    floatList.add(floatItem2);

    /* Display the contents of the sorted integer linked list.
     */
    for (item = intList.getFirst();
         item != 0;
         item = item->getNext())
    {
        item->displayValue();
    }

    /* Display the contents of the sorted floating linked list.
     */
    for (item = floatList.getFirst();
         item != 0;
         item = item->getNext())
    {
        item->displayValue();
    }

}