示例#1
0
int nthUglyNumber(int n) {
  List L;
  PtrItem TwoItem, ThreeItem, FiveItem, TargetItem;
  Position P;
  int i, NextUglyNumber;

  TwoItem = NewItem();
  ThreeItem = NewItem();
  FiveItem = NewItem();

  L = Initialize();
  Insert(L, 1);
  TwoItem -> P = ThreeItem -> P = FiveItem -> P = L -> Head;

  i = 1;
  while (i < n)
  {
    NextUglyNumber = GetMinOfThreeNum(TwoItem, ThreeItem, FiveItem, &TargetItem);
    if (NextUglyNumber != L -> Last -> val)
    {
      Insert(L, NextUglyNumber);
      ++i;
    }
  
    TargetItem -> P = TargetItem -> P -> next;    
  }

  NextUglyNumber = L -> Last -> val;;
  Destroy(L);
  return NextUglyNumber;
}
示例#2
0
static int ReadMenu(CurPos &cp, const char *MenuName) {
    unsigned char obj;
    unsigned short len;

    int menu = -1, item = -1;

    menu = NewMenu(MenuName);

    while ((obj = GetObj(cp, len)) != 0xFF) {
        switch (obj) {
        case CF_ITEM:
            {
                if (len == 0) {
                    item = NewItem(menu, 0);
                } else {
                    const char *s = GetCharStr(cp, len);
                    int Cmd;
                    if (s == 0) return -1;
                    item = NewItem(menu, s);
                    if ((obj = GetObj(cp, len)) != CF_MENUSUB) return -1;
                    if ((Cmd = ReadCommands(cp, 0)) == -1) return -1;
                    Menus[menu].Items[item].Cmd = Cmd + 65536;
                }
            }
            break;
        case CF_SUBMENU:
            {
                const char *s = GetCharStr(cp, len);
                const char *w;

                if ((obj = GetObj(cp, len)) != CF_STRING) return -1;
                if ((w = GetCharStr(cp, len)) == 0) return -1;
                item = NewSubMenu(menu, s, GetMenuId(w), SUBMENU_NORMAL);
            }
            break;

        case CF_SUBMENUCOND:
            {
                const char *s = GetCharStr(cp, len);
                const char *w;

                if ((obj = GetObj(cp, len)) != CF_STRING) return -1;
                if ((w = GetCharStr(cp, len)) == 0) return -1;
                item = NewSubMenu(menu, s, GetMenuId(w), SUBMENU_CONDITIONAL);
            }
            break;

        case CF_END:
            return 0;
        default:
            return -1;
        }
    }
    return -1;
}
示例#3
0
文件: proj_1.c 项目: jjrob13/CSE430
TEST
test_Enqueue(){
	Queue q;
	Node *newItem, *newItem2, *newItem3;
	InitQueue(&q);
	
	newItem = NewItem();
	
	//add item to queue
	AddQueue(&q, newItem);

	ASSERT(q.head == newItem);
	ASSERT(q.tail == newItem);
	ASSERT(q.count == 1);

	newItem2 = NewItem();
	AddQueue(&q, newItem2);

	//make sure that head val has not changed, and only tail val has changed
	ASSERT(q.head == newItem);
	ASSERT(q.tail == newItem2);
	ASSERT(q.count == 2);
	//head should point at tail
	ASSERT(q.head->next == q.tail);

	//one more for good measure
	newItem3 = NewItem();
	AddQueue(&q, newItem3);
	//head has not changed, as we add to the end
	ASSERT(q.head == newItem);
	//tail is our new item
	ASSERT(q.tail == newItem3);
	//count updated correctly
	ASSERT(q.count == 3);
	//head.prev points to tail
	ASSERT(q.head->prev == q.tail);
	//head.next does not point to tail, points to middle
	ASSERT(q.head->next == newItem2);
	//3 items, all connected
	ASSERT(q.head->next->next == q.tail);
	//tail.next == head
	ASSERT(q.tail->next == q.head);
	
	//free items
	FreeItem(newItem);
	FreeItem(newItem2);
	FreeItem(newItem3);


	PASS();
}
示例#4
0
文件: proj_1.c 项目: jjrob13/CSE430
TEST
test_RotateQ(){

	Queue q;
	InitQueue(&q);
	Node *newItem1, *newItem2, *newItem3, *newItem4;

	newItem1 = NewItem();
	newItem2 = NewItem();
	newItem3 = NewItem();
	newItem4 = NewItem();

	AddQueue(&q, newItem1);
	AddQueue(&q, newItem2);
	AddQueue(&q, newItem3);
	AddQueue(&q, newItem4);

	//Queue is 1 2 3 4
	ASSERT(q.head == newItem1);
	ASSERT(q.tail == newItem4);

	RotateQ(&q);
	//Queue is 2 3 4 1
	ASSERT(q.head == newItem2);
	ASSERT(q.tail == newItem1);

	RotateQ(&q);
	//Queue is 3 4 1 2
	ASSERT(q.head == newItem3);
	ASSERT(q.tail == newItem2);

	RotateQ(&q);
	//Queue is 4 1 2 3
	ASSERT(q.head == newItem4);
	ASSERT(q.tail == newItem3);

	RotateQ(&q);
	//Queue is 1 2 3 4
	ASSERT(q.head == newItem1);
	ASSERT(q.tail == newItem4);

	FreeItem(newItem1);
	FreeItem(newItem2);
	FreeItem(newItem3);
	FreeItem(newItem4);
	
	PASS();
}
bool History::GetAllSimilar(VMenu2 &HistoryMenu,const string& Str)
{
	int Length=static_cast<int>(Str.size());
	DWORD index=0;
	string strHName,strHGuid,strHFile,strHData;
	history_record_type HType;
	bool HLock;
	unsigned __int64 id;
	unsigned __int64 Time;
	while (HistoryCfgRef()->Enum(index++,m_TypeHistory,m_HistoryName,&id,strHName,&HType,&HLock,&Time,strHGuid,strHFile,strHData,true))
	{
		if (!StrCmpNI(Str.data(),strHName.data(),Length))
		{
			MenuItemEx NewItem(strHName);
			if(HLock)
			{
				NewItem.Flags|=LIF_CHECKED;
			}
			HistoryMenu.SetUserData(&id,sizeof(id),HistoryMenu.AddItem(NewItem));
		}
	}
	if(HistoryMenu.GetItemCount() == 1 && HistoryMenu.GetItemPtr(0)->strName.size() == static_cast<size_t>(Length))
	{
		HistoryMenu.DeleteItems();
		return false;
	}

	return true;
}
示例#6
0
文件: Main.cpp 项目: stievie/Martis
void TMainForm::AddItemToShowDockMenu(TForm * pForm)
{
  //TODO: Add your source code here
  TMenuItem *pMenuItem = NewItem(pForm->Caption, 0, TRUE, TRUE,
    ShowDockWindowMenuClick, 0, "");
  ShowWindow_Menu->Add(pMenuItem);
  pMenuItem->Tag = (int)pForm;
  pForm->Tag = (int)pMenuItem;
}
示例#7
0
文件: proj_1.c 项目: jjrob13/CSE430
TEST
test_NewItem(){
	Node * newItem;
	newItem = NewItem();
	ASSERT(newItem);

	FreeItem(newItem);

	PASS();
}
示例#8
0
//---------------------------------------------------------------------------
//新 Item
Item* AddItem(Item *node, int iWeight, int iProfit) {

    if (node == NULL)
        return NewItem(iWeight, iProfit);

    if ((float)iProfit / iWeight > node->fRatio)
        node->itmRight = AddItem(node->itmRight, iWeight, iProfit);
    else
        node->itmLeft = AddItem(node->itmLeft, iWeight, iProfit);

    return node;
}
示例#9
0
void FPTree::GenerateFPItems()
{
    ifstream fin(file);
    string key;
    while(fin >> key)
    {
        if(fpMap.count(key) > 0)
        {
            fpMap[key]++;
        }else
        {
            fpMap[key] = 1;
        }
    }
    fin.close();
    
    // 需满足最小支持度
    for(unordered_map<string, int>::const_iterator i = fpMap.begin(); i != fpMap.end();)
    {
        if(i -> second < minSupport)
        {
            i = fpMap.erase(i);
        }else
        {
            i ++;
        }
    }
    
    for(unordered_map<string, int>::const_iterator i = fpMap.begin(); i != fpMap.end(); i++)
    {
        FPItem* fpItem = NewItem(i -> first, i -> second);
        fpItems.push_back(fpItem);
    }

    for(int i = 0; i < fpItems.size(); i++)
    {
        cout << fpItems[i] -> itemData << ": " << fpItems[i] -> support << endl;
    }
    cout << "=======\n";
    sort(fpItems.begin(), fpItems.end(),[](FPItem* l, FPItem* r){if(l -> support == r -> support)
    {
        return stoi(l -> itemData) < stoi(r -> itemData);
    }return l -> support > r -> support;});
    for(int i = 0; i < fpItems.size(); i++)
    {
        cout << fpItems[i] -> itemData << ": " << fpItems[i] -> support << endl;
    }
}
示例#10
0
//-----------------------------------------------------------------------------
TBaseItem* TFactoryGameItem::Get(Type type, std::string& name)
{
  TMapStrPtrItem* pMap = FindMap(type);
  TBaseItem* pItem = FindItemInMapByName(name, pMap);
  if(pItem)
    return pItem;
  
  pItem = NewItem(type, name);
  if(mMngSerializer->Load(type, pItem)==false)
  {
    delete pItem;
    return NULL;
  }
  mListItems.push_back(pItem);
  AddItemInMap(pItem, pMap);
  return pItem;
}
示例#11
0
void FileDataCache::Load()
{
   m_cache.Destroy();

   m_durationDays = 30;
   Settings::Read( m_keyPrefix + "Duration", m_durationDays );
   m_durationDays = Max( 0, m_durationDays );

   m_enabled = true;
   Settings::Read( m_keyPrefix + "Enabled", m_enabled );

   if ( IsEnabled() )
   {
      FileDataCacheItem* item = 0;

      try
      {
         for ( int i = 0; ; ++i )
         {
            item = NewItem();

            if ( !item->Load( m_keyPrefix, i ) )
            {
               delete item, item = 0;
               break;
            }

            if ( m_durationDays > 0 && item->DaysSinceLastUsed() > unsigned( m_durationDays ) )
               delete item;
            else
               m_cache.Add( item );

            item = 0;
         }
      }
      catch ( ... )
      {
         if ( item != 0 )
            delete item;
         m_cache.Destroy();
         throw Error( "FileDataCache::Load(): Corrupted cache data" );
      }
   }
}
示例#12
0
// native interface
Int32 CDrmRawContent::NativeConstructDrmContent(
    /* [in] */ IInputStream *data,
    /* [in] */ Int32 len,
    /* [in] */ Int32 mimeType)
{
    Int32 id;
    T_DRM_Input_Data inData;
    DrmData* drmInData;

    switch (mimeType) {
    case DRM_MIMETYPE_MESSAGE:
        mimeType = TYPE_DRM_MESSAGE;
        break;
    case DRM_MIMETYPE_CONTENT:
        mimeType = TYPE_DRM_CONTENT;
        break;
    default:
        return JNI_DRM_FAILURE;
    }

    drmInData = NewItem();
    if (NULL == drmInData)
        return JNI_DRM_FAILURE;

    drmInData->pInData = data;
    drmInData->len = len;

    if (JNI_DRM_FAILURE == AddItem(drmInData))
        return JNI_DRM_FAILURE;

    inData.inputHandle = (int32_t)drmInData;
    inData.mimeType = mimeType;
    inData.getInputDataLength = GetInputStreamDataLength;
    inData.readInputData = ReadInputStreamData;

    id = SVC_drm_openSession(inData);
    if (id < 0)
        return JNI_DRM_FAILURE;

    drmInData->id = id;

    return id;
}
示例#13
0
void FPTree::BuildConditionFPItems(FPItem *fpItem,vector<FPItem *>& childFpItems)
{
    if(fpItem == NULL)
    {
        return;
    }
    unordered_map<string, int> childMap;
    vector<FPNode*> fpNodes = fpItem -> fpNodes;
    for(int i = 0; i < fpNodes.size(); i++)
    {
        FPNode* fpNode = fpNodes[i];
        while(fpNode -> parent != NULL && fpNode -> parent -> fpData -> data != "$")
        {
            string key = fpNode -> parent -> fpData -> data;
            if(childMap.count(key) > 0)
            {
                childMap[key] += fpNodes[i] -> fpData -> support;
            }else
            {
                childMap[key] = fpNodes[i] -> fpData -> support;
            }
            fpNode = fpNode -> parent;
        }
    }
    
    for(unordered_map<string, int>::const_iterator i = childMap.begin(); i != childMap.end();)
    {
        if(i -> second < minSupport)
        {
            i = childMap.erase(i);
        }else
        {
            i ++;
        }
    }
    
    for(unordered_map<string, int>::const_iterator i = childMap.begin(); i != childMap.end(); i++)
    {
        FPItem* fpItem = NewItem(i -> first, i -> second);
        childFpItems.push_back(fpItem);
    }
    
}
示例#14
0
static BOOL CALLBACK EnumWindowsProc(HWND Window, LPARAM Param)
{
	const auto Info = reinterpret_cast<ProcInfo*>(Param);

	try
	{
		if (!is_alttab_window(Window))
			return true;

		string WindowTitle;
		os::GetWindowText(Window, WindowTitle);

		DWORD ProcID;
		GetWindowThreadProcessId(Window, &ProcID);

		string MenuItem;

		if (Info->ShowImage)
		{
			if (const auto Process = os::handle(OpenProcess(imports.QueryFullProcessImageNameW? PROCESS_QUERY_LIMITED_INFORMATION : PROCESS_QUERY_INFORMATION | PROCESS_VM_READ, false, ProcID)))
				// BUGBUG check result
				(void)os::fs::GetModuleFileName(Process.native_handle(), nullptr, MenuItem);

			if (MenuItem.empty())
				MenuItem = L"???"s;
		}
		else
		{
			MenuItem = WindowTitle;
		}

		MenuItemEx NewItem(format(L"{0:9} {1} {2}"sv, ProcID, BoxSymbols[BS_V1], MenuItem));
		// for sorting
		NewItem.ComplexUserData = menu_data{ WindowTitle, ProcID, Window };
		Info->procList->AddItem(NewItem);

		return true;
	}
	CATCH_AND_SAVE_EXCEPTION_TO(Info->ExceptionPtr)

	return false;
}
示例#15
0
void CSingleItem::AddItems (SItemAddCtx &Ctx)

