PEBL 2.2
Psychology Experiment Building Language - Cross-platform psychological experiment development system
PEBLList Namespace Reference

Functions

Variant Shuffle (Variant v)
 
Variant Repeat (Variant v)
 
Variant RepeatList (Variant v)
 
Variant RepeatExpression (Variant v)
 
Variant Sequence (Variant v)
 
Variant DesignFullCounterbalance (Variant v)
 
Variant CrossFactorWithoutDuplicates (Variant v)
 
Variant Rotate (Variant v)
 
Variant Length (Variant v)
 This returns the number of items in the list.
 
Variant Nth (Variant v)
 
Variant First (Variant v)
 
Variant Second (Variant v)
 
Variant Third (Variant v)
 
Variant Fourth (Variant v)
 
Variant Fifth (Variant v)
 
Variant Last (Variant v)
 
Variant Merge (Variant v)
 
Variant Append (Variant v)
 
Variant List (Variant v)
 This creates a list functionally, rather than syntactically using the [] operators.
 
Variant Sort (Variant v)
 This just sorts the list.
 
Variant SortBy (Variant v)
 This sorts the list by another list.
 
Variant IsMember (Variant v)
 
Variant RemoveDuplicates (Variant v)
 
Variant MakeMap (Variant v)
 
Variant Transpose (Variant v)
 
Variant SubList (Variant v)
 This makes a list out of a sublist of a list. Or something like that.
 
Variant Remove (Variant v)
 
Variant PushOnEnd (Variant v)
 Given Merge([a,b,c],d), will return [a,b,c,d].
 
Variant SetElement (Variant v)
 
Variant ListToString (Variant v)
 
Variant ModList (Variant v)
 

Variables

PEBL_Function_Type FunctionTable []
 

Function Documentation

◆ Append()

Variant PEBLList::Append ( Variant  v)

This adds an element to a list Given Merge([a,b,c],d), will return [a,b,c,d]

Definition at line 669 of file PEBLList.cpp.

670{
671
672 PList * plist = v.GetComplexData()->GetList();
673
674
675 Variant v1 = plist->First(); //plist->PopFront();
676 //v[1] should be a list. Just extract the iterators.
677 PError::AssertType(v1, PEAT_LIST, "Argument error in first parameter of function [Append(<list>, <list>)]: ");
678
679 PList * tmpList = (PList*)(v1.GetComplexData()->GetObject().get());
680 vector<Variant>::iterator p1 = tmpList->Begin();
681 vector<Variant>::iterator p1end = tmpList->End();
682
683 Variant v2 = plist->Nth(2); //plist->PopFront();
684 //v[2] can be anything.
685
686
687 //Make a new list to return.
688 PList * returnList = new PList();
689
690 Variant tmpVariant;
691
692 //Add the first list.
693 while(p1 != p1end)
694 {
695 returnList->PushBack(*p1);
696 p1++;
697 }
698
699 //Append v2.
700 returnList->PushBack(v2);
702 PComplexData * tmpPCD= (new PComplexData(tmpObj));
703 Variant tmp = Variant(tmpPCD);
704 delete tmpPCD;
705 tmpPCD=NULL;
706 return tmp;
707
708}
#define NULL
Definition BinReloc.cpp:317
@ PEAT_LIST
Definition PError.h:61
counted_ptr< PEBLObjectBase > GetObject() const
PList * GetList() const
Definition PList.h:45
std::vector< Variant >::const_iterator End() const
Definition PList.cpp:132
std::vector< Variant >::const_iterator Begin() const
Definition PList.cpp:127
Variant Nth(unsigned int n)
Definition PList.cpp:181
void PushBack(const Variant &v)
Definition PList.cpp:149
Variant First()
Definition PList.cpp:169
PComplexData * GetComplexData() const
Definition Variant.cpp:1299
X * get() const
Definition rc_ptrs.h:110
void AssertType(Variant v, int type, const std::string &outsidemessage)

References PError::AssertType(), PList::Begin(), PList::End(), PList::First(), counted_ptr< X >::get(), Variant::GetComplexData(), PComplexData::GetList(), PComplexData::GetObject(), PList::Nth(), NULL, PEAT_LIST, and PList::PushBack().

◆ CrossFactorWithoutDuplicates()

Variant PEBLList::CrossFactorWithoutDuplicates ( Variant  v)

This function takes a single list, and returns a list of all pairs, excluding the pairs that have two of the same item. CrossFactorWithoutDuplicates([a,b,c]) = [[a,b],[a,c],[b,a],[b,c],[c,a],[c,b]] To achieve the same effect but include the duplicates, use DesignFullCounterBalance(x,x)

Make sublist with the pair in it.

Definition at line 352 of file PEBLList.cpp.

353{
354 PList * plist = v.GetComplexData()->GetList();
355
356 //v[1] should be a list. Just extract the iterators.
357
358 Variant v1 = plist->First();// plist->PopFront();
359 PError::AssertType(v1, PEAT_LIST, "Argument error in function [CrossFactorWithoutDuplicates(<list>)]: ");
360 PList * arglist = (PList*)(v1.GetComplexData()->GetObject().get());
361 vector<Variant>::iterator p1 = arglist->Begin();
362 vector<Variant>::iterator p2;
363 vector<Variant>::iterator pstart = p1;
364 vector<Variant>::iterator pend = arglist->End();
365
366 //There are now 2 list iterators: p1 and p2,
367 //and an iterator to the p2start for resetting.
368 //Make a new list to return.
369
370 PList * returnList = new PList();
371 PList * tmpList;
373 Variant tmpVariant;
374 PComplexData * tmpPCD;
375 int i1=0;
376 int i2=0;
377 while(p1 != pend)
378 {
379 p2 = pstart;
380 i2=0;
381 while (p2 != pend)
382 {
383 if(i1 != i2)
384 {
386 tmpList = new PList();
387 tmpList->PushBack(*p1);
388 tmpList->PushBack(*p2);
389
390
391 tmpObj = counted_ptr<PEBLObjectBase>(tmpList);
392
393 tmpPCD = (new PComplexData(tmpObj));
394 tmpVariant = Variant(tmpPCD);
395 delete tmpPCD;
396 tmpPCD=NULL;
397 //Put the sublist in the outer list
398 returnList->PushBack(tmpVariant);
399 }
400 p2++;
401 i2++;
402 }
403
404 p1++;
405 i1++;
406 }
407
408 tmpObj = counted_ptr<PEBLObjectBase>(returnList);
409 tmpPCD= new PComplexData(tmpObj);
410 Variant tmp = Variant(tmpPCD);
411 delete tmpPCD;
412 tmpPCD=NULL;
413 return tmp;
414
415}

