Beispiel #1
0
void test_findmax()
{
#if FINDMAX
    printf("Running test_findmax\n");
    SortedList l1, l2;
    int	m1, m2;

    readFile(l1, file1);
    readFile(l2, file2);
    m1 = l1.findMax();
    m2 = l2.findMax();
    cout << "list is ";
    l1.print();
    printf("Your max is %d, should be 78\n", m1);
    cout << "list is ";
    l2.print();
    printf("Your max is %d, should be 42\n", m2);
    SortedList eric;
    eric.insert(-100);
    eric.insert(-101);
    eric.insert(-102);
    m1 = eric.findMax();
    cout << "list is ";
    eric.print();
    printf("Your max is %d, should be -100\n", m1);
#endif
}
			Rect GuiTableComposition::GetBounds()
			{
				Rect cached = previousBounds;
				Rect result = GuiBoundsComposition::GetBounds();

				bool cellMinSizeModified = false;
				SortedList<GuiCellComposition*> cells;
				FOREACH(GuiCellComposition*, cell, cellCompositions)
				{
					if (cell && !cells.Contains(cell))
					{
						cells.Add(cell);
						Size newSize = cell->GetPreferredBounds().GetSize();
						if (cell->lastPreferredSize != newSize)
						{
							cell->lastPreferredSize = newSize;
							cellMinSizeModified = true;
						}
					}
				}

				if (cached != result || cellMinSizeModified)
				{
					UpdateCellBounds();
				}
				return result;
			}
QuadTree::QuadTree( SortedList& source )
{
	//Create the first node in the tree
	nodeData next;
	source.ResetList();
	source.GetNextItem( next );
	treeData = new treeNode;
	treeData -> tagged = false;
	treeData -> NW = NULL;
	treeData -> SW = NULL;
	treeData -> SE = NULL;
	treeData -> NE = NULL;
	currentPos = treeData;
	(currentPos->point).x = (next.centroid).x;
	(currentPos->point).y = (next.centroid).y;
	length = 1;
	
	//Iterate through the sorted list and insert items into tree
	while ( !source.IsLastItem() )
	{
		source.GetNextItem( next );
		insert( treeData, next.centroid );
	}
	
}
Beispiel #4
0
			static void CollectTypeDescriptors(ITypeDescriptor* td, SortedList<ITypeDescriptor*>& tds)
			{
				if (!tds.Contains(td))
				{
					tds.Add(td);
				}
			}