//	AddItems
//
//	Add items

	{
	//	Ignore if not debugging

	if (m_bDebugOnly && !g_pUniverse->InDebugMode())
		return;

	//	Create item

	CItem NewItem(m_pItemType, 1);
	if (mathRandom(1, 100) <= m_iDamaged)
		NewItem.SetDamaged();
	else
		m_Enhanced.EnhanceItem(NewItem);

	Ctx.ItemList.AddItem(NewItem);
	}
示例#16
0
void FileDataCache::Add( const FileDataCacheItem& item )
{
   FileInfo info( item.path );
   if ( !info.Exists() || !info.IsFile() )
      throw Error( "FileDataCache::Add(): No such file: " + item.path );

   cache_index::const_iterator i = m_cache.Search( item );
   if ( i == m_cache.End() )
   {
      FileDataCacheItem* newItem = NewItem();
      newItem->path = item.path;
      m_cache.Add( newItem );
      i = m_cache.Search( newItem );
   }

#define newItem (*const_cast<cache_index::iterator>( i ))
   time_t t0 = ::time( 0 );
   const tm* t = ::gmtime( &t0 );
   newItem->lastUsed = unsigned( ComplexTimeToJD( t->tm_year+1900, t->tm_mon+1, t->tm_mday ) );
   newItem->time = info.LastModified();
   newItem->AssignData( item );
#undef newItem
}
示例#17
0
void CFontExplorerApp::OnStockfont() 
   {
    //CStockFont dlg;                                               // REQ #055
    //dlg.DoModal();                                                // REQ #055
    NewItem(StockFontTemplate);                                     // REQ #055
}
示例#18
0
void CFontExplorerApp::OnRaster() 
   {
    // CRaster dlg;                                                 // REQ #054
    // dlg.DoModal();                                               // REQ #054
    NewItem(RasterExplorerTemplate);                                // REQ #054
   }