References PError::AssertType(), PList::Begin(), PList::End(), PList::First(), counted_ptr< X >::get(), Variant::GetComplexData(), PComplexData::GetList(), PComplexData::GetObject(), NULL, PEAT_LIST, and PList::PushBack().

◆ DesignFullCounterbalance()

Variant PEBLList::DesignFullCounterbalance ( Variant  v)

This takes two lists as parameters, and returns a nested list of lists that includes the full counterbalancing of a and b. Use cautiously; this gets mxn large

Make sublist with the pair in it.

Definition at line 282 of file PEBLList.cpp.

283{
284 PList * plist = v.GetComplexData()->GetList();
285
286 Variant v1 = plist->First(); //plist->PopFront();
287 //v[1] should be a list. Just extract the iterators.
288 PError::AssertType(v1, PEAT_LIST, "Argument error in first parameter of function [DesignFullCounterbalance(<list>, <list>)]: ");
289
290 PList * arglist1 = (PList*)(v1.GetComplexData()->GetObject().get());
291 vector<Variant>::iterator p1 = arglist1->Begin();
292 vector<Variant>::iterator p1end = arglist1->End();
293
294
295 Variant v2 = plist->Nth(2);// plist->PopFront();
296 //v[1] should be a list. Just extract the iterators.
297 PError::AssertType(v2, PEAT_LIST, "Argument error in second parameter of function [DesignFullCounterbalance(<list>, <list>)]: ");
298
299 PList * arglist2 = (PList*)(v2.GetComplexData()->GetObject().get());
300 vector<Variant>::iterator p2start = arglist2->Begin();
301 vector<Variant>::iterator p2;
302 vector<Variant>::iterator p2end = arglist2->End();
303
304 //There are now 2 list iterators: p1 and p2, and two ends to compare them to,
305 //and an iterator to the p2start for resetting.
306 //Make a new list to return.
307
308 PList * returnList = new PList();
309 PList * tmpList = NULL;
311 Variant tmpVariant;
312 PComplexData * tmpPCD;
313 while(p1 != p1end)
314 {
315 p2 = p2start;
316 while (p2 != p2end)
317 {
319 tmpList = new PList();
320 tmpList->PushBack(*p1);
321 tmpList->PushBack(*p2);
322
323 tmpobj = counted_ptr<PEBLObjectBase>(tmpList);
324
325 tmpPCD = (new PComplexData(tmpobj));
326 tmpVariant = Variant(tmpPCD);
327 delete tmpPCD;
328 tmpPCD=NULL;
329
330 //Put the sublist in the outer list
331 returnList->PushBack(tmpVariant);
332 p2++;
333 }
334
335 p1++;
336 }
337
338 tmpobj = counted_ptr<PEBLObjectBase>(returnList);
339 tmpPCD= (new PComplexData(tmpobj));
340 Variant tmp = Variant(tmpPCD);
341 delete tmpPCD;
342 tmpPCD=NULL;
343 return tmp;
344
345}

References PError::AssertType(), PList::Begin(), PList::End(), PList::First(), counted_ptr< X >::get(), Variant::GetComplexData(), PComplexData::GetList(), PComplexData::GetObject(), PList::Nth(), NULL, PEAT_LIST, and PList::PushBack().

◆ Fifth()

Variant PEBLList::Fifth ( Variant  v)

Definition at line 561 of file PEBLList.cpp.

562{
563 //v[1] should be a list
564
565 PList * plist = v.GetComplexData()->GetList();
566
567 Variant v1 = plist->First(); //plist->PopFront();
568 PError::AssertType(v1, PEAT_LIST, "Argument error in function [Fifth(<list>)]: ");
569
570 PList * myList = (PList*)(v1.GetComplexData()->GetObject().get());
571 return myList->Nth(5);
572}

References PError::AssertType(), PList::First(), counted_ptr< X >::get(), Variant::GetComplexData(), PComplexData::GetList(), PComplexData::GetObject(), PList::Nth(), and PEAT_LIST.

◆ First()

Variant PEBLList::First ( Variant  v)

This function returns the first variant in the PList passed in as an argument.

Definition at line 508 of file PEBLList.cpp.

509{
510 //v[1] should be a list
511
512 PList * plist = v.GetComplexData()->GetList();
513
514 Variant v1 = plist->First(); //plist->PopFront();
515 PError::AssertType(v1, PEAT_LIST, "Argument error in function [First(<list>)]: ");
516
517 PList * myList = (PList*)(v1.GetComplexData()->GetObject().get());
518
519 return Variant(myList->First());
520}

References PError::AssertType(), PList::First(), counted_ptr< X >::get(), Variant::GetComplexData(), PComplexData::GetList(), PComplexData::GetObject(), and PEAT_LIST.

◆ Fourth()

Variant PEBLList::Fourth ( Variant  v)

Definition at line 548 of file PEBLList.cpp.

549{
550 //v[1] should be a list
551
552 PList * plist = v.GetComplexData()->GetList();
553
554 Variant v1 = plist->First(); //plist->PopFront();
555 PError::AssertType(v1, PEAT_LIST, "Argument error in function [Fourth(<list>)]: ");
556
557 PList * myList = (PList*)(v1.GetComplexData()->GetObject().get());
558 return myList->Nth(4);
559}

References PError::AssertType(), PList::First(), counted_ptr< X >::get(), Variant::GetComplexData(), PComplexData::GetList(), PComplexData::GetObject(), PList::Nth(), and PEAT_LIST.

◆ IsMember()

Variant PEBLList::IsMember ( Variant  v)

Definition at line 807 of file PEBLList.cpp.