Beispiel #5
0
void checkfreq(SortedList& l, int num, int correct)
{
    printf("Running checkfreq\n");
    int	f = l.freq(num);;
    cout << "list is ";
    l.print();
    printf("Your freq(%d) rets %d, should be %d\n", num, f, correct);
#endif
}
void SortedList<T, Pred>::copyNodes(const SortedList<T, Pred>& rhs)
{
	SortedList<T, Pred>::const_iterator iter = rhs.begin();

	while (iter != rhs.end())
	{
		push_back(*iter);
		++iter;
	}
}
Beispiel #7
0
void checkwhereis(SortedList& l, int num, string correct)
{
    SortedList result;

    result = l.whereis(num);
    cout << "whereis "<< num << " in " ;
    l.print();
    confirm("your result", result, correct);
#endif
}
void RosettaCodeProvider::buildHuffTree()
{
    //build Node list from HuffCodeTable, no need to sort (already done on get call)
    SortedList<HuffNode*> nodeList;
    int i = 0;
    HuffData* iterate = _huffCodeTable->get(i);
    while(iterate != nullptr){
        ++i;
        nodeList.addWithoutSort(new HuffNode(iterate));
        iterate = _huffCodeTable->get(i);
    }
    //merge nodes together
    while(nodeList.size() >= 2){
        HuffNode* one = nodeList.remove(0);
        HuffNode* two = nodeList.remove(0);
        unsigned sum = one->getFrequency() + two->getFrequency();
        HuffNode* three = new HuffNode(sum);
        if(*one < *two){
            three->_leftChild = one;
            three->_rightChild = two;
        }else{
            three->_leftChild = two;
            three->_rightChild = one;
        }
        nodeList.addWithSort(three);
    }
    if(nodeList.size() == 0){
        //something went wrong
        //nothing in codeTable to start with?
        return;
    }
    if(nodeList.size() == 1){
        _huffTree = new HuffTree(nodeList.remove(0));
    }
}
void SearchLeafClasses(List<ParsingSymbol*>& classes, List<ParsingSymbol*>& leafClasses)
{
	SortedList<ParsingSymbol*> parents;
	CopyFrom(
		parents,
		From(classes)
			.Select([](ParsingSymbol* type){ return type->GetDescriptorSymbol(); })
			.Distinct()
		);
	CopyFrom(
		leafClasses,
		From(classes)
			.Where([&parents](ParsingSymbol* type){ return !parents.Contains(type); })
		);
}
Beispiel #10
0
//
// Show user what the list contains then show what it ought to contain
// Let the user decide if it is correct
//
void confirm(string name, SortedList& l, string correct)
{
    cout << name << " is now:" << endl;
    l.print();
    cout << "It should be" << endl;
    cout << correct << endl << endl;
}
Beispiel #11
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;
}
LLDependenciesBase::VertexList LLDependenciesBase::topo_sort(int vertices, const EdgeList& edges) const
{
    // Construct a Boost Graph Library graph according to the constraints
    // we've collected. It seems as though we ought to be able to capture
    // the uniqueness of vertex keys using a setS of vertices with a
    // string property -- but I don't yet understand adjacency_list well
    // enough to get there. All the examples I've seen so far use integers
    // for vertices.
    // Define the Graph type. Use a vector for vertices so we can use the
    // default topological_sort vertex lookup by int index. Use a set for
    // edges because the same dependency may be stated twice: Node "a" may
    // specify that it must precede "b", while "b" may also state that it
    // must follow "a".
    typedef boost::adjacency_list<boost::setS, boost::vecS, boost::directedS,
                                  boost::no_property> Graph;
    // Instantiate the graph. Without vertex properties, we need say no
    // more about vertices than the total number.
    Graph g(edges.begin(), edges.end(), vertices);
    // topo sort
    typedef boost::graph_traits<Graph>::vertex_descriptor VertexDesc;
    typedef std::vector<VertexDesc> SortedList;
    SortedList sorted;
    // note that it throws not_a_dag if it finds a cycle
    try
    {
        boost::topological_sort(g, std::back_inserter(sorted));
    }
    catch (const boost::not_a_dag& e)
    {
        // translate to the exception we define
        std::ostringstream out;
        out << "LLDependencies cycle: " << e.what() << '\n';
        // Omit independent nodes: display only those that might contribute to
        // the cycle.
        describe(out, false);
        throw Cycle(out.str());
    }
    // A peculiarity of boost::topological_sort() is that it emits results in
    // REVERSE topological order: to get the result you want, you must
    // traverse the SortedList using reverse iterators.
    return VertexList(sorted.rbegin(), sorted.rend());
}
Beispiel #13
0
void readFile(SortedList &l, const char filename[])
{
    int temp;
    ifstream fin;

    fin.open(filename);
    while ( fin >> temp ) {
        l.insert(temp);
    }
    fin.close();
}
Beispiel #14
0
	ParserDecl(Ptr<ParsingTreeObject> parserDecl)
	{
		nodeTypeMap.Add(parserDecl.Obj(), this);
		CollectTypes(parserDecl->GetMember(L"types").Cast<ParsingTreeArray>(), nodeTypeMap);
		{
			Ptr<ParsingTreeArray> items=parserDecl->GetMember(L"tokens").Cast<ParsingTreeArray>();
			if(items)
			{
				for(int i=0;i<items->Count();i++)
				{
					Ptr<ParsingTreeObject> type=items->GetItem(i).Cast<ParsingTreeObject>();
					if(type)
					{
						Ptr<ParsingTreeToken> name=type->GetMember(L"name").Cast<ParsingTreeToken>();
						if(name)
						{
							tokens.Add(name->GetValue());
						}
					}
				}
			}
		}
		{
			Ptr<ParsingTreeArray> items=parserDecl->GetMember(L"rules").Cast<ParsingTreeArray>();
			if(items)
			{
				for(int i=0;i<items->Count();i++)
				{
					Ptr<ParsingTreeObject> type=items->GetItem(i).Cast<ParsingTreeObject>();
					if(type)
					{
						Ptr<ParsingTreeToken> name=type->GetMember(L"name").Cast<ParsingTreeToken>();
						if(name)
						{
							rules.Add(name->GetValue());
						}
					}
				}
			}
		}
	}