示例#19
0
void CFontExplorerApp::OnGetcharplacement() 
   {
    // CCharacterPlacement dlg;                                     // REQ #005
    //dlg.DoModal();                                                // REQ #005
    NewItem(GetCharacterPlacementTemplate);                         // REQ #005
   }
示例#20
0
void CFontExplorerApp::OnKernexp() 
   {
    // CKerning dlg;                                                // REQ #005
    // dlg.DoModal();                                               // REQ #005
    NewItem(KerningExplorerTemplate);                               // REQ #005
}
示例#21
0
void CFontExplorerApp::OnLogfont() 
   {
    //CLogFontExplorer dlg;                                         // REQ #053
    //dlg.DoModal();                                                // REQ #053
    NewItem(LogFontExplorerTemplate);                               // REQ #053
}
示例#22
0
void ReadMaterialComp()
{
  char *input, fname[MAX_STR], word[MAX_STR], pname[MAX_STR], **params;
  long loc0, loc1, mat, mat0, iso, iso0, nuc, i0, i, np, j, n, line, r, g, b;
  double val, sum;
  FILE *fp;

  /* Get pointer to file list */

  if ((loc0 = (long)RDB[DATA_PTR_COMP_FILE]) < VALID_PTR)
    return;

  fprintf(out, "Overriding initial material compositions...\n");

  /* Reset previous pointer */

  mat0 = -1;

  /* Reset counters for line number calculation */

  WDB[DATA_LINE_NUM_N0] = 0.0;
  WDB[DATA_LINE_NUM_NL0] = 1.0;

  /* Loop over list */

  while (RDB[loc0] > VALID_PTR)
    {
      /* Get file name */

      sprintf(fname, "%s", GetText(loc0));

      /* Check that file exists */

      if ((fp = fopen(fname, "r")) != NULL)
	fclose(fp);
      else
	{
	  /* File not found */
	  
	  Error(0, "Material composition file \"%s\" does not exist", fname);
	}

      /* Read input file */
  
      input = ReadTextFile(fname);

      /* Avoid compiler warning */
      
      params = NULL;

      /* Loop over file */
      
      i0 = 0;
      while ((i = NextWord(&input[i0], word)) > 0)
	{
	  /* update pointer */
	  
	  i0 = i0 + i;

	  /* Get line number for error messages */
	  
	  line = GetLineNumber(input, i0);

	  /* Look for material definition */

	  if (!strcasecmp(word, "mat"))
	    {
	      /* Copy parameter name */

	      strcpy (pname, word);

	      /* Read parameters */

	      params = GetParams(word, input, &np, &i0, 4, 4*MAX_ISOTOPES + 8, 
				 fname);

	      /* Read data */

	      j = 0;

	      /* Find material (try starting from previous) */

	      mat = mat0;
	      while (mat > VALID_PTR)
		{
		  /* Compare */

		  if (!strcmp(params[j], GetText(mat + MATERIAL_PTR_NAME)))
		    break;

		  /* Next */

		  mat = NextItem(mat);
		}

	      /* Find material (start from beginning) */

	      if (mat < VALID_PTR)
		{
		  mat = (long)RDB[DATA_PTR_M0];
		  while (mat > VALID_PTR)
		    {
		      /* Compare */
		      
		      if (!strcmp(params[j], GetText(mat + MATERIAL_PTR_NAME)))
			break;
		      
		      /* Next */
		      
		      mat = NextItem(mat);
		    }
		}

	      /* Check */

	      if (mat < VALID_PTR)
		Error(-1, pname, fname, line, "Material %s is not defined",
		      params[j]);
	      else
		j++;

	      /* Remember previous */

	      mat0 = NextItem(mat);
	      
	      /* Material density */

	      if (!strcmp(params[j], "sum"))
		{
		  /* Set value to -inf to calculate sum from composition */
		  
		  WDB[mat + MATERIAL_ADENS] = -INFTY;
		  
		  j++;
		}
	      else
		{
		  /* Read value */
		  
		  WDB[mat + MATERIAL_ADENS] = 
		    TestParam(pname, fname, line, params[j++], PTYPE_REAL,
			      -1000.0, 1000.0);
		}

	      /* Reset sum */

	      sum = 0.0;

	      /* Reset previous pointer */

	      iso0 = -1;

	      /* Loop over parameters */
	  
	      while (j < np)
		{
		  /* Check parameter */
		  
		  if (!strcmp(params[j], "tmp"))
		    {
		      /***** Temperature for Doppler-breadening **************/
		  
		      j++;
		      
		      /* Get temperature */
		      
		      WDB[mat + MATERIAL_DOPPLER_TEMP] = 
			TestParam(pname, fname, line, params[j++], 
				  PTYPE_REAL, 0.0, 100000.0);

		      /* Set option */
		      
		      WDB[DATA_USE_DOPPLER_PREPROCESSOR] = (double)YES;
		      
		      /*******************************************************/
		    }
		  if (!strcmp(params[j], "tms") || !strcmp(params[j], "ettm"))
		    {
		      /***** Temperature for TMS *****************************/
		  
		      j++;
		      
		      /* Get temperature */
		      
		      WDB[mat + MATERIAL_TMS_TMIN] = 
			TestParam(pname, fname, line, params[j++], 
				  PTYPE_REAL, 0.0, 100000.0);
		      
		      /* Copy to maximum */
		      
		      WDB[mat + MATERIAL_TMS_TMAX] = 
			RDB[mat + MATERIAL_TMS_TMIN];
		      
		      /* Set mode */
		      
		      WDB[DATA_TMS_MODE] = (double)TMS_MODE_CE;
		      WDB[mat + MATERIAL_TMS_MODE] = (double)YES;
		      
		      /*******************************************************/
		    }
		  else if (!strcmp(params[j], "rgb"))
		    {
		      /***** Material colour *********************************/

		      j++;
		      
		      /* Get r, b and g */
		      
		      r = TestParam(pname, fname, line, params[j++], 
				    PTYPE_INT, 0, 255);
		      
		      g = TestParam(pname, fname, line, params[j++], 
				    PTYPE_INT, 0, 255);

		      b = TestParam(pname, fname, line, params[j++], 
				    PTYPE_INT, 0, 255);

		      /* Set color */
		      
		      WDB[mat + MATERIAL_RGB] = b + 1000.0*g + 1000000.0*r;
		      
		      /*******************************************************/
		    }
		  else if (!strcmp(params[j], "vol"))
		    {
		      /***** Material volume *********************************/
		      
		      j++;
		      
		      /* Get volume */
		      
		      WDB[mat + MATERIAL_VOLUME_GIVEN] =
			TestParam(pname, fname, line, params[j++], PTYPE_REAL, 
				  0.0, INFTY);
		      
		      /*******************************************************/
		    }
		  else if (!strcmp(params[j], "fix"))
		    {
		      /***** Default library ID and temperature***************/

		      j++;
		  
		      /* Get default ID and temperature */
		      
		      WDB[mat + MATERIAL_DEFAULT_PTR_LIB_ID] = 
			PutText(params[j++]);
		      WDB[mat + MATERIAL_DEFAULT_TMP] = 
			TestParam(pname, fname, line, params[j++], PTYPE_REAL, 
				  0.0, INFTY);
		      
		      /*******************************************************/
		    }
		  else if (!strcmp(params[j], "mass"))
		    {
		      /***** Material mass ***********************************/

		      j++;
		      
		      /* Get mass */
		      
		      WDB[mat + MATERIAL_MASS_GIVEN] = 
			TestParam(pname, fname, line, params[j++], PTYPE_REAL, 
				  0.0, INFTY);

		      /*******************************************************/
		    }
		  else if (!strcmp(params[j], "burn"))
		    {
		      /***** Burnable material *******************************/
		      
		      j++;
		      
		      /* Set burn flag */
		      
		      SetOption(mat + MATERIAL_OPTIONS, OPT_BURN_MAT);
		      
		      /* Set burn sort flag and materials flag */
		      
		      WDB[mat + MATERIAL_BURN_SORT_FLAG] = 1.0;
		      WDB[DATA_BURN_MATERIALS_FLAG] = (double)YES;
		      
		      /* Get number of rings */
		      
		      WDB[mat + MATERIAL_BURN_RINGS] = 
			(double)TestParam(pname, fname, line, params[j++], 
					  PTYPE_INT, 0, 10000000);
		  
		      /*******************************************************/
		    }
		  else if (!strcmp(params[j], "moder"))
		    {
		      /***** Thermal scattering data *************************/

		      j++;
		      
		      /* Check number of parameters */
		      
		      if (j > np - 3)
			Error(mat, "Invalid number of parameters");
		      
		      /* Create new item (use the same structure as with */
		      /* the therm card) */
		      
		      WDB[mat + MATERIAL_PTR_SAB] = NULLPTR;
		      loc1 = NewItem(mat + MATERIAL_PTR_SAB, 
				     THERM_BLOCK_SIZE);

		      /* Read name */
		      
		      WDB[loc1 + THERM_PTR_ALIAS] = 
			(double)PutText(params[j++]);
		      
		      /* Read ZA */
		      
		      WDB[loc1 + THERM_ZA] =  
			(double)TestParam(pname, fname, line, params[j++], 
					  PTYPE_INT, 1001, 120000);
		      
		      /*******************************************************/
		    }
		  else if (!strcmp(params[j], "tft"))
		    {
		      /***** Minimum and maximum temperatures for TMS ********/

		      j++;
		      
		      /* Get minimum temperature */
		      
		      WDB[mat + MATERIAL_TMS_TMIN] = 
			TestParam(pname, fname, line, params[j++], 
				  PTYPE_REAL, 0.0, 100000.0);
		      
		      /* Get maximum temperature */
		      
		      WDB[mat + MATERIAL_TMS_TMAX] = 
			TestParam(pname, fname, line, params[j++], 
				  PTYPE_REAL, RDB[mat + MATERIAL_TMS_TMIN],
				  100000.0);
		      
		      /* Set mode */
		      
		      WDB[DATA_TMS_MODE] = (double)TMS_MODE_CE;
		      WDB[mat + MATERIAL_TMS_MODE] = (double)YES;
		      
		      /*******************************************************/
		    }
		  else 
		    {
		      /***** Composition *************************************/

		      /* Find nuclide in composition (start from previous) */

		      iso = iso0;
		      while (iso > VALID_PTR)
			{
			  /* Pointer to nuclide data */

			  nuc = (long)RDB[iso + COMPOSITION_PTR_NUCLIDE];
			  CheckPointer(FUNCTION_NAME, "(nuc)", DATA_ARRAY,nuc);

			  /* Compare */
			  
			  if (!strcmp(GetText(nuc + NUCLIDE_PTR_NAME),
				      params[j]))
			    break;

			  /* Next */

			  iso = NextItem(iso);
			}

		      /* Find nuclide in composition (start from beginning) */

		      if (iso < VALID_PTR)
			{			  
			  iso = (long)RDB[mat + MATERIAL_PTR_COMP];
			  while (iso > VALID_PTR)
			    {
			      /* Pointer to nuclide data */
			      
			      nuc = (long)RDB[iso + COMPOSITION_PTR_NUCLIDE];
			      CheckPointer(FUNCTION_NAME, "(nuc)", 
					   DATA_ARRAY,nuc);

			      /* Compare */
			  
			      if (!strcmp(GetText(nuc + NUCLIDE_PTR_NAME),
					  params[j]))
				break;
			      
			      /* Next */
			      
			      iso = NextItem(iso);
			    }
			}

		      /* Check pointer */
		      
		      if (iso < VALID_PTR)
			Error(-1, pname, fname, line, 
			      "Material %s has no nuclide %s in composition",
			      GetText(mat + MATERIAL_PTR_NAME), params[j]);
		      else
			j++;

		      /* Remember pointer */

		      iso0 = iso;
			      
		      /* Read fraction */
		  
		      val = TestParam(pname, fname, line, params[j++], 
				      PTYPE_REAL, -100.0, 1E+25);
		  
		      /* Put value */

		      WDB[iso + COMPOSITION_ADENS] = val;

		      /* Add to sum */
		      
		      sum = sum + val;
		      
		      /*******************************************************/
		    }
		}
	      
	      /* Set density if sum */

	      if (RDB[mat + MATERIAL_ADENS] == -INFTY)
		WDB[mat + MATERIAL_ADENS] = sum;

	      /* Calculate normalized fractions */
	      
	      IsotopeFractions(mat);
  	    }

	  /* Free parameter list */
      
	  if (np > 0)
	    for (n = 0; n < np + 1; n++)
	      Mem(MEM_FREE, params[n]);
	}

      /* Free memory */
  
      Mem(MEM_FREE, input);

      /* Next file */

      loc0++;
    }

  /* This must be called to get the divided compositions into material */
  /* structures */

  SumDivCompositions();
  
  fprintf(out, "OK.\n\n");
}
bool CEditTreeCtrl::DoInsertRoot(HTREEITEM hItem) {
	TRACE1(_T("CEditTreeCtrl::OnInsertRoot('%s')\n"), LPCTSTR(GetItemText(hItem)));
	TVINSERTSTRUCT ins;
	SetupInsertStruct(ins, TVI_ROOT);
	return NewItem(ins);
}
bool CEditTreeCtrl::DoInsertSibling(HTREEITEM hItem) {
	TRACE1(_T("CEditTreeCtrl::OnInsertSibling('%s')\n"), LPCTSTR(GetItemText(hItem)));
	TVINSERTSTRUCT ins;
	SetupInsertStruct(ins, GetParentItem(hItem));
	return NewItem(ins);
}
示例#25
0
//-----------------------------------------------------------------------------
TBaseItem* TFactoryGameItem::Add(Type type, std::string& name)
{
  TBaseItem* pItem = NewItem(type, name);
  return pItem;
}
示例#26
0
STDMETHODIMP C_Items::Retrieve(I_Archive * arc)
{
	if (!arc)
		return E_POINTER;

	C_STLException::install();

	//TODO - templatize this function and stick it in a base class.
	try {

		BSTR bs = NULL;
		unsigned int len = 0;

		if (S_OK != arc->RetrieveString(&bs)) {
			return E_FAIL;
		}

		String s(bs);
		s.toLower();
		String::FreeBSTR(&bs);

		static String tags[5] = {
			_T("mmp:item"),
			_T("mmp:text"),
			_T("mmp:node"),
			_T("mmp:picture"),
			_T("mmp:branch")
		};

		typedef enum ematches {
			plainitem,
			text,
			node,
			picture,
			branch
		};

		static String types[4] = {
			_T("node"),
			_T("text-block"),
			_T("picture"),
			_T("branch")
		};

		ematches match = plainitem;

		CLSID clsid;
		IID iid;

		StringPtr ptr(s.Find(tags[plainitem]));
		StringPtr ptrKill(s.Find(tags[plainitem]));

		for (unsigned int test = plainitem; test <= branch; test++) {

			ptr = s.Find(tags[test]);

			if (ptr.isValid()) {

				ptrKill = s.Find(String(_T("/")) + tags[test]);
				match = static_cast<ematches>(test);

				break;
			}
		}

		switch (match) {
		case node:
			clsid = CLSID_Node;
			iid = IID_I_Node;
			break;
		case text:
			clsid = CLSID_TextBlock;
			iid = IID_I_TextBlock;
			break;
		case picture:
			clsid = CLSID_Picture;
			iid = IID_I_Picture;
			break;
		case branch:
			clsid = CLSID_Branch;
			iid = IID_I_Branch;
			break;
		}

		while (ptr.isValid() && !ptrKill.isValid()) {//Check this is the start of an item...

			C_ItemPtr item;

			/////////////////////////////////////////////////////
			//	In a paste operation, the object's GUID must be ignored
			//	- a new object is being created with its own identity.
			BOOL b = FALSE;
			BOOL bPreserveID = TRUE;
			BSTR bs = NULL;

			arc->get_PreserveIdentities(&bPreserveID);

			if (bPreserveID) {

				/////////////////////////////////////////////////////
				//	Get the GUID to identify the object. Check if it 
				//	exists already - if so, divert the serialisation data
				//	to the existing object and add a reference to the 
				//	Children collection.
				String sUUID;

				StringPtr ptrUUID = s.Find(_T("uuid"));

				if (ptrUUID.isValid()) {

					StringPtr ptrLeft = s.Find(_T("\""), ptrUUID);
					ptrLeft++;

					if (ptrLeft.isValid()) {

						StringPtr ptrRight = s.Find(_T("\""), ptrLeft);

						if (ptrRight.isValid()) {
							sUUID = s.Mid(ptrLeft.Index(), ptrRight.Index() - ptrLeft.Index());
						}
						else {
							sUUID = s.Right(s.GetLength() - ptrLeft.Index());
						}

						T_SafeArray<char> buffer(sUUID.GetLength() + 1);

						::_stprintf(buffer[0], _T("%s\0"), sUUID.toLPCTSTR());

						GUID guid = String(buffer[0]).toGUID();

						map<GUID, I_MapItem*>::iterator it = m_S_Items.find(guid);

						if (it != m_S_Items.end()) {

							//The object with this GUID already exists in the item map
							item = (*it).second;

							_ASSERTE(item);

							if (item) {

								VARIANT v;

								C_UniquePtr unique(item);

								if (unique) {
									unique->get_UID(&bs);
								}

								VariantInit(&v);
								v.vt = VT_BSTR;
								v.bstrVal = bs;

								get_Exists(v, &b);

								if (!b) {

									//	Add the item to the collection
									Add(bs, item);
									b = TRUE;
								}
							}
						}
					}
				}
			}

			if (b) {

				if (bs) {
					String::FreeBSTR(&bs);
				}
			}
			else {

				if (match == plainitem) {

					int type = -1;

					StringPtr ptrType = s.Find(_T("type"));
					String sType;

					if (ptrType.isValid()) {

						StringPtr ptrLeft = s.Find(_T("\""), ptrType);

						if (ptrLeft.isValid()) {

							ptrLeft++;
							StringPtr ptrRight = s.Find(_T("\""), ptrLeft);

							if (ptrRight.isValid()) {
								sType = s.Mid(ptrLeft.Index(), ptrRight.Index() - ptrLeft.Index());
							}
							else {
								sType = s.Right(s.GetLength() - ptrLeft.Index());
							}

							for (int n = 0; n < 4; n++) {

								if (sType == types[n]) {

									type = n;

									switch (type) {
									case 0:
										clsid = CLSID_Node;
										iid = IID_I_Node;
										break;
									case 1:
										clsid = CLSID_TextBlock;
										iid = IID_I_TextBlock;
										break;
									case 2:
										clsid = CLSID_Picture;
										iid = IID_I_Picture;
										break;
									case 3:
										clsid = CLSID_Branch;
										iid = IID_I_Branch;
										break;
									}

									break;
								}
							}
						}
					}

					if (type < 0) {

						/////////////////////////////////////////////////////
						//	Get the CLSID and IID to identify the object's type
						String sCLSID;
						StringPtr ptrCLSID = s.Find(_T("clsid"));
						StringPtr ptrLeft = s.Find(_T("\""), ptrCLSID);
						ptrLeft++;
						StringPtr ptrRight = s.Find(_T("\""), ptrLeft);

						if (ptrRight.isValid()) {
							sCLSID = s.Mid(ptrLeft.Index(), ptrRight.Index() - ptrLeft.Index());
						}
						else {
							sCLSID = s.Right(s.GetLength() - ptrLeft.Index());
						}

						bs = sCLSID.toBSTR();
						CLSIDFromString(bs, &clsid);
						String::FreeBSTR(&bs);

						String sIID;
						StringPtr ptrIID = s.Find(_T("iid"));
						ptrLeft = s.Find(_T("\""), ptrIID);
						ptrLeft++;
						ptrRight = s.Find(_T("\""), ptrLeft);

						if (ptrRight.isValid()) {
							sIID = s.Mid(ptrLeft.Index(), ptrRight.Index() - ptrLeft.Index());
						}
						else {
							sIID = s.Right(s.GetLength() - ptrLeft.Index());
						}

						bs = sIID.toBSTR();
						IIDFromString(bs, &iid);
						String::FreeBSTR(&bs);
					}
				}

				//	TODO: Drop the string parameter
				item = NewItem(clsid, iid, String(_T("")));
			}

			if (item) {

				arc->Rollback();

				C_PersistentPtr persist(item);

				if (persist) {

					persist->Serialise(arc);

					C_DrawingStrategyPtr strategy(item);

					if (strategy) {
						strategy->putref_Parent(m_pParent);
					}

					BOOL bHasFocus = FALSE;

					item->get_HasFocus(&bHasFocus);

					if (bHasFocus) {

						I_ECBDiagram *map = NULL;

						if (m_pParent) {
							m_pParent->get_Map(&map);
						}

						if (map) {

							map->putref_CurrentSelection(item);
							map->Release();
						}
					}
				}
			}

			if (match == plainitem) {

				//	Discard closing tag
				if (S_OK != arc->RetrieveString(&bs)) {
					return E_FAIL;
				}

				s = bs;
				String::FreeBSTR(&bs);

				s = s.toLower();
				ptr = s.Find(tags[match]);
				ptrKill = s.Find(String(_T("/")) + tags[match]);
			}
			else {
				break;
			}
		}

		if (match == plainitem && !ptrKill.isValid()) {

			//...if it isn't, it doesn't belong here!
			arc->Rollback();
		}

		//	Sort the items as soon as they're retrieved
		Sort();
	}
	catch (C_STLNonStackException const &exception) {
		exception.Log(_T("Exception in C_Items::Retrieve"));
	}

	return S_OK;
}
示例#27
0
bool PSItems::LoadFile(char *FileName, PSTree *tree)
{
  HANDLE fp = CreateFile(FileName,GENERIC_READ,FILE_SHARE_READ,NULL,OPEN_EXISTING,0,NULL);
  char *buf;
  DWORD sz;
  if (fp!=INVALID_HANDLE_VALUE)
  {
    FILETIME ft;
    BOOL gottime = GetFileTime(fp,NULL,NULL,&ft);
    if (!gottime || FSF.LStricmp(LastFileName,FileName) || CompareFileTime(&ft,&LastFileTime)>0)
    {
      lstrcpy(LastFileName,FileName);
      if (gottime)
        LastFileTime = ft;
      else
        memset(&LastFileTime,0,sizeof(LastFileTime));
      if (!base)
      {
        sz = GetFileSize(fp,NULL);
        if (sz == INVALID_FILE_SIZE)
          sz = 0;
        buf = (char *)malloc(sz+1);
        if (buf)
        {
          DWORD transfered;
          if (sz)
          {
            ReadFile(fp,buf,sz,&transfered,NULL);
            sz = transfered;
          }
          buf[sz]=0;
        }
      }
      CloseHandle(fp);
    }
    else
    {
      CloseHandle(fp);
      return true;
    }
  }
  else
  {
    *LastFileName = 0;
    memset(&LastFileTime,0,sizeof(LastFileTime));
    if (!base)
    {
      sz = 0;
      buf = (char *)malloc(1);
      buf[0] = 0;
    }
  }

  #if 0
  {
    HANDLE fp = CreateFile("e:\\download\\temp\\alex.alex",GENERIC_WRITE,FILE_SHARE_READ,NULL,OPEN_ALWAYS,0,NULL);
    SetFilePointer(fp,0,NULL,FILE_END);
    DWORD t;
    WriteFile(fp,"read\r\n",6,&t,NULL);
    CloseHandle(fp);
  }
  #endif

  if (!buf && !base)
  {
    return false;
  }
  if (!base)
  {
    base = new CSgmlExt;
    if (!base)
    {
      free(buf);
      return false;
    }
    if (!base->parse(buf,sz))
    {
      delete base;
      free(buf);
      return false;
    }
    free(buf);
  }
  else
  {
    {
      PSItems temp;
      if (!temp.LoadFile(FileName,NULL))
      {
        delete base;
        return false;
      }
      struct EditorSetPosition esp;
      #ifdef ALLOW_VIEWER_API
      struct ViewerSetPosition vsp;
      #endif
      char str[_MAX_PATH];
      PSInfo info = {"editor",str,&esp};
      int type = TI_EDITOR;
      #ifdef ALLOW_VIEWER_API
      for (int i=0; i<2; i++)
      #endif
      {
        PSgmlExt Item = base->next();
        while (Item)
        {
          if (Item->getname() && !FSF.LStricmp(Item->getname(),"item") && Item->GetChrParam("type") && !FSF.LStricmp(Item->GetChrParam("type"),info.Type) && Item->GetChrParam("path"))
          {
            //GetItem(Item,info);
            lstrcpy(info.FileName,Item->GetChrParam("path"));
            if (!temp.FindItem(info))
            {
              if (tree)
              {
                PSTrackInfo ti;
                lstrcpy(ti.FileName,info.FileName);
                ti.Type = type;
                while (tree->GetFN(&ti))
                  tree->Delete(&ti);
              }
              Item = Item->prev();
              DelItem(info);
              #if 0
              {
                HANDLE fp = CreateFile("e:\\download\\temp\\alex.alex",GENERIC_WRITE,FILE_SHARE_READ,NULL,OPEN_ALWAYS,0,NULL);
                SetFilePointer(fp,0,NULL,FILE_END);
                DWORD t;
                WriteFile(fp,"del\r\n",5,&t,NULL);
                CloseHandle(fp);
              }
              #endif
            }
            else
            {
              PSTrackInfo ti;
              lstrcpy(ti.FileName,info.FileName);
              ti.Type = type;
              if (!tree || !tree->FindFN(&ti))
              {
                PSgmlExt tmp = temp.PFindItem(info);
                temp.GetItem(tmp,info);
                lstrcpy(info.FileName,tmp->GetChrParam("path"));
                SetItem(info);
              }
            }
          }
          Item = Item->next();
        }
        #ifdef ALLOW_VIEWER_API
        type = TI_VIEWER;
        info.Type = "viewer";
        info.vsp = &vsp;
        #endif
      }
      #ifdef ALLOW_VIEWER_API
      info.Type = "editor";
      for (int i=0; i<2; i++)
      #endif
      {
        PSgmlExt Item = temp.Base()->next();
        while (Item)
        {
          if (Item->getname() && !FSF.LStricmp(Item->getname(),"item") && Item->GetChrParam("type") && !FSF.LStricmp(Item->GetChrParam("type"),info.Type) && Item->GetChrParam("path"))
          {
            GetItem(Item,info);
            lstrcpy(info.FileName,Item->GetChrParam("path"));
            if (!FindItem(info))
            {
              NewItem(info);
            }
          }
          Item = Item->next();
        }
        #ifdef ALLOW_VIEWER_API
        info.Type = "viewer";
        info.vsp = &vsp;
        #endif
      }
    }
  }
  return true;
}
示例#28
0
void CFontExplorerApp::OnGetCFontDialogExplorer()                   // REQ #078
    {                                                               // REQ #078
     NewItem(FontDialogExplorerTemplate);                           // REQ #078
    } // CFontExplorerApp::OnGetCFontDialogExplorer                 // REQ #078
