Exemple #1
0
void TestList() {
    List<int> a;
    a.Add(3);
    a.Add(5);
    assert(a.Count() == 2);
    assert(a.Contains(3));
    assert(a.Contains(5));
    assert(a[0] == 3);

    List<int> b(a);
    b.Add(a);
    assert(b.Count() == 4);
    a.Remove(3);
    assert(a.Count() == 1);
    assert(a.Contains(3) == false);
    assert(a[0] = 5);
    
    a.Insert(4, 0);
    a.Insert(6, 1);
    a.Insert(7, a.Count() - 1);
    assert(a[0] == 4);
    assert(a[1] == 6);
    assert(a[2] == 7);

    a.Remove(6);
    assert(a[2] == 5);
}
Exemple #2
0
void Vertex::RemoveIfNonNeighbor(Vertex *n) {
        // removes n from neighbor list if n isn't a neighbor.
        if(!neighbor.Contains(n)) return;
        for(int i=0;i<face.num;i++) {
                if(face[i]->HasVertex(n)) return;
        }
        neighbor.Remove(n);
}
Exemple #3
0
void GameObject::OnHierarchyGameObjectsSelected(
        List<GameObject*> &selectedEntities )
{
    if (IsEditorGameObject() || IsScene()) return;

    bool selected = selectedEntities.Contains(this);
    bool wasSelected = IsSelected();
    m_isSelectedInHierarchy = selected;
    if (!wasSelected && selected)
    {
        m_selectionGameObject = new EditorSelectionGameObject(this);
        m_selectionGameObject->SetParent(SceneManager::GetActiveScene());
    }
    else if (wasSelected && !selected && m_selectionGameObject)
    {
        delete m_selectionGameObject;
        m_selectionGameObject = nullptr;
    }
}
Exemple #4
0
int main() {
   // Demo the use of our LinkedList class.
   LinkedList<int> l; // TData is int....
   l.AddFirst(1);     // ... so all the Add methods take ints.
   l.AddFirst(2);
   l.AddFirst(3);
   l.AddLast(4);
   l.AddLast(5);


   // Use the .Get method to access individual elements.
   // How efficient is this loop? Not as efficient.
	// The loop takes too long to walk through all elements of linked lists
	//	if the size of linked list is large.
   for (int i = 0; i < l.Size(); i++) {
      cout << l.Get(i) << endl;
   }


   cout << "Remove: " << endl;
   // The .RemoveFirst/Last/At methods return the data removed.
   while (l.Size() > 0) {
      cout << l.RemoveFirst() << endl;
   }

   cout << endl;

   // It is easy to get the "border" cases wrong in a linked structure. Let's
   // test to see what happens when adding to a list that had just been emptied.
   l.AddFirst(1);
   l.AddFirst(2);
   l.AddFirst(3);
   l.AddLast(4);
   l.AddLast(5);

   cout << "After adding back to the emptied list:" << endl;
   for (int i = 0; i < l.Size(); i++) {
      cout << l.Get(i) << endl;
   }
   // Does that look correct?
   cout << endl;

   cout << "Contains 14? " << endl;
   // Demo the Contains method. Will this be true or false?
   cout << l.Contains(14) << endl;
   cout << endl;

   // So far we have used the LinkedList directly, so the List base class 
   // doesn't seem necessary. Through polymorphism, we can declare a List
   // pointer to a LinkedList object.
   List<int> *p = new LinkedList<int>();
   // We can now only call List<int> methods on p... which, fortunately, is all
   // of our important functions.
   p->AddLast(4);
   p->AddLast(8);
   p->AddLast(15);
   p->AddLast(16);
   p->AddLast(23);
   p->AddLast(42);
   cout << "Pointer to a List contains 16? " << p->Contains(16) << endl;


   // So far we don't have much of a reason to do this type of polymorphism.
   // But we will...
 


   // Lecture part 2: iterators!
   // Picture the normal iterator loop:
   // for (_____::iterator itr = _____.begin(); itr != _____.end(); itr++) {
   //    do something with *itr or itr->

   /*
   If we want our LinkedList to follow this trend, what do we need to 
   implement?

   1. An inner class named iterator, so our full scoped name will be 
      LinkedList<TData>::iterator
   2. Operators ++, ==, !=, *, and -> in the iterator class.
   3. Member methods .begin() and .end() in LinkedList.
   
   When those are implemented, we can then...
   */
   cout << endl << "ITERATORS!!!" << endl;
   for (LinkedList<int>::iterator itr = l.begin(); itr != l.end(); itr++) {
      cout << *itr << endl;
   }
}
Exemple #5
0
void main()
{
	List L;
	L.AddHead(1);

	L.AddTail(2);

	L.AddHead(3);

	L.AddTail(4);

	L.AddHead(5);

	L.Print();

	L.Insert();

	L.Print();

	L.Print(2);

	L.Print(8);

	List T;

	T = L;

	T.Print();

	List Sum = -L + T;

	Sum.Print();

	int a[10] = { 8, 6, 7, 4 };
	Sum.AddTailRange(a, 10);
	Sum.Print();
	cout << boolalpha << Sum.Contains(70) << endl;
	cout << Sum << endl;
	Sum[2].data = 500;
	cout << Sum << endl;
	cout << Sum.GetElementAt(5)->data << endl;
	List Sum2 = Sum;
	cout << boolalpha << Sum2.Equals(Sum) << endl;
	Sum[1].data = 500;
	cout << boolalpha << Sum2.Equals(Sum) << endl;
	cout << "Index of 3 is: " << Sum.IndexOf(3) << endl;
	cout << "Last index of 3 is: " << Sum.LastIndexOf(3) << endl;
	Sum.InsertRange(a, 5, 1);
	cout << Sum << endl;
	Sum.Remove(5);
	Sum.RemoveAll(500);
	Sum.RemoveAll(0);
	cout << Sum << endl;
	cout << Sum.GetLength() << endl;
	Sum.Revers();
	cout << Sum << endl;

	int * b = Sum.ToArray();
	for (int i = 0; i < Sum.GetLength(); i++)
		cout << b[i] << "  ";
	cout << endl;
	delete[] b;

	Sum.Sort();
	cout << Sum << endl;
}
		Ptr<workflow::WfFunctionDeclaration> Workflow_GenerateEventHandler(description::IEventInfo* eventInfo)
		{
			auto func = MakePtr<WfFunctionDeclaration>();
			func->anonymity = WfFunctionAnonymity::Anonymous;
			func->returnType = GetTypeFromTypeInfo(TypeInfoRetriver<void>::CreateTypeInfo().Obj());

			vint count = eventInfo->GetHandlerType()->GetElementType()->GetGenericArgumentCount() - 1;
			bool standardName = false;
			if (count == 2)
			{
				auto senderType = eventInfo->GetHandlerType()->GetElementType()->GetGenericArgument(1)->GetTypeDescriptor();
				auto argumentType = eventInfo->GetHandlerType()->GetElementType()->GetGenericArgument(2)->GetTypeDescriptor();
				if (senderType == GetTypeDescriptor<GuiGraphicsComposition>())
				{
					auto expectedType = GetTypeDescriptor<GuiEventArgs>();
					List<ITypeDescriptor*> types;
					types.Add(argumentType);
					for (vint i = 0; i < types.Count(); i++)
					{
						auto type = types[i];
						if (type == expectedType)
						{
							standardName = true;
							break;
						}
						vint baseCount = type->GetBaseTypeDescriptorCount();
						for (vint j = 0; j < baseCount; j++)
						{
							auto baseType = type->GetBaseTypeDescriptor(j);
							if (!types.Contains(baseType))
							{
								types.Add(baseType);
							}
						}
					}
				}
			}

			if (standardName)
			{
				{
					auto arg = MakePtr<WfFunctionArgument>();
					arg->name.value = L"sender";
					arg->type = GetTypeFromTypeInfo(eventInfo->GetHandlerType()->GetElementType()->GetGenericArgument(1));
					func->arguments.Add(arg);
				}
				{
					auto arg = MakePtr<WfFunctionArgument>();
					arg->name.value = L"arguments";
					arg->type = GetTypeFromTypeInfo(eventInfo->GetHandlerType()->GetElementType()->GetGenericArgument(2));
					func->arguments.Add(arg);
				}
			}
			else
			{
				auto type = TypeInfoRetriver<Value>::CreateTypeInfo();
				for (vint i = 0; i < count; i++)
				{
					auto arg = MakePtr<WfFunctionArgument>();
					arg->name.value = L"<argument>" + itow(i + 1);
					arg->type = GetTypeFromTypeInfo(type.Obj());
					func->arguments.Add(arg);
				}
			}

			return func;
		}