808{
809 PList * plist = v.GetComplexData()->GetList();
810
811 //v[1] should be an item to check for membership.
812 Variant v1 = plist->First();// plist->PopFront();
813
814
815 Variant v2 = plist->Nth(2); // plist->PopFront();
816 PError::AssertType(v2, PEAT_LIST, "Argument error in second parameter of function [IsMember(<list>, <item>)]: ");
817
818 PList * tmpList = (PList*)(v2.GetComplexData()->GetObject().get());
819 vector<Variant>::iterator p = tmpList->Begin();
820 vector<Variant>::iterator pEnd = tmpList->End();
821
822 while(p != pEnd)
823 {
824 if(*p == v1)
825 return Variant(true);
826 p++;
827 }
828 return Variant(false);
829}

References PError::AssertType(), PList::Begin(), PList::End(), PList::First(), counted_ptr< X >::get(), Variant::GetComplexData(), PComplexData::GetList(), PComplexData::GetObject(), PList::Nth(), and PEAT_LIST.

◆ Last()

Variant PEBLList::Last ( Variant  v)

Definition at line 593 of file PEBLList.cpp.

594{
595 //v[1] should be a list
596 PList * plist = v.GetComplexData()->GetList();
597
598 Variant v1 = plist->First();// plist->PopFront();
599 PError::AssertType(v1, PEAT_LIST, "Argument error in function [Last(<list>)]: ");
600
601 PList * myList = (PList*)(v1.GetComplexData()->GetObject().get());
602
603 return Variant(myList->Last());
604}
Variant Last()
Definition PList.cpp:235

References PError::AssertType(), PList::First(), counted_ptr< X >::get(), Variant::GetComplexData(), PComplexData::GetList(), PComplexData::GetObject(), PList::Last(), and PEAT_LIST.

◆ Length()

Variant PEBLList::Length ( Variant  v)

This returns the number of items in the list.

Definition at line 492 of file PEBLList.cpp.

493{
494
495 PList * plist = v.GetComplexData()->GetList();
496
497 //v[1] should be a list
498 Variant v1 = plist->First();// plist->PopFront();
499 PError::AssertType(v1, PEAT_LIST, "Argument error in function [Length(<list>)]: ");
500
501 PList * myList = (PList*)(v1.GetComplexData()->GetObject().get());
502 return Variant((long unsigned int)(myList->Length()));
503}
unsigned long Length() const
Definition PList.h:89

References PError::AssertType(), PList::First(), counted_ptr< X >::get(), Variant::GetComplexData(), PComplexData::GetList(), PComplexData::GetObject(), PList::Length(), and PEAT_LIST.

◆ List()

Variant PEBLList::List ( Variant  v)

This creates a list functionally, rather than syntactically using the [] operators.

Definition at line 121 of file PEBLList.cpp.

122{
123 return v;
124}

◆ ListToString()

Variant PEBLList::ListToString ( Variant  v)

Definition at line 1024 of file PEBLList.cpp.

1025{
1026
1027 //v[1] should be a list. Just extract the iterators.
1028 PList * plist = v.GetComplexData()->GetList();
1029 Variant v1 = plist->First(); //plist->PopFront();
1030 PError::AssertType(v1, PEAT_LIST, "Argument error in first parameter of function [ListToString(<list>, <sep>, <pre>, <post>)]: ");
1031
1032
1033 PList * tmpList = (PList*)(v1.GetComplexData()->GetObject().get());
1034
1035 vector<Variant>::iterator pstart = tmpList->Begin();
1036 vector<Variant>::iterator p;
1037 vector<Variant>::iterator pend = tmpList->End();
1038
1039 Variant sep1 = "";
1040 Variant pre = "";
1041 Variant post = "";
1042
1043
1044 if(plist->Length()>=2) sep1 = plist->Nth(2);
1045 if(plist->Length()>=3) pre = plist->Nth(3);
1046 if(plist->Length()>=4) post = plist->Nth(4);
1047
1048 //cout << "processing List to string: " << sep1 << "|" << pre <<"|" << post << "|" << endl;
1049 Variant out="";
1050 Variant sep = "";
1051 p = pstart;
1052 while(p!=pend)
1053 {
1054
1055 out = out + sep + pre+ Variant(*p) + post;
1056
1057 if(p == pstart)
1058 sep =sep1;
1059
1060 p++;
1061 }
1062 return out;
1063}

References PError::AssertType(), PList::Begin(), PList::End(), PList::First(), counted_ptr< X >::get(), Variant::GetComplexData(), PComplexData::GetList(), PComplexData::GetObject(), PList::Length(), PList::Nth(), and PEAT_LIST.

◆ MakeMap()

Variant PEBLList::MakeMap ( Variant  v)

Definition at line 842 of file PEBLList.cpp.

843{
844 //v[1] should be a list
845 /* counted_ptr<PList> plist = (v.GetComplexData())->GetList();
846 Variant v1 = plist->First(); plist->PopFront();
847 counted_ptr<PList> myList = v1.GetComplexData()->GetList();
848 */
849 PError::SignalFatalError("Function [MakeMap] not implemented");
850 return Variant(true);
851}
void SignalFatalError(const std::string &message)

References PError::SignalFatalError().

◆ Merge()

Variant PEBLList::Merge ( Variant  v)

This takes two lists and returns a single list

Definition at line 608 of file PEBLList.cpp.

609{
610 PList * plist = v.GetComplexData()->GetList();
611
612 Variant v1 = plist->First();// plist->PopFront();
613 //v[1] should be a list. Just extract the iterators.
614 PError::AssertType(v1, PEAT_LIST, "Argument error in first parameter of function [Merge(<list>, <list>)]: ");
615 PList * tmpList = (PList*)(v1.GetComplexData()->GetObject().get());
616 vector<Variant>::iterator p1start = tmpList->Begin();
617 vector<Variant>::iterator p1 = p1start;
618 vector<Variant>::iterator p1end = tmpList->End();
619
620
621
622 Variant v2 = plist->Nth(2);// plist->PopFront();
623 //v[1] should be a list. Just extract the iterators.
624 PError::AssertType(v2, PEAT_LIST, "Argument error in second parameter of function [Merge(<list>, <list>)]: ");
625
626 tmpList = (PList*)(v2.GetComplexData()->GetObject().get());
627 vector<Variant>::iterator p2start = tmpList->Begin();
628 vector<Variant>::iterator p2 = p2start;
629 vector<Variant>::iterator p2end = tmpList->End();
630
631 //There are now 2 list iterators: p1 and p2, and two ends to compare them to,
632 //and an iterator to the p2start for resetting.
633 //Make a new list to return.
634
635 PList * returnList = new PList();
636
637 Variant tmpVariant;
638
639 //Add the first list.
640 while(p1 != p1end)
641 {
642 returnList->PushBack(*p1);
643 p1++;
644 }
645
646 //Add the second list.
647 while (p2 != p2end)
648 {
649 returnList->PushBack(*p2);
650 p2++;
651 }
652
654 PComplexData * tmpPCD= (new PComplexData(tmpObj));
655
656 Variant tmp = Variant(tmpPCD);
657 delete tmpPCD;
658 tmpPCD=NULL;
659 return tmp;
660
661
662
663}