示例#29
0
long CreateUniverse(long loc0, char *name, long level)
{
  long loc1, loc2, lst, ptr, uni, cell, nst, reg, lat, pbd, umsh, stl, n;

  /* Check level count */

  if (level > MAX_GEOMETRY_LEVELS)
    Error(loc0, "Maximum number of geometry levels exceeded (infinite loop?)");

  /* Compare level to maximum */

  if (level + 1 > (long)RDB[DATA_GEOM_LEVELS])
    WDB[DATA_GEOM_LEVELS] = (double)(level + 1.0);

  /***************************************************************************/
 
  /***** Check if universe exists ********************************************/

  /* Loop over universes */

  uni = RDB[DATA_PTR_U0];
  while (uni > VALID_PTR)
    {
      /* Compare names */
      
      if (!strcmp(GetText(uni + UNIVERSE_PTR_NAME), name)) 
	return uni;
      
      /* Next universe */
      
      uni = NextItem(uni);
    }

  /* Create new universe */

  uni = NewItem(DATA_PTR_U0, UNIVERSE_BLOCK_SIZE);

  /* Put name */

  WDB[uni + UNIVERSE_PTR_NAME] = (double)PutText(name);

  /* Put level */
  
  WDB[uni + UNIVERSE_LEVEL] = (double)level;

  /* Reset pointers */

  WDB[uni + UNIVERSE_PTR_CELL_LIST] = NULLPTR;
  WDB[uni + UNIVERSE_PTR_NEST] = NULLPTR;
  WDB[uni + UNIVERSE_PTR_LAT] = NULLPTR;
  WDB[uni + UNIVERSE_PTR_PBED] = NULLPTR;
  WDB[uni + UNIVERSE_PTR_UMSH] = NULLPTR;
  WDB[uni + UNIVERSE_PTR_SYM] = NULLPTR;

  /* Allocate memory for collision counter */

  AllocValuePair(uni + UNIVERSE_COL_COUNT);

  /* Allocate memory for coordinates */

  ptr = AllocPrivateData(1, PRIVA_ARRAY);
  WDB[uni + UNIVERSE_PTR_PRIVA_X] = (double)ptr;

  ptr = AllocPrivateData(1, PRIVA_ARRAY);
  WDB[uni + UNIVERSE_PTR_PRIVA_Y] = (double)ptr;

  ptr = AllocPrivateData(1, PRIVA_ARRAY);
  WDB[uni + UNIVERSE_PTR_PRIVA_Z] = (double)ptr;

  /* Onko tän ajan pakko olla universe-rakenteessa? */

  ptr = AllocPrivateData(1, PRIVA_ARRAY);
  WDB[uni + UNIVERSE_PTR_PRIVA_T] = (double)ptr;

  /* Allocate memory for previous region */

  ptr = AllocPrivateData(1, PRIVA_ARRAY);
  WDB[uni + UNIVERSE_PTR_PREV_REG] = (double)ptr;

  /***************************************************************************/

  /***** Cells ***************************************************************/

  /* Loop over cells */

  cell = RDB[DATA_PTR_C0];
  while (cell > VALID_PTR)
    {

      /* Compare names and check used-flag */

      if (!((long)RDB[cell + CELL_OPTIONS] & OPT_USED))
	if (CompareStr(cell + CELL_PTR_UNI, uni + UNIVERSE_PTR_NAME))
	  {
	    /* Set used-flag */

	    SetOption(cell + CELL_OPTIONS, OPT_USED);

	    /* Put pointer */
	    
	    WDB[cell + CELL_PTR_UNI] = (double)uni;
	    
	    /* Create new item in universe cell list */
	    
	    lst = NewItem(uni + UNIVERSE_PTR_CELL_LIST, CELL_LIST_BLOCK_SIZE);
	    
	    /* Put pointer */
	    
	    WDB[lst + CELL_LIST_PTR_CELL] = (double)cell;

	    /* Allocate memory from private array */

	    ptr = AllocPrivateData(1, PRIVA_ARRAY);

	    /* Put pointer */
	    
	    WDB[lst + CELL_LIST_PTR_COUNT] = (double)ptr;

	    /* Check if fill pointer is set */
	    
	    if (RDB[cell + CELL_PTR_FILL] > VALID_PTR)
	      {
		/* Call recursively */
		
		sprintf(name, "%s", GetText(cell + CELL_PTR_FILL));
		loc1 = CreateUniverse(cell, name, level + 1);
		
		/* Put pointer */
		
		WDB[cell + CELL_PTR_FILL] = (double)loc1;
	      }
	    
	    /* Put universe type */
	    
	    WDB[uni + UNIVERSE_TYPE] = (double)UNIVERSE_TYPE_CELL;
	  }
      
      /* Next cell */
      
      cell = NextItem(cell);
    }

  /* Check if cells are defined */
  
  if ((ptr = (long)RDB[uni + UNIVERSE_PTR_CELL_LIST]) > 0)
    {
      /* Close list (NOTE: Tää oli processinput.c:ssä 8.11.2010 asti) */

      CloseList(ptr);

      /* Return pointer to universe */

      return uni;
    }

  /***************************************************************************/

  /***** Nests ***************************************************************/

  /* Loop over nests */

  nst = RDB[DATA_PTR_NST0];
  while (nst > VALID_PTR)
    {
      /* Compare names and check used-flag */
      
      if ((CompareStr(nst + NEST_PTR_NAME, uni + UNIVERSE_PTR_NAME)) &
	  !((long)RDB[nst + NEST_OPTIONS] & OPT_USED))
	{
	  /* Set used-flag */

	  SetOption(nst + NEST_OPTIONS, OPT_USED);

	  /* Put pointers */
	  
	  WDB[nst + NEST_PTR_UNI] = (double)uni;
	  WDB[uni + UNIVERSE_PTR_NEST] = (double)nst;

	  /* Get pointer to regions */
	      
	  reg = (long)RDB[nst + NEST_PTR_REGIONS];
	  CheckPointer(FUNCTION_NAME, "(reg)", DATA_ARRAY, reg);

	  /* Close list */

	  CloseList(reg);

	  /* Loop over regions */ 
	      
	  while (reg > VALID_PTR)
	    {
	      /* Check if fill pointer is set */

	      if (RDB[reg + NEST_REG_PTR_FILL] > VALID_PTR)
		{
		  /* Call recursively */

		  sprintf(name, "%s", GetText(reg + NEST_REG_PTR_FILL));
		  loc1 = CreateUniverse(nst, name, level + 1);

		  /* Put pointer */

		  WDB[reg + NEST_REG_PTR_FILL] = (double)loc1;
		}

	      /* Next region */

	      reg = NextItem(reg);
	    }

	  /* Put universe type */

	  WDB[uni + UNIVERSE_TYPE] = (double)UNIVERSE_TYPE_NEST;

	  /* Return pointer to universe */

	  return uni;
	}

      /* Next nest */

      nst = NextItem(nst);
    }

  /***************************************************************************/

  /***** Lattices ************************************************************/

  /* Loop over lattices */

  lat = RDB[DATA_PTR_L0];
  while (lat > VALID_PTR)
    {
      /* Compare names and check used-flag */

      if ((CompareStr(lat + LAT_PTR_NAME, uni + UNIVERSE_PTR_NAME)) &
	  !((long)RDB[lat + LAT_OPTIONS] & OPT_USED))
	{
	  /* Set used-flag */

	  SetOption(lat + LAT_OPTIONS, OPT_USED);

	  /* Put pointers */

	  WDB[lat + LAT_PTR_UNI] = (double)uni;
	  WDB[uni + UNIVERSE_PTR_LAT] = (double)lat;

	  /* Check type */

	  if ((long)RDB[lat + LAT_TYPE] == LAT_TYPE_CLU)
	    {
	      /***** Circular array ******************************************/
	      
	      /* Get pointer to rings */
	      
	      reg = (long)RDB[lat + LAT_PTR_FILL];
	      CheckPointer(FUNCTION_NAME, "(reg)", DATA_ARRAY, reg);

	      /* Loop over rings */ 
	      
	      while (reg > VALID_PTR)
		{
		  /* Loop over items */ 
		  
		  ptr = (long)RDB[reg + RING_PTR_FILL];
		  while ((long)RDB[ptr] > VALID_PTR)
		    {
		      /* Call recursively */
		      
		      sprintf(name, "%s", GetText(ptr));
		      loc1 = CreateUniverse(lat, name, level + 1);
		      
		      /* Put pointer */
		      
		      WDB[ptr++] = (double)loc1;
		    }

		  /* Next region */

		  reg = NextItem(reg);
		}

	      /***************************************************************/
	    }
	  else
	    {
	      /***** Simple types ********************************************/
	      
	      /* Loop over items */ 
	  
	      ptr = (long)RDB[lat + LAT_PTR_FILL];
	      while ((long)RDB[ptr] > VALID_PTR)
		{
		  /* Get universe  name */

		  sprintf(name, "%s", GetText(ptr));

		  /* Check if intentionally undefined (dots) */

		  for (n = 0; n < strlen(name); n++)
		    if (name[n] != '.')
		      break;
		  
		  /* Call recursively or put null pointer */
		  
		  if (n < strlen(name))
		    loc1 = CreateUniverse(lat, name, level + 1);
		  else
		    loc1 = NULLPTR;
		    
		  /* Put pointer */
		  
		  WDB[ptr++] = (double)loc1;
		}

	      /***************************************************************/
	    }

	  /* Put universe type */

	  WDB[uni + UNIVERSE_TYPE] = (double)UNIVERSE_TYPE_LATTICE;

	  /* Return pointer to universe */

	  return uni;
	}

      /* Next lattice */

      lat = NextItem(lat);
    }

  /***************************************************************************/

  /***** Pebble-bed geometries ***********************************************/

  /* Loop over geometries */

  pbd = RDB[DATA_PTR_PB0];
  while (pbd > VALID_PTR)
    {
      /* Compare names and check used-flag */
      
      if ((CompareStr(pbd + PBED_PTR_NAME, uni + UNIVERSE_PTR_NAME)) &
	  !((long)RDB[pbd + PBED_OPTIONS] & OPT_USED))
	{
	  /* Set used-flag */

	  SetOption(pbd + PBED_OPTIONS, OPT_USED);

	  /* Put pointers */

	  WDB[pbd + PBED_PTR_UNI] = (double)uni;
	  WDB[uni + UNIVERSE_PTR_PBED] = (double)pbd;

	  /* Call recursively for background universe */
	  
	  sprintf(name, "%s", GetText(pbd + PBED_PTR_BG_UNIV));
	  loc1 = CreateUniverse(pbd, name, level + 1);

	  /* Put pointer */

	  WDB[pbd + PBED_PTR_BG_UNIV] = (double)loc1;

	  /* Loop over pebbles */
	  
	  loc1 = (long)RDB[pbd + PBED_PTR_PEBBLES];
	  while (loc1 > VALID_PTR)
	    {
	      /* Call recursively for pebble */
	  
	      sprintf(name, "%s", GetText(loc1 + PEBBLE_PTR_UNIV));
	      ptr = CreateUniverse(pbd, name, level + 1);

	      /* Put pointer */

	      WDB[loc1 + PEBBLE_PTR_UNIV] = (double)ptr;

	      /* Loop over types */

	      loc2 = (long)RDB[pbd + PBED_PTR_PEBBLE_TYPES];
	      while(loc2 > VALID_PTR)
		{
		  /* Compare universe pointer */

		  if ((long)RDB[loc2 + PEBTYPE_PTR_UNIV] == ptr)
		    {
		      /* Add counter */

		      WDB[loc2 + PEBTYPE_COUNT] = 
			RDB[loc2 + PEBTYPE_COUNT] + 1.0;

		      /* Break loop */

		      break;
		    }

		  /* Next type */

		  loc2 = NextItem(loc2);
		}

	      /* Check pointer */

	      if (loc2 < VALID_PTR)
		{
		  /* No previous definition */

		  loc2 = NewItem(pbd + PBED_PTR_PEBBLE_TYPES, 
				 PEBTYPE_BLOCK_SIZE);

		  /* Put universe pointer */

		  WDB[loc2 + PEBTYPE_PTR_UNIV] = (double)ptr;

		  /* Init counter */

		  WDB[loc2 + PEBTYPE_COUNT] = 1.0;
		}

	      /* Next pebble */

	      loc1 = NextItem(loc1);
	    }

	  /* Put universe type */

	  WDB[uni + UNIVERSE_TYPE] = (double)UNIVERSE_TYPE_PBED;

	  /* Return pointer to universe */

	  return uni;
	}

      /* Next geometry */

      pbd = NextItem(pbd);
    }

  /***************************************************************************/

  /***** Unstructured mesh based geometries **********************************/

  /* Loop over geometries */

  umsh = RDB[DATA_PTR_UMSH0];
  while (umsh > VALID_PTR)
    {
      /* Compare names and check used-flag */
      
      if ((CompareStr(umsh + UMSH_PTR_NAME, uni + UNIVERSE_PTR_NAME)) &
	  !((long)RDB[umsh + UMSH_OPTIONS] & OPT_USED))
	{
	  /* Set used-flag */

	  SetOption(umsh + UMSH_OPTIONS, OPT_USED);

	  /* Put pointers */

	  WDB[umsh + UMSH_PTR_UNI] = (double)uni;
	  WDB[uni + UNIVERSE_PTR_UMSH] = (double)umsh;

	  /* Call recursively for background universe */
	  
	  sprintf(name, "%s", GetText(umsh + UMSH_PTR_BG_UNIV));
	  loc1 = CreateUniverse(umsh, name, level + 1);

	  /* Put pointer */

	  WDB[umsh + UMSH_PTR_BG_UNIV] = (double)loc1;

	  /* Put universe type */

	  WDB[uni + UNIVERSE_TYPE] = (double)UNIVERSE_TYPE_UMSH;

	  /* Allocate memory for next cell */

	  AllocValuePair(uni + UNIVERSE_PTR_NEXT_CELL);

	  /* Return pointer to universe */

	  return uni;
	}

      /* Next geometry */

      umsh = NextItem(umsh);
    }

  /***************************************************************************/

  /***** STL geometries ******************************************************/

  /* Loop over geometries */
 
  stl = RDB[DATA_PTR_STL0];
  while (stl > VALID_PTR)
    {
      /* Compare names and check used-flag */
      
      if ((CompareStr(stl + STL_PTR_NAME, uni + UNIVERSE_PTR_NAME)) &
	  !((long)RDB[stl + STL_OPTIONS] & OPT_USED))
	{
	  /* Set used-flag */

	  SetOption(stl + STL_OPTIONS, OPT_USED);

	  /* Put pointers */

	  WDB[stl + STL_PTR_UNI] = (double)uni;
	  WDB[uni + UNIVERSE_PTR_STL] = (double)stl;

	  /* Call recursively for background universe */
	  
	  sprintf(name, "%s", GetText(stl + STL_PTR_BG_UNIV));
	  loc1 = CreateUniverse(stl, name, level + 1);

	  /* Put pointer */

	  WDB[stl + STL_PTR_BG_UNIV] = (double)loc1;

	  /* Put universe type */

	  WDB[uni + UNIVERSE_TYPE] = (double)UNIVERSE_TYPE_STL;

	  /* Return pointer to universe */

	  return uni;
	}

      /* Next geometry */

      stl = NextItem(stl);
    }

  /***************************************************************************/

  /* Universe is not defined */
  
  if ((level == 0) && ((long)RDB[DATA_PTR_ROOT_UNIVERSE] < VALID_PTR))
    Error(loc0, "Root universe %s is not defined", name);
  else
    Error(loc0, "Universe %s is not defined", name);
  
  /* Avoid compiler warning */

  return NULLPTR;
}
示例#30
0
void BundlePane::OnMenuNew(wxCommandEvent& event) {
	const int menuId = event.GetId();

	switch (menuId) {
		case MENU_NEW_BUNDLE:
			{
				// Get name from user
				const wxString name = wxGetTextFromUser(_("Name of new item:"), _("New Item"), _("New Bundle"), this);
				if (name.empty()) return; // user cancel

				// Create a new  bundle item
				const unsigned int bundleId = m_plistHandler.NewBundle(name);
				m_plistHandler.SaveBundle(bundleId);

				// Add to tree
				const wxTreeItemId rootItem = m_bundleTree->GetRootItem();
				const wxTreeItemId bundleItem = m_bundleTree->AppendItem(rootItem, name, 0, -1, new BundleItemData(bundleId));
				const wxTreeItemId menuItem = m_bundleTree->AppendItem(bundleItem, _("Menu"), 6, -1, new BundleItemData(BUNDLE_MENU, bundleId));
				m_bundleTree->SortChildren(rootItem);
				m_bundleTree->SelectItem(bundleItem);
			}
			break;
		case MENU_NEW_COMMAND:
			NewItem(BUNDLE_COMMAND);
			break;
		case MENU_NEW_SNIPPET:
			NewItem(BUNDLE_SNIPPET);
			break;
		case MENU_NEW_DRAGCMD:
			NewItem(BUNDLE_DRAGCMD);
			break;
		case MENU_NEW_PREF:
			NewItem(BUNDLE_PREF);
			break;
		case MENU_NEW_LANGUAGE:
			NewItem(BUNDLE_LANGUAGE);
			break;
		case MENU_NEW_SEPARATOR:
			{
				const wxTreeItemId selItem = m_bundleTree->GetSelection();
				const BundleItemData* data = (BundleItemData*)m_bundleTree->GetItemData(selItem);

				PListDict infoDict = GetEditableMenuPlist(data->m_bundleId);
				InsertMenuItem(selItem, wxT("---- separator ----"), new BundleItemData(BUNDLE_SEPARATOR, data->m_bundleId), infoDict);
				m_plistHandler.SaveBundle(data->m_bundleId);

				// Update menu in editorFrame
				m_syntaxHandler.ReParseBundles(true/*onlyMenu*/);
			}
			break;
		case MENU_NEW_SUBMENU:
			{
				// Get name from user
				const wxString name = wxGetTextFromUser(_("Name of new item:"), _("New Item"), _("New SubMenu"), this);
				if (name.empty()) return; // user cancel

				const wxTreeItemId selItem = m_bundleTree->GetSelection();
				const BundleItemData* data = (BundleItemData*)m_bundleTree->GetItemData(selItem);
				
				// Get a new uuid
				const wxString newUuid = PListHandler::GetNewUuid();
				const wxCharBuffer uuidBuf = newUuid.ToUTF8();
				const char* uuid = uuidBuf.data();

				// Create the new group
				PListDict infoDict = GetEditableMenuPlist(data->m_bundleId);
				PListDict menuDict;
				if (!infoDict.GetDict("mainMenu", menuDict)) {
					wxFAIL_MSG(wxT("No mainMenu in info.plist"));
					return;
				}
				PListDict submenuDict = menuDict.NewDict("submenus");
				PListDict subDict = submenuDict.NewDict(uuid);
				subDict.NewArray("items");
				subDict.wxSetString("name", name);

				// Insert in menu
				InsertMenuItem(selItem, name, new BundleItemData(BUNDLE_SUBDIR, data->m_bundleId, newUuid), infoDict);
				m_plistHandler.SaveBundle(data->m_bundleId);

				// Update menu in editorFrame
				m_syntaxHandler.ReParseBundles(true/*onlyMenu*/);
			}
			break;
		default: wxASSERT(false);
	}
};