int main()
{
    SortedList* sl = new SortedList();

    sl->insert(1);
    sl->insert(50);

    sl->displayList();

    sl->insert(3);
    sl->insert(20);
    sl->insert(7);

    sl->displayList();
    
    while(sl->removeFirst())
	sl->displayList();
    
    delete sl;
    
    return 0;
} // end main()
int main()
{
    int j;
    time_t aTime; // seed random numbers
    srand(static_cast<unsigned>(time(&aTime)));
    const int size = 10;

    Link* linkArray[size]; // array of ptrs to links

    for(j = 0; j < size; j++) // fill with ptrs to links
    {
	int n = rand() % 99; // random number (0 to 99)
	Link* pNewLink = new Link(n);
	linkArray[j] = pNewLink;
    }

    cout << "Unsorted array: ";
    for(j = 0; j < size; j++)
	linkArray[j]->displayLink();
    cout << endl;

    SortedList *sl = new SortedList(linkArray, size);

    for(j = 0; j < size; j++)
	linkArray[j] = sl->removeFirst();

    cout << "Sorted Array: ";
    for(j = 0; j < size; j++)
	linkArray[j]->displayLink();
    cout << endl;

    for(j = 0; j < size; j++) // delete indivisual links
	delete linkArray[j];
    
    return 0;
} // end main()
Beispiel #17
0
	ParserDecl(Ptr<ParsingTreeObject> parserDecl)
	{
		nodeTypeMap.Add(parserDecl.Obj(), this);
		Ptr<ParsingTreeArray> defs=parserDecl->GetMember(L"definitions").Cast<ParsingTreeArray>();
		if(defs)
		{
			vint count=defs->Count();
			for(vint i=0;i<count;i++)
			{
				Ptr<ParsingTreeObject> defObject=defs->GetItem(i).Cast<ParsingTreeObject>();
				if(defObject)
				{
					if(defObject->GetType()==L"TokenDef")
					{
						Ptr<ParsingTreeToken> name=defObject->GetMember(L"name").Cast<ParsingTreeToken>();
						if(name)
						{
							tokens.Add(name->GetValue());
						}
					}
					else if(defObject->GetType()==L"RuleDef")
					{
						Ptr<ParsingTreeToken> name=defObject->GetMember(L"name").Cast<ParsingTreeToken>();
						if(name)
						{
							rules.Add(name->GetValue());
						}
					}
					else
					{
						CollectSubType(defObject, nodeTypeMap);
					}
				}
			}
		}
	}