References PError::AssertType(), PList::Begin(), PList::End(), PList::First(), counted_ptr< X >::get(), Variant::GetComplexData(), PComplexData::GetList(), PComplexData::GetObject(), PList::Nth(), NULL, PEAT_LIST, and PList::PushBack().

◆ ModList()

Variant PEBLList::ModList ( Variant  v)

Definition at line 1067 of file PEBLList.cpp.

1068{
1069 //v[1] should be a list. Just extract the iterators.
1070 PList * plist = v.GetComplexData()->GetList();
1071 Variant v1 = plist->First(); //plist->PopFront();
1072 PError::AssertType(v1, PEAT_LIST, "Argument error in first parameter of function [ModList(<list>, <pre>, <post>)]: ");
1073
1074
1075 PList * tmpList = (PList*)(v1.GetComplexData()->GetObject().get());
1076 PList * newList = new PList(*tmpList);
1077
1078 vector<Variant>::iterator pstart = newList->Begin();
1079 vector<Variant>::iterator p;
1080 vector<Variant>::iterator pend = newList->End();
1081
1082 Variant pre = "";
1083 Variant post = "";
1084
1085
1086 if(plist->Length()>=2) pre = plist->Nth(2);
1087 if(plist->Length()>=3) post = plist->Nth(3);
1088
1089 p = pstart;
1090 while(p!=pend)
1091 {
1092 *p = (pre + *p + post);
1093 p++;
1094 }
1096
1097 PComplexData * PCD =(new PComplexData(newList2));
1098 Variant tmp = Variant(PCD);
1099 delete PCD;
1100 PCD=NULL;
1101 return tmp;
1102
1103}

References PError::AssertType(), PList::Begin(), PList::End(), PList::First(), counted_ptr< X >::get(), Variant::GetComplexData(), PComplexData::GetList(), PComplexData::GetObject(), PList::Length(), PList::Nth(), NULL, and PEAT_LIST.

◆ Nth()

Variant PEBLList::Nth ( Variant  v)

Definition at line 576 of file PEBLList.cpp.

577{
578 PList * plist = v.GetComplexData()->GetList();
579
580
581 //v[1] should be a list
582 Variant v1 = plist->First(); //plist->PopFront();
583 PError::AssertType(v1, PEAT_LIST, "Argument error in first parameter of function [Nth(<list>, <integer>)]: ");
584 PList * myList = (PList*)(v1.GetComplexData()->GetObject().get());
585
586 //v[2] should be an integer
587 PError::AssertType(plist->Nth(2), PEAT_INTEGER, "Argument error in second parameter of function [Nth(<list>, <integer>)]: ");
588 int n = plist->Nth(2);// plist->PopFront();
589 return Variant(myList->Nth(n));
590}
@ PEAT_INTEGER
Definition PError.h:44

References PError::AssertType(), PList::First(), counted_ptr< X >::get(), Variant::GetComplexData(), PComplexData::GetList(), PComplexData::GetObject(), PList::Nth(), PEAT_INTEGER, and PEAT_LIST.

◆ PushOnEnd()

Variant PEBLList::PushOnEnd ( Variant  v)

Given Merge([a,b,c],d), will return [a,b,c,d].

Definition at line 734 of file PEBLList.cpp.

735{
736
737 PList * plist = v.GetComplexData()->GetList();
738
739 Variant v1 = plist->First(); //plist->PopFront();
740 //v[1] should be a list. Just extract the iterators.
741 PError::AssertType(v1, PEAT_LIST, "Argument error in first parameter of function [PushOnEnd(<list>, <listitem>)]: ");
742
743 //Get the list object, and iterators to it:
744 PList * tmpList = (PList*)(v1.GetComplexData()->GetObject().get());
745
746 //Get the other object:
747 Variant v2 = plist->Nth(2);// plist->PopFront();
748 //v[2] can be anything.
749
750 tmpList->PushBack(v2);
751 //v should still contain the list, so return it now.
752 return v1;
753}

References PError::AssertType(), PList::First(), counted_ptr< X >::get(), Variant::GetComplexData(), PComplexData::GetList(), PComplexData::GetObject(), PList::Nth(), PEAT_LIST, and PList::PushBack().

◆ Remove()

Variant PEBLList::Remove ( Variant  v)

Definition at line 1016 of file PEBLList.cpp.

1017{
1018
1019 PError::SignalFatalError("Function [Remove] not implemented");
1020 return Variant(1);
1021}

References PError::SignalFatalError().

◆ RemoveDuplicates()

Variant PEBLList::RemoveDuplicates ( Variant  v)

Definition at line 831 of file PEBLList.cpp.

832{
833 //v[1] should be a list
834 /* counted_ptr<PList> plist = (v.GetComplexData())->GetList();
835 Variant v1 = plist->First(); plist->PopFront();
836 counted_ptr<PList> myList = v1.GetComplexData()->GetList();
837 */
838 PError::SignalFatalError("Function [RemoveDuplicates] not implemented");
839 return Variant(true);
840}

References PError::SignalFatalError().

◆ Repeat()

Variant PEBLList::Repeat ( Variant  v)

Repeat(value, number) This function returns a list with

repeated <number> times The expression is evaluated before it is repeated.

Definition at line 90 of file PEBLList.cpp.

