int AsciiTableCommand :: Execute( ALib::CommandLine & cmd ) { GetSkipOptions( cmd ); ProcessFlags( cmd ); IOManager io( cmd ); CSVRow row; while( io.ReadCSV( row ) ) { if ( ! Skip( row ) ) { AddRow( row ); } } OutputTable( io.Out() ); return 0; }
void GenerateItemTable (CUniverse &Universe, CXMLElement *pCmdLine) { // Create the context SItemTableCtx Ctx; Ctx.pUniverse = &Universe; Ctx.pCmdLine = pCmdLine; // Compute the criteria TArray<CItemType *> Selection; SelectByCriteria(Ctx, pCmdLine->GetAttribute(CRITERIA_ATTRIB), &Selection); if (Selection.GetCount() == 0) { printf("No entries match criteria.\n"); return; } // Compute columns if (!CalcColumns(Ctx, pCmdLine)) return; // Sort the list SItemTypeList ItemList; SortTable(Ctx, Selection, &ItemList); // If by attribute, output categorized list if (pCmdLine->GetAttributeBool(BY_ATTRIBUTE_ATTRIB)) OutputByAttribute(Ctx, ItemList); else if (pCmdLine->GetAttributeBool(BY_SHIP_CLASS_ATTRIB)) OutputByShipClass(Ctx, ItemList, false); else if (pCmdLine->GetAttributeBool(BY_SHIP_CLASS_USAGE_ATTRIB)) OutputByShipClass(Ctx, ItemList, true); // Otherwise, just output a full table else { OutputHeader(Ctx); OutputTable(Ctx, ItemList); } printf("\n"); }
void OutputByShipClass (SItemTableCtx &Ctx, const SItemTypeList &ItemList, bool bShowUsage) { int i, j; // Make a map of ship classes for each item TSortMap<DWORD, TArray<CShipClass *>> ItemToShipClass; for (i = 0; i < g_pUniverse->GetShipClassCount(); i++) { CShipClass *pClass = g_pUniverse->GetShipClass(i); // Skip non-generic ones if (!pClass->HasLiteralAttribute(CONSTLIT("genericClass"))) continue; // Add the list of types used by the ship TSortMap<DWORD, bool> TypesUsed; pClass->AddTypesUsed(&TypesUsed); // For each item type, add it to the map for (j = 0; j < TypesUsed.GetCount(); j++) { CDesignType *pType = g_pUniverse->FindDesignType(TypesUsed.GetKey(j)); if (pType && pType->GetType() == designItemType) { TArray<CShipClass *> *pList = ItemToShipClass.SetAt(pType->GetUNID()); pList->Insert(pClass); } } } // If we want to show usage, then we print each item along with the // ship classes using each item. if (bShowUsage) { for (i = 0; i < ItemList.GetCount(); i++) { CItemType *pType = ItemList[i]; printf("%s\n", (LPSTR)pType->GetNounPhrase()); TArray<CShipClass *> *pList = ItemToShipClass.SetAt(pType->GetUNID()); for (j = 0; j < pList->GetCount(); j++) printf("\t%s\n", (LPSTR)pList->GetAt(j)->GetName()); if (pList->GetCount() == 0) printf("\t(none)\n"); printf("\n"); } } // Otherwise we categorize by ship class else { // Now make a list of all ship classes that have our items SByShipClassTypeList ByShipClassTable; for (i = 0; i < ItemList.GetCount(); i++) { const CString &sKey = ItemList.GetKey(i); CItemType *pType = ItemList[i]; // Loop over all ship classes TArray<CShipClass *> *pList = ItemToShipClass.SetAt(pType->GetUNID()); for (j = 0; j < pList->GetCount(); j++) { CString sClassName = pList->GetAt(j)->GetName(); bool bNew; SShipClassEntry *pEntry = ByShipClassTable.SetAt(sClassName, &bNew); if (bNew) pEntry->sShipClassName = sClassName; pEntry->ItemTable.Insert(sKey, pType); } // If no ship class if (pList->GetCount() == 0) { bool bNew; SShipClassEntry *pEntry = ByShipClassTable.SetAt(CONSTLIT("(none)"), &bNew); if (bNew) pEntry->sShipClassName = CONSTLIT("(none)"); pEntry->ItemTable.Insert(sKey, pType); } } // Now loop over all attributes for (i = 0; i < ByShipClassTable.GetCount(); i++) { const SShipClassEntry &Entry = ByShipClassTable[i]; printf("%s\n\n", Entry.sShipClassName.GetASCIIZPointer()); OutputHeader(Ctx); OutputTable(Ctx, Entry.ItemTable); printf("\n"); } } }
void Depth_Class::WriteOutput() { if(StepNum<1){return;} DepthOut.open(OutputFile,ios::out); DepthOut<<"///////////////Nuclide Density Table///////////////"<<'\n'; OutputTable(StepNt); if(RadioactivityFlag>0) { if(RadioactivityFlag==1) { DepthOut<<"///////////////Instantaneous Radioactivity(Curies) Table///////////////"<<'\n'; } else if(RadioactivityFlag==2) { DepthOut<<"///////////////Integral Radioactivity(Curies)Table///////////////"<<'\n'; } OutputTable(Radioactivity); } if(AbsRateFlag>0) { if(AbsRateFlag==1) { DepthOut<<"///////////////Instantaneous Absorption Rate(Neutrons/Sec) Table///////////////"<<'\n'; } else if(AbsRateFlag==2) { DepthOut<<"///////////////Integral Absorption Rate(Neutrons/Sec) Table///////////////"<<'\n'; } OutputTable(AbsorpRate); } if(FissionRateFlag>0) { if(FissionRateFlag==1) { DepthOut<<"///////////////Instantaneous Fission Rate(Fissions/Sec) Table///////////////"<<'\n'; } else if(FissionRateFlag==2) { DepthOut<<"///////////////Integral Fission Rate(Fissions/Sec) Table///////////////"<<'\n'; } OutputTable(FissionRate); } if(DecayHeatFlag>0) { if(DecayHeatFlag==1) { DepthOut<<"///////////////Instantaneous Decay Heat(Watts) Table///////////////"<<'\n'; } else if(DecayHeatFlag==2) { DepthOut<<"///////////////Integral Decay Heat(Watts) Table///////////////"<<'\n'; } OutputTable(DecayHeat); } DepthOut.close(); }