Beispiel #1
0
void cMenuFileBrowserBase::FlagItem(cMenuBrowserItem *item, bool next)
{
    printf("------------cMenuFileBrowserBase::FlagItem----------\n");
    if(GetLast(item->GetPath()) != std::string(".."))
    {
        printf("--------flaggedEntries_.insert---------\n");
        flaggedEntries_.insert(item->GetId());
	printf("hhhhhhhhhhh IsFlagged(item) = %d\n", IsFlagged(item));
        item->Flag();
        if(next && item->IsFile())
        {
            SetNextCurrent(true);
        }
    }
}
KString KStrings::GenerateString(	LPCTSTR	pDelimeter,
									bool	bLastDelimeter) const
{
	KString String;

	for(TConstIterator Iter = GetFirst() ; Iter.IsValid() ; ++Iter)
	{
		String += *Iter;

		if(Iter != GetLast() || bLastDelimeter)
			String += pDelimeter;
	}

	return String;
}
Beispiel #3
0
//! draws the element and its children
void CNrpGuiFlick::draw()
{
	if (!IsVisible)
		return;

	if( Children.size() > 0 )
	{
		if( IGUIElement* elm = GetFirst() )
			_btnUp->setVisible( elm->getRelativePosition().UpperLeftCorner.Y < 0 );

		if( IGUIElement* elm = GetLast() )
			_btnDown->setVisible( elm->getRelativePosition().LowerRightCorner.Y > AbsoluteRect.getHeight() );
	}

	IGUIElement::draw();
}
RUIUseBuffer* RUIUseBufferList::_FindLastUseBuffer(RUIUseBuffer* pRUIUseBufferBefore, BOOL bUse)
{
	RUIUseBuffer*	pRUIUseBuffer;
	
	if (pRUIUseBufferBefore != NULL) pRUIUseBuffer = (RUIUseBuffer*) GetPrev(pRUIUseBufferBefore);
	else                             pRUIUseBuffer = (RUIUseBuffer*) GetLast();

	while (pRUIUseBuffer != NULL)
	{
		if (pRUIUseBuffer->GetUse() == bUse)
			return pRUIUseBuffer;

		pRUIUseBuffer = (RUIUseBuffer*) GetPrev(pRUIUseBuffer);
	}

	return NULL;
}
Beispiel #5
0
void AddPolyn(polynomail *pa, polynomail *pb) {
	Link *ha, *hb, *hc;					//利用归并的方法,将两个多项式合并成一个
	ha = pa->head->next;
	hb = pb->head->next;
	hc = pa->head;
	while (ha&&hb) {
		if (ha->data->expn < hb->data->expn) {
			hc->next = ha;
			hc = hc->next;
			ha = ha->next;
		}
		else if (ha->data->expn == hb->data->expn) {
			Link *t;
			ha->data->coef += hb->data->coef;
			t = hb;
			hb = hb->next;
			FreeNode(t);
			if (fabs(ha->data->coef) < 1e-6) {
				t = ha;
				ha = ha->next;
				FreeNode(t);
			}
			else {
				hc->next = ha;
				ha = ha->next;
				hc = hc->next;
			}
		}
		else {
			hc->next = hb;
			hc = hc->next;
			hb = hb->next;
		}
	}
	if (ha)hc->next = ha;
	else if (hb)hc->next = hb;
	else hc->next = NULL;
	pb->head->next = NULL;
	DestroyPolyn(pb);
	pa->tail = GetLast(*pa);
	pa->len = ListLength(*pa);
}
Beispiel #6
0
// Delete from list
void wxPropertyValue::Delete(wxPropertyValue *node)
{
  wxPropertyValue *expr = GetFirst();

  wxPropertyValue *previous = NULL;
  while (expr && (expr != node))
  {
    previous = expr;
    expr = expr->GetNext();
  }

  if (expr)
  {
    if (previous)
      previous->m_next = expr->m_next;

    // If node was the first in the list,
    // make the list point to the NEXT one.
    if (GetFirst() == expr)
    {
      m_value.first = expr->m_next;
    }

    // If node was the last in the list,
    // make the list 'last' pointer point to the PREVIOUS one.
    if (GetLast() == expr)
    {
      if (previous)
        m_last = previous;
      else
        m_last = NULL;
    }
    m_modifiedFlag = true;
    delete expr;
  }

}
Beispiel #7
0
// Export the internal data structures into a Flash OS.
BOOLEAN ExportFlashOSFile (const PROGRAM *Program, EXP_FILE *File, SIZE FileSize, ProgramCalcs DestCalc)
{
	// A simple macro to make the code more readable.
#define FailWithError(Err...) ({ Error (Err); return FALSE; })
	
	// Get a pointer to the main section.
	const char *SectionFileName = NULL;
	OFFSET DataStart, DataEnd;
	I4 ROMBase;
	const I1 ZeroByte = 0;
	
	SECTION *MainSection = Program->MainSection;
	
	switch (DestCalc)
	{
		case CALC_TI89:
		case CALC_V200:
			ROMBase = 0x200000;
			break;
		
		case CALC_TI92PLUS:
			ROMBase = 0x400000;
			break;
		
		case CALC_TI89 | CALC_FLAG_TITANIUM:
			ROMBase = 0x800000;
			break;
		
		case CALC_TI92:
			FailWithError (NULL, "Flash upgrades are not available for the TI-92.");
		
		default:
			FailWithError (NULL, "Unknown calculator model.");
	}
	
	if (!MainSection)
		FailWithError (NULL, "No main section.");
	
	SectionFileName = MainSection->FileName;
	
	if (!(MainSection->StartupNumber || (Program->Type == PT_NOSTUB)))
		FailWithError (SectionFileName, "No startup section(s) defined.");
	
	if (!(MainSection->Data))
		FailWithError (SectionFileName, "No section contents.");
	
	// Write out the section contents first.
	DataStart = ExportTell (File);
	ExportWrite (File, MainSection->Data, MainSection->Size, 1);
	// Pad the main section to an even length.
	if (MainSection->Size & 0x1)
		ExportWrite (File, &ZeroByte, 1, 1);
	DataEnd = ExportTell (File);
	
	if (!(IsEmpty (MainSection->Relocs)))
	{
		RELOC *Reloc;
		
		// Write out the relocation entries.
		for (Reloc = GetLast (MainSection->Relocs); Reloc; Reloc = GetPrev (Reloc))
		{
			// Get the current file name for error messages.
			const char *CurFileName = GetFileName (MainSection, Reloc->Location);
			
			// If this can be resolved to a calculator-dependent value, write the
			// value into the section data.
			if (EmitCalcBuiltinValue (Reloc, DestCalc, File, FileSize, DataStart))
				continue;
			
			// We can only emit relocs with a target symbol in the same section.
			if (!(Reloc->Target.Symbol))
				FailWithError (CurFileName, "Unresolved reference to `%s'.", Reloc->Target.SymbolName);
			if (Reloc->Target.Symbol->Parent != MainSection)
				FailWithError (CurFileName, "Cannot emit reloc to `%s' in different section.", Reloc->Target.SymbolName);
			
			// We can only emit 4-byte absolute relocs.
			if (Reloc->Relative || (Reloc->Size != 4))
				FailWithError (CurFileName, "Cannot emit %ld byte %s reloc to `%s'.", (long) Reloc->Size, Reloc->Relative ? "relative" : "absolute", Reloc->Target.SymbolName);
			
			{
				OFFSET TargetLocation = GetLocationOffset (MainSection, &(Reloc->Target)) + Reloc->FixedOffset;
				
				TargetLocation += (OFFSET) (ROMBase + 0x12000);
				ExportSeek (File, DataStart + Reloc->Location);
				ExportWriteTI (File, TargetLocation, Reloc->Size, TRUE, TRUE);
				
				// Do not increase the statistics, since that would give a false
				// impression that the relocation entries actually take up some
				// space in the OS.
			}
		}
		ExportSeek (File, DataEnd);
	}
	
	if ((!(IsEmpty (MainSection->ROMCalls))) && (!(MainSection->ROMCalls.Handled)))
		FailWithError (SectionFileName, "ROM calls are not supported in Flash OSs.");
	
	if ((!(IsEmpty (MainSection->RAMCalls))) && (!(MainSection->RAMCalls.Handled)))
		FailWithError (SectionFileName, "RAM calls are not supported in Flash OSs.");
	
	if ((!(IsEmpty (MainSection->LibCalls))) && (!(MainSection->LibCalls.Handled)))
		FailWithError (SectionFileName, "Library calls are not supported in Flash OSs.");
	
	return TRUE;
	
#undef FailWithError
}
Beispiel #8
0
int main(int argc, char** argv) {
   BinaryStr val;
   int i=0;
   ListNode* node,*end;

   if (argc <2) {
      printf("Usage : %s <existing list filename or new filename to store disk list> \n",argv[0]);
      return -1;
   }
   DiskList* dList = ListInit(argv[1]);
   printf("DiskList %p\n",dList);
   assert(dList);
   //Adding to the end

   while(1){
      int opt;
      printf("<list: choose operation [1-4] 4 for help~>");
      scanf("%d",&opt);
      if (opt > 7) {
         printf("Invalid option.\n");
         opt = 4;
      } 
      if (opt == 4) {
         printf("1 --> to add an element.\n");
         printf("2 --> to remove an element.\n");
         printf("3 --> to print list\n");
         printf("4 --> to print this help message\n");
         printf("5 --> Start transaction .\n");
         printf("6 --> Commit transaction.\n");
         printf("7 --> Abort transaction.\n");
         continue;
      }
      if (opt == 1) {
         int fVal,val;
         BinaryStr s;
         BlockMgrDiskPtr ptr;
         printf("Enter element to add after, enter non-existing element to add to end of the list.\n");
         printf(":~");
         scanf("%d",&fVal);
         printf("Enter value to add.\n");
         printf(":~");
         scanf("%d",&val);
         s.data = (char*)&fVal; 
         s.len = sizeof(fVal);
         if (ListFind(dList,s,&ptr)) {
            ptr = GetLast(dList);
         }
         assert((node = ListLoadNode(dList,ptr)));
         s.data = (char*) &val; 
         s.len = sizeof(val);
         ListAddAfter(dList,node,s);

      }
      if (opt ==3) {
         ListPrint(dList);
         printf("\n");
      }
      if (opt == 2) {
         int fVal,val;
         BinaryStr s;
         BlockMgrDiskPtr ptr;
         printf("Enter value to remove.\n");
         printf(":~");
         scanf("%d",&val);
         s.data = (char*)&val; 
         s.len = sizeof(val);
         if (ListFind(dList,s,&ptr)) {
            printf("Value %d does not exists in the list.\n",val);
            continue;
         }
         assert((node = ListLoadNode(dList,ptr)));
         s.data =(char*) &val; 
         s.len = sizeof(val);
         ListRemove(dList,node);
      }
      if (opt == 5) {
         printf("Starting transaction.\n");
         BlockMgrTransactStart(dList->handle);
      }
      if (opt == 6) {
         printf("Committing transaction.\n");
         BlockMgrTransactCommit(dList->handle);
         BlockMgrTransactReplay(dList->handle);
      }

      if (opt == 7) {
         printf("Aborting transaction.\n");
         BlockMgrTransactAbort(dList->handle);
      }
   }
   return 0;
}
void ribi::gtst::ParticipantDialogStateGroupReAssign::ShowPage(ParticipantDialog * const dialog)
{
  assert(dialog);
  assert(GetDialog()->CanGetParticipant()
    && "A Participant must be logged in in this state");

  const boost::shared_ptr<const Participant>& participant = dialog->GetParticipant();
  assert(GetDialog()->GetParticipant()->CanGetId()
    && "A Participant must be assigned an ID before entering this state");

  const auto payoffs = participant->GetPayoffs();

  const Group * const group = m_server->GetGroups()->FindMyGroup(participant);
  assert(group);

  //Create the widget(s)
  ui.m_label_status = new Wt::WLabel;
  ui.m_label_time_left = new Wt::WLabel;

  //Check the widget(s)
  assert(ui.m_label_status);
  assert(ui.m_label_time_left);

  dialog->addWidget(new Wt::WBreak);
  dialog->addWidget(new Wt::WBreak);
  dialog->addWidget(new Wt::WLabel("Group re-assign"));
  dialog->addWidget(new Wt::WBreak);
  dialog->addWidget(new Wt::WBreak);
  dialog->addWidget(ui.m_label_time_left);
  dialog->addWidget(new Wt::WBreak);
  dialog->addWidget(new Wt::WBreak);
  dialog->addWidget(new Wt::WLabel("This is the end of this period"));
  dialog->addWidget(new Wt::WBreak);
  dialog->addWidget(new Wt::WBreak);
  dialog->addWidget(new Wt::WLabel(
    (std::string("You are in group #")
    + std::to_string(group->GetId())).c_str()));
  dialog->addWidget(new Wt::WBreak);
  dialog->addWidget(new Wt::WLabel(
    (std::string("Your earnings in this period are ")
      + CurrencyToStr(payoffs->GetLast()->m_payoff)
      + std::string(" points")).c_str()));
  dialog->addWidget(new Wt::WBreak);
  dialog->addWidget(new Wt::WLabel(
    (std::string("Your total earnings are ")
      + CurrencyToStr(payoffs->GetTotal())
      + std::string(" points")).c_str()));
  dialog->addWidget(new Wt::WBreak);
  dialog->addWidget(new Wt::WBreak);
  dialog->addWidget(new Wt::WLabel("Group average earnings:"));
  dialog->addWidget(new Wt::WBreak);
  dialog->addWidget(new Wt::WBreak);

  Wt::WTable * table = new Wt::WTable(dialog);
  const auto groups = m_server->GetGroups()->CollectGroups(false,false,true,false);
  std::for_each(groups.begin(),groups.end(),
    [&dialog,&table,this,group](const Group* const any_group)
    {
      assert(!any_group->GetAveragePayoffs().empty());
      table->insertRow(0);

      table->elementAt(0,0)->addWidget(new Wt::WText(
        Wt::WString("Group {1}").arg(any_group->GetId())));

      table->elementAt(0,1)->addWidget(new Wt::WText(
        Wt::WString("{1} points").arg(
          this->CurrencyToStr(any_group->GetAveragePayoffs().back()))));

      if (any_group == group)
      {
        table->elementAt(0,2)->addWidget(new Wt::WText("your group"));
      }
    }
  );


  dialog->addWidget(new Wt::WBreak);
  dialog->addWidget(new Wt::WBreak);

  ServerStateGroupReAssign * const server_state
    = dynamic_cast<ServerStateGroupReAssign*>(m_server->GetStates()->GetCurrentState());
  if (!server_state)
  {
    std::clog << __func__ << ": warning: no ServerStateGroupReAssign\n";
    return;
  }

  const auto p = server_state->GetWorstAndBestGroup();
  if (group == p.first)
  {
    //Worst
    if (p.second->GetSize() == 5)
    {
      dialog->addWidget(new Wt::WText("Your group has the lowest average earnings in this period"));
      dialog->addWidget(new Wt::WBreak);
      dialog->addWidget(new Wt::WText("and has been selected to <b>be eliminated from the experiment</b>"));
    }
    else
    {
      dialog->addWidget(new Wt::WText(Wt::WString("Group {1} has the highest average earnings in this period and has been selected to grow").arg(p.first->GetId())));
      dialog->addWidget(new Wt::WBreak);
      dialog->addWidget(new Wt::WText(Wt::WString("This group grows from 3 to 5 members.")));
      dialog->addWidget(new Wt::WBreak);
      dialog->addWidget(new Wt::WText(Wt::WString("Your group <b>remains the same</b>")));
    }
  }
  else if (group == p.second)
  {
    if (group->GetSize() == 5)
    {
      dialog->addWidget(new Wt::WText("Your group has the highest average earnings in this period"));
      dialog->addWidget(new Wt::WBreak);
      dialog->addWidget(new Wt::WText("and has been selected to <b>grow and split</b> into two groups."));
      dialog->addWidget(new Wt::WBreak);
      dialog->addWidget(new Wt::WText("Your group first grows from 5 to 6 members, and then splits into two groups of three members."));
      dialog->addWidget(new Wt::WBreak);
      dialog->addWidget(new Wt::WText("Your group in the next period will be one of those two groups"));
    }
    else
    {
      dialog->addWidget(new Wt::WText("Your group has the highest average earnings in this period and has been selected to <b>grow</b>"));
      dialog->addWidget(new Wt::WBreak);
      dialog->addWidget(new Wt::WText("Your group grows from 3 to 5 members"));
    }
  }
  else
  {
    if (p.second->GetSize() == 3)
    {
      //Best group grows
      dialog->addWidget(new Wt::WText(Wt::WString("Group {1} has the highest average earnings in this period and has been selected to grow").arg(p.first->GetId())));
      dialog->addWidget(new Wt::WBreak);
      dialog->addWidget(new Wt::WText(Wt::WString("This group grows from 3 to 5 members.")));
      dialog->addWidget(new Wt::WBreak);
      dialog->addWidget(new Wt::WText(Wt::WString("Your group <b>remains the same</b>")));
    }
    else
    {
      //Best group splits, worst dies
      dialog->addWidget(new Wt::WText(Wt::WString("Group {1} has the highest average earnings in this period").arg(p.second->GetId())));
      dialog->addWidget(new Wt::WBreak);
      dialog->addWidget(new Wt::WText("and has been selected to grow and split into two groups."));
      dialog->addWidget(new Wt::WBreak);
      dialog->addWidget(new Wt::WText(Wt::WString("Group {1} has the lowest average earnings in this period").arg(p.first->GetId())));
      dialog->addWidget(new Wt::WBreak);
      dialog->addWidget(new Wt::WText("and has been selected to be eliminated from the experiment."));
      dialog->addWidget(new Wt::WBreak);
      dialog->addWidget(new Wt::WText(Wt::WString("Your group <b>remains the same</b>")));
    }
  }

  dialog->addWidget(new Wt::WBreak);
  dialog->addWidget(new Wt::WBreak);

  if (group == p.first && p.second->GetSize() == 5)
  {
    //A dead Participant :3
    dialog->addWidget(new Wt::WLabel("For you, this experiment ends now"));
  }
  else
  {
    //A survivor
    #define TEMP_DEBUG_215487632492487527652376428
    #ifdef TEMP_DEBUG_215487632492487527652376428
    if(!dynamic_cast<const PayoffReAssign*>(payoffs->GetLast().get()))
    {
      TRACE(group->GetId());
      TRACE(participant->GetId());
    }
    #endif
    assert(dynamic_cast<const PayoffReAssign*>(payoffs->GetLast().get()));
    dialog->addWidget(new Wt::WLabel(
      Wt::WString("You earn {1} points for reaching the next period").arg(
        CurrencyToStr(payoffs->GetLast()->m_payoff))));
  }

}
const char  * Exception::LastError(ERRCOD_T& werr, UINT16& mid)
{
    werr = errorCode;
    mid = objId;
    return (hasMessage) ? GetLast( ) : NULL;
}