91{
92 //v is a list; v[1] is the object to repeat (can be anything)
93 PList * plist = v.GetComplexData()->GetList();
94 Variant v1 = plist->First(); //plist->PopFront();
95
96
97 //v[2] is the number of repeats: should be a number (will be rounded to integer if needed).
98 PError::AssertType(plist->Nth(2), PEAT_NUMBER, "Argument error in second parameter of function [Repeat(<object>,<number>)]: ");
99
100 Variant numVar = plist->Nth(2);
101 pDouble numDouble = numVar; // Use pDouble type to avoid ambiguity
102 int number = (int)round(numDouble);// Round to nearest integer to handle JSON floats
103
104
105 PList * returnList = new PList();
106 for(int i=0;i<number;i++)
107 {
108 returnList->PushBack(v1);
109 }
110
112 PComplexData * tmpPCD= (new PComplexData(tmplist));
113 Variant tmp = Variant(tmpPCD);
114 delete tmpPCD;
115 tmpPCD=NULL;
116 return tmp;
117
118}
#define pDouble
Definition Defs.h:7
@ PEAT_NUMBER
Definition PError.h:43

References PError::AssertType(), PList::First(), Variant::GetComplexData(), PComplexData::GetList(), PList::Nth(), NULL, pDouble, PEAT_NUMBER, and PList::PushBack().

◆ RepeatExpression()

Variant PEBLList::RepeatExpression ( Variant  v)

RepeatExpression(<name_of_function>, <list_of_parameters>, <number>) This function returns a list <number> long that is produced by the return value of <name_of_function>, evaluated with <list_of_parameters> as parameters. <name_of_function> can be either a standard library function or a user-defined function. This is most useful for generating randomized values, but can also be used to created complex designs by storing global variables.

Definition at line 265 of file PEBLList.cpp.

266{
267 //v[1] should be a list
268 /* counted_ptr<PList> plist = (v.GetComplexData())->GetList();
269 Variant v1 = plist->First(); plist->PopFront();
270 counted_ptr<PList> myList = v1.GetComplexData()->GetList();
271 */
272
273 PError::SignalFatalError("Function [RepeatExpression] not implemented");
274 return Variant(true);
275}

References PError::SignalFatalError().

◆ RepeatList()

Variant PEBLList::RepeatList ( Variant  v)

RepeatList(list, n) This creates a new list consisting of the original list repeated n times.

Definition at line 130 of file PEBLList.cpp.

131{
132 //v[1] should be a list. Just extract the iterators.
133 PList * plist = v.GetComplexData()->GetList();
134
135
136
137 Variant v1 = plist->First(); //plist->PopFront();
138 PError::AssertType(v1, PEAT_LIST, "Argument error in first parameter of function [RepeatList(<list>, <int>)]: ");
139
140 PList * arglist = (PList*)(v1.GetComplexData()->GetObject().get());
141 vector<Variant>::iterator p;
142 vector<Variant>::iterator pstart = arglist->Begin();
143 vector<Variant>::iterator pend = arglist->End();
144
145
146 //v[2] is the number of repeats: should be a number (will be rounded to integer if needed).
147 PError::AssertType(plist->Nth(2), PEAT_NUMBER, "Argument error in second parameter of function [RepeatList(<list>, <number>)]: ");
148 Variant numVar = plist->Nth(2);
149 pDouble numDouble = numVar; // Use pDouble type to avoid ambiguity
150 int number = (int)round(numDouble);// Round to nearest integer to handle JSON floats
151
152
153 //There is now an iterator p, and and end to compare it to, and
154 //an iterator to the pstart for resetting.
155 //Make a new list to return.
156
157 PList * returnList = new PList();
158
159 for(int i=0; i<number; i++)
160 {
161 p=pstart;
162 while (p != pend)
163 {
164 returnList->PushBack(*p);
165 p++;
166 }
167 }
168
170 PComplexData * tmpPCD= (new PComplexData(tmp2));
171 Variant tmp = Variant(tmpPCD);
172 delete tmpPCD;
173 tmpPCD=NULL;
174 return tmp;
175
176
177}

References PError::AssertType(), PList::Begin(), PList::End(), PList::First(), counted_ptr< X >::get(), Variant::GetComplexData(), PComplexData::GetList(), PComplexData::GetObject(), PList::Nth(), NULL, pDouble, PEAT_LIST, PEAT_NUMBER, and PList::PushBack().

◆ Rotate()

Variant PEBLList::Rotate ( Variant  v)

Definition at line 417 of file PEBLList.cpp.

418{
419 //v[1] should be a list. Just extract the iterators.
420 PList * plist = v.GetComplexData()->GetList();
421
422 Variant v1 = plist->First(); //plist->PopFront();
423 PError::AssertType(v1, PEAT_LIST, "Argument error in first parameter of function [Rotate(<list>, <n>)]: ");
424
425 Variant v2 = plist->Nth(2);// plist->PopFront();
426 PError::AssertType(v2, PEAT_INTEGER, "Argument error in second parameter of function [Rotate(<list>, <n>)]: ");
427
428
429 PList * arglist = v1.GetComplexData()->GetList();
430
431 vector<Variant>::iterator pi = arglist->Begin();
432 vector<Variant>::iterator pStart = pi;
433 vector<Variant>::iterator pListStart = pi;
434 vector<Variant>::iterator pEnd = arglist->End();
435
436
437 //startpoint is the 0-based index of which item to start the new list with.
438 int rotation = (int)v2;
439
440 long int length = arglist->Length();
441
442 //We need to find a startpoint as a positive number between 0 and length.
443 //The normal % and mod functions will not produce this.
444
445 int rem1 = rotation % length;
446
447 if(rem1<0)
448 {
449 rem1 = rem1 + (length);
450 }
451 pListStart += (rem1);
452
453
454
455 //Make a new list, starting with pListStart, and moving to
456 //the end, and then attaching pStart to pListStart.
457
458 PList * returnList = new PList();
460 Variant tmpVariant;
461
462 //Adjust the iterator to the start of the list.
463 pi=pListStart;
464 while(pi != pEnd)
465 {
466
467 //Put the item on the list
468 returnList->PushBack(*pi);
469 pi++;
470 }
471
472 pi=pStart;
473 while(pi != pListStart)
474 {
475
476 //Put the item on the list
477 returnList->PushBack(*pi);
478 pi++;
479 }
480
481 tmpObj = counted_ptr<PEBLObjectBase>(returnList);
482 PComplexData * tmpPCD= (new PComplexData(tmpObj));
483 Variant tmp = Variant(tmpPCD);
484 delete tmpPCD;
485 tmpPCD=NULL;
486 return tmp;
487
488
489}