Beispiel #18
0
bool batch_test(int test)
{
  size_t size = 1402;
  size_t capacity = 45500;
  string * buf = new string[size];
  ifstream in("sorted_short.txt");
  for(size_t i = 0; i != size; ++i) in >> buf[i];
  in.close();

  // array insert
  if(test == 46)
  {
    SortedList * list = new SortedArrayList;
    list->batch(&SortedList::insert, string("random_short.txt"));
    SortedArrayList * p = static_cast<SortedArrayList *>(list);
    for(size_t i = 0; i != size; ++i) if((*p)[i] != buf[i]) return false;
  }
  // array remove
  else if(test == 47)
  {
    SortedList * list = new SortedArrayList;
    list->batch(&SortedList::remove, string("random_short.txt"));
    SortedArrayList * p = static_cast<SortedArrayList *>(list);
    if(p->size_cassej() != 0) return false;
  }
  // linked-list insert
  else if(test == 48)
  {
    SortedList * list = new SortedLinkedList;
    list->batch(&SortedList::insert, string("random_short.txt"));
    SortedLinkedList * p = static_cast<SortedLinkedList *>(list);
    for(size_t i = 0; i != size; ++i) if((*p)[i] != buf[i]) return false;
  }
  // linked-list remove
  else if(test == 49)
  {
    SortedList * list = new SortedLinkedList;
    list->batch(&SortedList::remove, string("random_short.txt"));
    SortedLinkedList * p = static_cast<SortedLinkedList *>(list);
    if(p->size_cassej() != 0) return false;
  }
  else exit(1);
  return true;
}
Beispiel #19
0
SortedList<T>* SortedList<T>::merge(SortedList<T> *t1, SortedList<T> *t2)
{
    int siz1 = t1->size();
    int siz2 = t2->size();
    int totalSize = siz1 + siz2;
    int cnt1=0, cnt2=0;

    SortedList<T>* merged = new SortedList<T>();
    for(int i = 0; i < totalSize; i++){
         if(cnt1 == siz1){
            merged->addWithoutSort(t2->get(cnt2));
            ++cnt2;
        }else if(cnt2 == siz2){
            merged->addWithoutSort(t1->get(cnt1));
            ++cnt1;
        }else{
            if(std::is_pointer<T>::value){ //dealing with pointer to object
                //pointer to pointer to object will not work unfortunately
                T item1 = t1->get(cnt1);
                T item2 = t2->get(cnt2);
                if(*(item1) < *(item2)){
                    merged->addWithoutSort(t1->get(cnt1));
                    ++cnt1;
                }else{
                    merged->addWithoutSort(t2->get(cnt2));
                    ++cnt2;
                }
            }else{
                if(t1->get(cnt1) < t2->get(cnt2)){
                    merged->addWithoutSort(t1->get(cnt1));
                    ++cnt1;
                }else{
                    merged->addWithoutSort(t2->get(cnt2));
                    ++cnt2;
                }
            }
        }
    }
    return merged;
}
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();
    }

}
Beispiel #21
0
	int main()
	{
    		SortedList<int> list;
    		int mainItem;

    		list.Insert(352);
    		list.Insert(48);
    		list.Insert(12);
    		list.Insert(40);
    		list.Print();

    		if (!list.IsEmpty())
    			{
    			list.DeleteTop(mainItem);  // delete the first node
    			cout << "node delete was " << mainItem << endl << endl;
    			}

    		cout << "\nprint out list after delete" << endl;
    		list.Print();

    		list.Insert(1);  // insert at the top of the list
    		list.Insert(500); //insert at the bottom of the list
    		list.Insert(77); // insert in the middle
    		cout << "\nprint the list after inserting nodes"<< endl;
    		list.Print();

    		list.Delete(48);  // delete in the middle
    		cout << "\nprint the list deleting a middle node"<< endl;
    		list.Print();

    		list.Delete(1);  // delete the first node
    		cout << "\nprint the list deleting the first node" << endl;
    		list.Print();

    		list.Delete(500);  // delete the last node
    		cout << "\nprint the list deleting the last node" << endl;
			list.Print();

			while(!list.IsEmpty())
			{
				list.DeleteTop(mainItem);
			}

			cout << "List is empty: " << (list.IsEmpty()? "true\n": "false\n");

			list.DeleteTop(mainItem);

			list.Delete(2);
	}