References PError::AssertType(), PList::Begin(), PList::End(), PList::First(), Variant::GetComplexData(), PComplexData::GetList(), PList::Length(), PList::Nth(), NULL, PEAT_INTEGER, PEAT_LIST, and PList::PushBack().

◆ Second()

Variant PEBLList::Second ( Variant  v)

Definition at line 521 of file PEBLList.cpp.

522{
523 //v[1] should be a list
524
525 PList * plist = v.GetComplexData()->GetList();
526
527 Variant v1 = plist->First();// plist->PopFront();
528 PError::AssertType(v1, PEAT_LIST, "Argument error in function [Second(<list>)]: ");
529
530 PList * myList = (PList*)(v1.GetComplexData()->GetObject().get());
531 return myList->Nth(2);
532}

References PError::AssertType(), PList::First(), counted_ptr< X >::get(), Variant::GetComplexData(), PComplexData::GetList(), PComplexData::GetObject(), PList::Nth(), and PEAT_LIST.

◆ Sequence()

Variant PEBLList::Sequence ( Variant  v)

Sequence constructs a sequence of numbers between the low and high, with step-size increments between. Attempts to stay in integers when the low and step are integers.

Definition at line 185 of file PEBLList.cpp.

186{
187 //v is a list; v[1] is the bottom of the sequence
188 PList * plist = v.GetComplexData()->GetList();
189
190 PError::AssertType(plist->First(), PEAT_NUMBER, "Argument error in first parameter of function [Sequence(<first>, <last>, <step>)]");
191 Variant start = plist->First();// plist->PopFront();
192
193 //v[2] is the last number in the sequence
194 PError::AssertType(plist->Nth(2), PEAT_NUMBER, "Argument error in second parameter of function [Sequence(<first>, <last>, <step>)]: ");
195 Variant end = plist->Nth(2);// plist->PopFront();
196
197 //v[3] is the increment step of the sequence.
198 PError::AssertType(plist->Nth(3), PEAT_NUMBER, "Argument error in second parameter of function [Sequence(<first>, <last>, <step>)]: ");
199 Variant step = plist->Nth(3);// plist->PopFront();
200
201
202 //Make sure that the step is not equal to 0--we will never end if it is.
203 if(step == Variant(0))
204 {
205 PError::SignalFatalError("Step size in Sequence(<start>, <end>, <step>) is 0.");
206 }
207
208 Variant tolerance = .00000001;
209
210 PList * returnList = new PList();
211 //returnList->Clear();
212
213 Variant current;
214
215 //We need to operate differently if step is positive vs. negative.
216
217 if(step > Variant(0))
218 {
219 //If step is positive, end better be greater than start.
220 if(end < start)
221 {
222 PError::SignalFatalError("For positive <step>s, <end> must be greater than <start> in [Sequence(<start>, <end>, <step>)]");
223 }
224
225 //Step is positive, continue while less-than end
226 for(current = start; current <= end + tolerance; current = current + step)
227 {
228 returnList->PushBack(current);
229 }
230 }
231 else
232 {
233 //If step is negative, end better be smaller than start.
234 if(end > start)
235 {
236 PError::SignalFatalError("For negative <step>s, <end> must be less than <start> in [Sequence(<start>, <end>, <step>)]");
237 }
238
239 //Step is negative, continue while greater-than end.
240 for(current = start; current >= end - tolerance ; current = current + step)
241 {
242 returnList->PushBack(current);
243 }
244 }
245
247 PComplexData * tmpPCD= (new PComplexData(tmp2));
248 Variant tmp = Variant(tmpPCD);
249 delete tmpPCD;
250 tmpPCD=NULL;
251 return tmp;
252
253
254}

References PError::AssertType(), PList::First(), Variant::GetComplexData(), PComplexData::GetList(), PList::Nth(), NULL, PEAT_NUMBER, PList::PushBack(), and PError::SignalFatalError().

◆ SetElement()

Variant PEBLList::SetElement ( Variant  v)

Definition at line 710 of file PEBLList.cpp.

711{
712 PList * plist = v.GetComplexData()->GetList();
713 Variant v1 = plist->First();
714 PError::AssertType(v1, PEAT_LIST, "Argument error in first parameter of function [SetElement(<list>,<index>,<listitem>)]: ");
715
716
717 Variant v2 = plist->Nth(2);
718 PError::AssertType(v2, PEAT_INTEGER, "Argument error in second parameter of function [SetElement(<list>,<index>,<listitem>)]: ");
719
720
721 Variant v3 = plist->Nth(3);
722 //No need to check v3 for type.
723
724 PList * pl = v1.GetComplexData()->GetList();
725 pl->SetElement((int)v2,v3);
726
727 return Variant(true);
728}
void SetElement(unsigned int n, Variant value)
Definition PList.cpp:222

References PError::AssertType(), PList::First(), Variant::GetComplexData(), PComplexData::GetList(), PList::Nth(), PEAT_INTEGER, PEAT_LIST, and PList::SetElement().

◆ Shuffle()

Variant PEBLList::Shuffle ( Variant  v)

Definition at line 53 of file PEBLList.cpp.

54{
55 //v is a list. v[1] should be have a list in it.
56 PList * plist = v.GetComplexData()->GetList();
57
58 Variant v1 = plist->First(); //plist->PopFront();
59
60 //v1 should be a list.
61 PError::AssertType(v1, PEAT_LIST, "Argument error in function [Shuffled(<list>)]: ");
62
63
64 PList * dataList = (PList*)(v1.GetComplexData()->GetObject().get());
65
66 //Now, make a keylist of random numbers, the length of datalist.
67 PList keyList;// = PList();
68
69 for(unsigned int i = 0; i < dataList->Length(); i++)
70 {
71 keyList.PushBack(RandomUniform());
72 }
73
74
75 //Now, sort by the key list
76 counted_ptr<PEBLObjectBase> newList = dataList->SortBy(keyList);
77 PComplexData * PCD =(new PComplexData(newList));
78
79 Variant tmp = Variant(PCD);
80 delete PCD;
81 PCD=NULL;
82 return tmp;
83
84 }
counted_ptr< PEBLObjectBase > SortBy(const PList &key)
Definition PList.cpp:253

References PError::AssertType(), PList::First(), counted_ptr< X >::get(), Variant::GetComplexData(), PComplexData::GetList(), PComplexData::GetObject(), PList::Length(), NULL, PEAT_LIST, PList::PushBack(), and PList::SortBy().

◆ Sort()

Variant PEBLList::Sort ( Variant  v)

This just sorts the list.

Definition at line 759 of file PEBLList.cpp.

760{
761 //v[1] should be a list
762 PList * plist = v.GetComplexData()->GetList();
763
764
765 Variant v1 = plist->First(); //plist->PopFront();
766 PError::AssertType(v1, PEAT_LIST, "Argument error in function [Sort(<list>)]: ");
767
768 PList * dataList = (PList*)(v1.GetComplexData()->GetObject().get());
769
770 counted_ptr<PEBLObjectBase> newList = dataList->SortBy(*dataList);
771 PComplexData * PCD = (new PComplexData(newList));
772 Variant tmp = Variant(PCD);
773 delete PCD;
774 PCD=NULL;
775 return tmp;
776
777}

References PError::AssertType(), PList::First(), counted_ptr< X >::get(), Variant::GetComplexData(), PComplexData::GetList(), PComplexData::GetObject(), NULL, PEAT_LIST, and PList::SortBy().

◆ SortBy()

Variant PEBLList::SortBy ( Variant  v)

This sorts the list by another list.

Definition at line 781 of file PEBLList.cpp.

782{
783 //v[1] should be a list
784 PList * plist = v.GetComplexData()->GetList();
785
786 Variant v1 = plist->First();// plist->PopFront();
787 PError::AssertType(v1, PEAT_LIST, "Argument error in first parameter of function [SortBy(<list>, <list>)]: ");
788
789 PList * dataList = (PList*)(v1.GetComplexData()->GetObject().get());
790
791 //v[2] should be the keys which the list should be sorted by.
792 Variant v2 = plist->Nth(2);// plist->PopFront();
793 PError::AssertType(v2, PEAT_LIST, "Argument error in second parameter of function [SortBy(<list>, <list>)]: ");
794 PList * keyList = (PList*)(v2.GetComplexData()->GetObject().get());
795
796 counted_ptr<PEBLObjectBase> newList = dataList->SortBy(*keyList);
797 PComplexData * PCD = ( new PComplexData(newList));
798 Variant tmp = Variant(PCD);
799 delete PCD;
800 PCD=NULL;
801 return tmp;
802
803}

References PError::AssertType(), PList::First(), counted_ptr< X >::get(), Variant::GetComplexData(), PComplexData::GetList(), PComplexData::GetObject(), PList::Nth(), NULL, PEAT_LIST, and PList::SortBy().

◆ SubList()

Variant PEBLList::SubList ( Variant  v)

This makes a list out of a sublist of a list. Or something like that.

Definition at line 940 of file PEBLList.cpp.

941{
942
943 //v[1] should be a list. Just extract the iterators.
944 PList * plist = v.GetComplexData()->GetList();
945 Variant v1 = plist->First(); //plist->PopFront();
946 PError::AssertType(v1, PEAT_LIST, "Argument error in first parameter of function [SubList(<list>, <int>, <int>)]: ");
947
948 PList * tmpList = (PList*)(v1.GetComplexData()->GetObject().get());
949 vector<Variant>::iterator pstart = tmpList->Begin();
950 vector<Variant>::iterator p;
951 vector<Variant>::iterator pend = tmpList->End();
952
953
954 PError::AssertType(plist->Nth(2), PEAT_INTEGER, "Argument error in second parameter of function [SubList(<list>, <int>, <int>)]: ");
955 int start = plist->Nth(2); //plist->PopFront();
956
957 PError::AssertType(plist->Nth(3), PEAT_INTEGER, "Argument error in third parameter of function [SubList(<list>, <int>, <int>)]: ");
958 int end = plist->Nth(3); //plist->PopFront();
959
960
961 //Check to see if everything is in bounds.
962 if(start < 1
963 || end > (int)(tmpList->Length())
964 || start > end )
965 {
966 Variant message;
967 message = Variant("[SubList] tried to extract items ")+
968 Variant((int)start)+ Variant(" to ") + Variant((int)end) +
969 Variant(" of a ") + Variant((int)(tmpList->Length())) + Variant( " item list.");
970
972 }
973
974
975
976 //There is now an iterator p, and an end to compare it to, and
977 //an iterator to the pstart for resetting.
978 //Make a new list to return.
979
980 PList * returnList = new PList();
981 Variant tmpVariant;
983 //Start at the beginning of the list. Keep count; if the count is
984 //between the two boundaries, add it to the list.
985 p=pstart;
986 int i = 0;
987 while (p != pend)
988 {
989 i++;
990 //If i is big enough, consider adding it to the list
991 if(i>=start)
992 {
993 if( i <=end) //But only if it isn't too big
994 {
995 returnList->PushBack(*p);
996 }
997 else //If it is too big, get out of the while loop.
998 {
999 break;
1000 }
1001 }
1002 p++;
1003 }
1004 tmpObj = counted_ptr<PEBLObjectBase>(returnList);
1005 PComplexData * tmpPCD = (new PComplexData(tmpObj));
1006 Variant tmp = Variant(tmpPCD);
1007 delete tmpPCD;
1008 tmpPCD=NULL;
1009 return tmp;
1010
1011}

References PError::AssertType(), PList::Begin(), PList::End(), PList::First(), counted_ptr< X >::get(), Variant::GetComplexData(), PComplexData::GetList(), PComplexData::GetObject(), PList::Length(), PList::Nth(), NULL, PEAT_INTEGER, PEAT_LIST, PList::PushBack(), and PError::SignalFatalError().

◆ Third()

Variant PEBLList::Third ( Variant  v)

Definition at line 534 of file PEBLList.cpp.