Beispiel #22
0
int main( int argc, char** argv ) {
	cout << "\n Double link list\n";
	DoubleLink<int> dblVec;
	dblVec.push( 3 );
	dblVec.push( 1 );
	dblVec.push( 10 );
	dblVec.push( 15 );
	dblVec.push( 8 );
	dblVec.display();
	dblVec.pop();
	dblVec.display();
	
	
	cout << "\n Stack list\n";
	Stack<int> stack;
	stack.push( 3 );
	stack.push( 1 );
	stack.push( 10 );
	stack.push( 15 );
	stack.push( 8 );
	stack.display();
	stack.pop();
	stack.display();
//	cout << stack.find( 10 ) << endl;
	
	cout << "\n Queue list\n";
	Queue<int> queue;
	queue.push( 3 );
	queue.push( 1 );
	queue.push( 10 );
	queue.push( 15 );
	queue.push( 8 );
	queue.display();
	queue.pop();
	queue.display();
//	cout << queue.find( 10 ) << endl;
	
	
	cout << "\n Circle list\n";
	CircleLink<int> circle;
	circle.push( 3 );
	circle.push( 1 );
	circle.push( 10 );
	circle.push( 15 );
	circle.push( 8 );
	circle.display();
	circle.pop();
	circle.display();
//	cout << circle.find( 10 ) << endl;
	
	
	cout << "\n Sorted list\n";
	SortedList<int> sort;
	sort.push( 3 );
	sort.push( 1 );
	sort.push( 10 );
	sort.push( 15 );
	sort.push( 8 );
	sort.display();
	sort.pop();
	sort.display();
//	cout << sort.find( 10 ) << endl;
	
	cout << "\nPriority list\n";
	PriorityList<int> plist;
	plist.push( 3 );
	plist.push( 1 );
	plist.push( 10 );
	plist.push( 15 );
	plist.push( 8 );
	plist.display();
	plist.pop();
	plist.display();
	cout << plist.find( 10 ) << endl;
	plist.display();
	
}
static void generateJSNavTree(QList<FTVNode *> &nodeList)
{
   QString htmlOutput = Config::getString("html-output");

   // new JS  
   QFile f(htmlOutput + "/navtreedata.js");
   SortedList<NavIndexEntry *> navIndex;

   if (f.open(QIODevice::WriteOnly)) {
   
      QTextStream t(&f);
      t << "var NAVTREE =" << endl;
      t << "[" << endl;
      t << "  [ ";

      QString projName = Config::getString("project-name");

      if (projName.isEmpty()) {
         if (Doxy_Globals::mainPage && ! Doxy_Globals::mainPage->title().isEmpty()) { 
            // use title of main page as root
            t << "\"" << convertToJSString(Doxy_Globals::mainPage->title()) << "\", ";

         } else { 
            // use default section title as root
            LayoutNavEntry *lne = LayoutDocManager::instance().rootNavEntry()->find(LayoutNavEntry::MainPage);
            t << "\"" << convertToJSString(lne->title()) << "\", ";
         }

      } else { 
         // use PROJECT_NAME as root tree element
         t << "\"" << convertToJSString(projName) << "\", ";
      }

      t << "\"index" << Doxy_Globals::htmlFileExtension << "\", ";

      // add special entry for index page
      navIndex.inSort(new NavIndexEntry("index" + Doxy_Globals::htmlFileExtension, ""));

      // related page index, written as a child of index.html
      navIndex.inSort(new NavIndexEntry("pages" + Doxy_Globals::htmlFileExtension, ""));

      // adjust for display output     
      reSortNodes(nodeList);

      bool omitComma = true;
      generateJSTree(navIndex, t, nodeList, 1, omitComma);

      if (omitComma) {
         t << "]" << endl;
      } else {
         t << endl << "  ] ]" << endl;
      }

      t << "];" << endl << endl;
 
      int subIndex  = 0;
      int elemCount = 0;
      const int maxElemCount = 250;

      // new JS     
      QFile fsidx(htmlOutput + "/navtreeindex0.js");

      if (fsidx.open(QIODevice::WriteOnly)) {
         
         QTextStream tsidx(&fsidx);

         t << "var NAVTREEINDEX =" << endl;
         t << "[" << endl;

         tsidx << "var NAVTREEINDEX" << subIndex << " =" << endl;
         tsidx << "{" << endl;

         omitComma = true;     

         auto nextItem  = navIndex.begin();

         for (auto e : navIndex)  {
            // for each entry
            ++nextItem;

            if (elemCount == 0) {
               if (! omitComma) {
                  t << "," << endl;

               } else {
                  omitComma = false;
               }

               t << "\"" << e->m_url << "\"";
            }

            tsidx << "\"" << e->m_url << "\":[" << e->m_indexId << "]";
            
            if (nextItem != navIndex.end() && elemCount < maxElemCount - 1) {
               // not the last entry
               tsidx << ",";   
            }

            tsidx << endl;

            elemCount++;

            if (nextItem != navIndex.end() && elemCount >= maxElemCount) {           
               // switch to new sub-index
               tsidx << "};" << endl;

               elemCount = 0;
               fsidx.close();

               subIndex++;

               fsidx.setFileName(htmlOutput + "/navtreeindex" + QString::number(subIndex) + ".js");

               if (! fsidx.open(QIODevice::WriteOnly)) {
                  break;
               }

               tsidx.setDevice(&fsidx);
               tsidx << "var NAVTREEINDEX" << subIndex << " =" << endl;
               tsidx << "{" << endl;
            }
         }

         tsidx << "};" << endl;
         t << endl << "];" << endl;
      }

      t << endl << "var SYNCONMSG = '"  << theTranslator->trPanelSyncTooltip(false) << "';";
      t << endl << "var SYNCOFFMSG = '" << theTranslator->trPanelSyncTooltip(true)  << "';";
   }

   ResourceMgr::instance().copyResourceAs("html/navtree.js", htmlOutput, "navtree.js");
}
static bool generateJSTree(SortedList<NavIndexEntry *> &navIndex, QTextStream &t, const QList<FTVNode *> &nl, int level, bool &omitComma)
{
   static QString htmlOutput   = Config::getString("html-output");   
   static QString mainPageName = Config::getFullName(Config::getString("main-page-name")); 
   static bool mainPageOmit    = Config::getBool("main-page-omit"); 

   QString indentStr;
   indentStr.fill(' ', level * 2);

   bool found = false;

   for (auto node : nl)  {
      // terminate previous entry

      if (! omitComma) {
         t << "," << endl;
      }
      omitComma = false;

      // start entry
      if (! found) {
         t << "[" << endl;
      }
      found = true;

      if (node->addToNavIndex) { 
         // add entry to the navigation index

         if (node->def && node->def->definitionType() == Definition::TypeFile) {            
            QSharedPointer<FileDef> fd = node->def.dynamicCast<FileDef>();
  
            if (! mainPageName.isEmpty() && fd->getFilePath() == mainPageName) {       
               // do not add this file to the navIndex, for \files

            } else {  
                                   
               if (docFileVisibleInIndex(fd)) {
                  navIndex.inSort(new NavIndexEntry(node2URL(node, true, false), pathToNode(node)));
               }
   
               if (srcFileVisibleInIndex(fd)) {
                  navIndex.inSort(new NavIndexEntry(node2URL(node, true, true), pathToNode(node)));
               }
            }

         } else { 
                
            if (mainPageOmit && node->def == Doxy_Globals::mainPage) { 
               // do not add this file to the navIndex 
             
            } else {
               navIndex.inSort(new NavIndexEntry(node2URL(node), pathToNode(node)));
            }
         }
      }

      if (node->separateIndex) { 
         // store some items in a separate file (annotated, modules, namespaces, files)
         bool firstChild   = true;
         bool showMainPage = true;

         if (node->def && node->def->definitionType() == Definition::TypeFile) {            
            QSharedPointer<FileDef> fd = node->def.dynamicCast<FileDef>();

            if (! mainPageName.isEmpty() && fd->getFilePath() == mainPageName) {   
               // do not add this file to the navIndex, for \files

               showMainPage = false;
               omitComma    = true;
            }

         } else { 
                
            if (mainPageOmit && node->def == Doxy_Globals::mainPage) { 
               // do not add this file to the navIndex 

               showMainPage = false;
               omitComma    = true;
            }
         }

         if (showMainPage) {         
            t << indentStr << "  [ ";
            generateJSLink(t, node);
   
            if (node->children.count() > 0) { 
               // write children to separate file for dynamic loading
               QString fileId = node->file;
   
               if (! node->anchor.isEmpty()) {
                  fileId += "_" + node->anchor;
               }
   
               if (dupOfParent(node)) {
                  fileId += "_dup";
               }
   
               QFile fi(htmlOutput + "/" + fileId + ".js");
   
               if (fi.open(QIODevice::WriteOnly)) {
                  QTextStream tt(&fi);
   
                  tt << "var " << convertFileId2Var(fileId) << " =" << endl;
                  generateJSTree(navIndex, tt, node->children, 1, firstChild);
                  tt << endl << "];";
               }
   
               t << "\"" << fileId << "\" ]";            

            } else { 
               // no children
               t << "null ]";
            }
         }

      } else {
         bool firstChild = true;

         if (mainPageOmit && node->def == Doxy_Globals::mainPage) { 
            // omit treeview entries for index page
            omitComma = true;

         } else  {
            t << indentStr << "  [ ";
            generateJSLink(t, node);
   
            bool emptySection = ! generateJSTree(navIndex, t, node->children, level + 1, firstChild);
   
            if (emptySection) {
               t << "null ]";
            } else {
               t << endl << indentStr << "  ] ]";
            }
         }
      }
   }

   return found;
}
Beispiel #25
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 #26
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);


}
Beispiel #27
0
int main()
{
	
	#define HELP "Usage: $ palindrome [parameter]\nWhere: parameter is one of:\n\t\t-h (help)\n\t\t-k (read from keyboard)\n\t\t-f file (read from file)\n\t\t-d letter (remove all palindromes which start by this letter)\n\t\t-s (show data)\n\t\t-q (exit)\n";
	
	string input ("\0");
	string original ("\0");
	string command;

	SortedList list;

	//always print the help at the begin
	cout << HELP;	

	do
	{
		//print a new prompt until -q
		cout << "$ palindrome ";

		//read command
		getline(cin, command, '\n');

		//create our own argv
		vector<string> myArgv;
		istringstream iss(command);
		string token;
		while(getline(iss, token, ' '))
		{
			myArgv.push_back(token);
		} 

		//create our own argc
		int myArgc = myArgv.size();

		//main method
		if (myArgc == 1)
		{
			if (myArgv[0] == "-h")
			{
				cout << HELP;
			}
			else if (myArgv[0] == "-s")
			{
				//show in the screen the number of queues in the list, the total number of palindromes in each queue and their starting letter
				cout << list.toString() << endl;
			}
			else if (myArgv[0] == "-k")
			{
				int i = 0;

				cout << "(-q to exit)" << endl;

				do
				{
					cout << "(" << i << ") "; i++;
					getline(cin, original, '\n');
					input = rmSpace(original);

					if (isPalindrome(input))
					{
						//insert original in the list
						list.insert(original);
						cout << "Palindrome inserted!" << endl;
					}
					else
						if (original!="-q")
							cout << "This is not palindrome, then not inserted!" << endl;
				} 
				while(original!="-q");
			}
			else
			{
				if (myArgv[0] != "-q")
				{
					cout << "Paremeter unknown " << myArgv[0] << endl;
				}
			}
		}
		else if (myArgc == 2)
		{
			if (myArgv[0] == "-f")
			{
				int cont0 = 0, cont1 = 0;

				ifstream inputFile (myArgv[1]);
				if(inputFile.is_open())
				{
					string tmp;
					while(getline(inputFile, tmp))
					{
						input = rmSpace(tmp);
						if (isPalindrome(input))
						{
							//insert tmp in the list
							list.insert(tmp);
							cont1++;
						}
						else
							cont0++;
					}
					cout << cont1 << " palindromes inserted." << endl;
					cout << cont0 << " sentences that are not palindrome, not inserted." << endl;
				}	
				else
				{
					//filename does not exists
					cout << "The file couldn't be opened, maybe doesn't exists :(\n";
				}
			}
			else if (myArgv[0] == "-d")
			{
				//delete the node of the leter passed in parameter
				if (myArgv[1].length() == 1)
					if(list.remove(myArgv[1].front()))
						cout << "Removed!" << endl;
					else
						cout<< "Node does not exists!" << endl;
				else
					cout << "just one char pleaaaaaase :)" << endl;
			}
			else
			{
				cout << "Paremeter unknown " << myArgv[0] << endl;
			}
		}
		else if (myArgc > 2)
		{
			cout << "There's way too much arguments :')\n";
		}
	}
	while(command != "-q");
}