535{
536 //v[1] should be a list
537
538 PList * plist = v.GetComplexData()->GetList();
539
540 Variant v1 = plist->First(); //plist->PopFront();
541 PError::AssertType(v1, PEAT_LIST, "Argument error in function [Second(<list>)]: ");
542
543 PList * myList = (PList*)(v1.GetComplexData()->GetObject().get());
544 //vector<Variant>::iterator p = myList->Begin();
545 return myList->Nth(3);
546}

References PError::AssertType(), PList::First(), counted_ptr< X >::get(), Variant::GetComplexData(), PComplexData::GetList(), PComplexData::GetObject(), PList::Nth(), and PEAT_LIST.

◆ Transpose()

Variant PEBLList::Transpose ( Variant  v)

v[1] MUST be a list of lists, and each of the sub-lists must be of the same length.

Definition at line 859 of file PEBLList.cpp.

860{
861 //v[1] should be a list
862 PList * plist = v.GetComplexData()->GetList();
863 Variant v1 = plist->First(); //plist->PopFront();
864 PError::AssertType(v1, PEAT_LIST, "Argument error in function [Transpose(<list-of-lists>)]: ");
865
866 PList * tmpList = (PList*)(v1.GetComplexData()->GetObject().get());
867 vector<Variant>::iterator pstart = tmpList->Begin();
868 vector<Variant>::iterator p;
869// vector<Variant>::iterator pend = tmpList->End();
870
871 unsigned long int outerLength = tmpList->Length();
872 unsigned long int innerLength=0;
873
874 //Create a vector of iterators to elements of each sublist.
875 std::vector<vector<Variant>::iterator> listIterators(outerLength,pstart);
876
877 p = pstart;
878
879 for(unsigned int j = 0; j < outerLength; j++)
880 {
881 PError::AssertType(*p, PEAT_LIST, "Every item in Transpose(<list-of-lists>) must be a list. ");
882
883 tmpList = (PList*)((*p).GetComplexData()->GetObject().get());
884 if(j == 0)
885 {
886 innerLength = tmpList->Length();
887 }
888 else
889 {
890 if(tmpList->Length() != innerLength)
891 {
892 PError::SignalFatalError("All sublists must be of the same length in Transpose(<list-of-lists>).");
893 }
894 }
895
896 //assign the iterator to the first element of the sublist.
897 listIterators[j] = tmpList->Begin();
898 p++;
899 }
900
901
902 //Now, everything is in the clear, so transpose.
903
904 PComplexData * tmpPCD;
905 PList * returnList = new PList;
906 Variant tmpVariant;
908
909
910 for(unsigned int i = 0; i < innerLength; i++)
911 {
912 tmpList = new PList();
913
914 for(unsigned int j = 0; j < outerLength; j++)
915 {
916 tmpList->PushBack(*listIterators[j]); //Grab the item from the list
917 listIterators[j]++; //iterate
918 }
919 //The first item of each list has been added to tmpList, so add
920 //it to returnList.
921 tmpObj = counted_ptr<PEBLObjectBase>(tmpList);
922 tmpPCD = (new PComplexData(tmpObj));
923 tmpVariant = Variant(tmpPCD);
924 returnList->PushBack(tmpVariant);
925 delete tmpPCD;
926 tmpPCD=NULL;
927 }
928
929 tmpObj = counted_ptr<PEBLObjectBase>(returnList);
930 tmpPCD= (new PComplexData(tmpObj));
931
932 Variant tmp = Variant(tmpPCD);
933 delete tmpPCD;
934 tmpPCD=NULL;
935
936 return tmp;
937}

References PError::AssertType(), PList::Begin(), PList::First(), counted_ptr< X >::get(), Variant::GetComplexData(), PComplexData::GetList(), PComplexData::GetObject(), PList::Length(), NULL, PEAT_LIST, PList::PushBack(), and PError::SignalFatalError().

Variable Documentation

◆ FunctionTable

PEBL_Function_Type PEBLList::FunctionTable[]

Definition at line 420 of file Functions.h.

421 {
422
423 {(char*)"SHUFFLE", Shuffle, 1, 1},
424 {(char*)"REPEAT", Repeat, 2, 2},
425 {(char*)"REPEATLIST", RepeatList,2, 2},
426 {(char*)"SEQUENCE", Sequence, 3, 3},
427 {(char*)"DESIGNFULLCOUNTERBALANCE", DesignFullCounterbalance, 2, 2},
428 {(char*)"CROSSFACTORWITHOUTDUPLICATES", CrossFactorWithoutDuplicates, 1, 1},
429 {(char*)"ROTATE", Rotate, 2, 2},
430 {(char*)"LENGTH", Length, 1, 1},
431 {(char*)"FIRST", First, 1, 1},
432 {(char*)"SECOND", Second, 1, 1},
433 {(char*)"THIRD", Third, 1, 1},
434 {(char*)"FOURTH", Fourth, 1, 1},
435 {(char*)"FIFTH", Fifth, 1, 1},
436 {(char*)"MERGE", Merge, 2, 2},
437 {(char*)"LIST", List, 1, 1000},
438 {(char*)"APPEND", Append, 2, 2},
439 {(char*)"PUSHONEND", PushOnEnd, 2, 2},
440 {(char*)"SETELEMENT", SetElement, 3, 3},
441 {(char*)"SORT", Sort, 1, 1},
442 {(char*)"SORTBY", SortBy, 2, 2},
443 {(char*)"NTH", Nth, 2, 2},
444 {(char*)"LAST", Last, 1, 1},
445 {(char*)"ISMEMBER", IsMember, 2, 2},
446 {(char*)"REMOVEDUPLICATES", RemoveDuplicates, 1, 1},
447 {(char*)"MAKEMAP", MakeMap, 2, 2},
448 {(char*)"TRANSPOSE", Transpose, 1, 1},
449 {(char*)"SUBLIST", SubList, 3, 3},
450
451 {(char*)"REMOVE", Remove, 2, 2},
452 {(char*)"LISTTOSTRING", ListToString,1,4},
453 {(char*)"MODLIST", ModList,1,3},
454 {0, 0, 0, 0}
455 };

Referenced by Loader::LoadLibraryFunctions().