本文整理汇总了C++中NList类的典型用法代码示例。如果您正苦于以下问题:C++ NList类的具体用法?C++ NList怎么用?C++ NList使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了NList类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: main
int main(int argc, char *argv[]){
NAtom *value1 = NAtom::get("value1");
NAtom *value2 = NAtom::get("value2");
NList list;
NObject *ptr = &list;
assert(ptr->equals(ptr));
assert(ptr->equals(&list));
assert(list.equals(&list));
assert(list.equals(ptr));
list << value1;
list << value2;
assert(list.size() == 2);
assert(list.popLast() == value2);
assert(list.popLast() == value1);
assert(list.size() == 0);
list.shift(value2);
list.shift(value1);
assert(list.size() == 2);
assert(list.popFirst() == value1);
assert(list.popFirst() == value2);
assert(list.size() == 0);
return 0;
}
示例2: setModules
bool NProj::setModules(const NOpt<NProj> &opts) {
NString tmp;
NList<NString> validModules;
validModules.append("NBase");
validModules.append("NEvents");
validModules.append("NNetwork");
validModules.append("NSecurity");
validModules.append("NXml");
validModules.append("NDBal");
validModules.append("NMySQL");
tmp = opts.getValues().at(0);
addOpt(&m_modules, tmp);
for (nuint64 i = 0; i < m_modules.size(); i++) {
if (!validModules.contains(m_modules.at(i))) {
NString msg;
msg = msg + "Module " + m_modules.at(i) + " is not a "
"valid module";
throw NException(msg, NException::TOOLS);
}
}
return true;
}
示例3:
NList<NString> NHostAddress::aliases(void) {
NList<NString> ret;
NString tmp;
while (*m_host.h_aliases) {
tmp = *m_host.h_aliases;
ret.append(tmp);
m_host.h_aliases++;
}
return ret;
}
示例4: LoadTasks
//
// Load
//
// Load a list of tasks
//
void LoadTasks(GameObj *subject, FScope *fScope, NList<Task> &tasks)
{
// Iterate the scope
FScope *sScope;
while ((sScope = fScope->NextFunction()) != NULL)
{
switch (sScope->NameCrc())
{
case 0x40B71B7D: // "Task"
tasks.Append(LoadTask(subject, sScope));
break;
}
}
}
示例5: SaveTasks
//
// Save
//
// Save a list of tasks
//
void SaveTasks(FScope *fScope, const char *name, const NList<Task> &tasks)
{
// Save nothing if no tasks in list
if (tasks.GetCount())
{
// Write the name given
fScope = fScope->AddFunction(name);
// For each task in the list
for (NList<Task>::Iterator t(&tasks); *t; t++)
{
SaveTask(fScope, "Task", **t);
}
}
}
示例6:
/*
~IsRecordTypeList~ checks if the given type list is a record type list.
This is needed in several places like ~In~, ~Out~, ~Save~, ~Open~....
Three type lists a common nowadays:
1 (72 0)
2 ((72 0))
3 ((72 0) ...)
With this information a crosscheck is done with the Secondo catalogue.
*/
bool
Record::IsRecordTypeList(ListExpr typeInfo)
{
bool isRecord = false;
NList list = typeInfo;
#ifdef RECORD_DEBUG
cerr << "Record::IsRecordTypeList(" << nl->ToString(typeInfo) << ")" << endl;
#endif
// check type info list expression, it has to be
// "(72 0)"
// or "((72 0))"
// or "((72 0) ...)"
if (list.length() >= 1) {
// extact the algebra and type id from the given list
int listAlgebraId;
int listTypeId;
if (list.first().isAtom()) {
// case: "(72 0)"
listAlgebraId = list.first().intval();
listTypeId = list.second().intval();
} else {
// case: "((72 0))" or "((72 0) ...)"
listAlgebraId = list.first().first().intval();
listTypeId = list.first().second().intval();
}
// retrieve record ids from secondo cataloge
int scAlgebraId;
int scTypeId;
SecondoCatalog* sc = SecondoSystem::GetCatalog();
sc->GetTypeId(Record::BasicType(), scAlgebraId, scTypeId);
// compare the list ids with secondo record ids
if (listAlgebraId == scAlgebraId && listTypeId == scTypeId) {
isRecord = true;
}
}
return isRecord;
}
示例7: Request
//
// Request
//
// Request sound effect data from the cache
//
Item * Request(Record *record)
{
ASSERT(Initialized());
ASSERT(record);
ASSERT(record->valid);
ASSERT(record->fastFind);
// Is this effect too large for the cache
if (record->fastFind->Size() > maxCacheSize)
{
LOG_WARN(("File '%s' is too large for the cache", record->Name()));
record->valid = FALSE;
return (NULL);
}
// Record if first time being played
if (!record->freq)
{
actuallyUsed++;
}
// Increment the frequency of this effect
record->freq++;
// Step through each cache item
for (NList<Item>::Iterator i(&items); *i; i++)
{
// Is this the one we're after
if ((*i)->record == record)
{
cacheHits++;
return (*i);
}
}
// Record a cache miss
cacheMisses++;
// Make space for this new effect (will also shrink cache if max size decreased)
while (items.GetCount() && (maxCacheSize - curCacheSize < record->fastFind->Size()))
{
// Try and remove a sound effect out of the cache
if (!FlushItem())
{
// Unable to remove any effects
return (NULL);
}
}
ASSERT(maxCacheSize - curCacheSize >= record->fastFind->Size());
// Open the file
FileSys::DataFile *dFile = FileSys::Open(record->fastFind);
// Should be found since already checked
if (!dFile)
{
LOG_WARN(("File '%s' has vanished!", record->Name()));
record->valid = FALSE;
return (NULL);
}
// Let's just be extra careful, someone might swap data files on a server
if (dFile->Size() != record->fastFind->Size())
{
LOG_WARN(("File '%s' has changed size!", record->Name()));
record->valid = FALSE;
return (NULL);
}
// Allocate memory for file data
void *data = AIL_mem_alloc_lock(record->fastFind->Size());
if (!data)
{
return (NULL);
}
// Read the data from disk
if (dFile->Read(data, record->fastFind->Size()) != record->fastFind->Size())
{
// Free the memory we just allocated
AIL_mem_free_lock(data);
// Close the file
FileSys::Close(dFile);
// We won't try this one again
record->valid = FALSE;
LOG_WARN(("Error reading effect '%s' into cache", record->Name()));
return (NULL);
}
// Close the file
//.........这里部分代码省略.........
示例8:
int
SimpleNbmtr::fetch_neighbor_list(NList &nb_list)
{
nb_list.assign(nl.begin(), nl.end());
return nb_list.size();
}
示例9: Item
namespace SidePlacement
{
///////////////////////////////////////////////////////////////////////////////
//
// Struct Item - Data for the placement of a single generic unit type
//
struct Item
{
// List node
NList<Item>::Node node;
// Type to place
GameIdent type;
// Position data
F32 direction, distance, orientation;
// Constructor
Item(const char *type, F32 direction, F32 distance, F32 orientation) :
type(type),
direction(direction),
distance(distance),
orientation(orientation)
{
}
};
///////////////////////////////////////////////////////////////////////////////
//
// System Functions
//
// Is the system initialized
static Bool initialized = FALSE;
// The name of the config file
static const char *configName = "placement.cfg";
// The list of items
static NList<Item> items(&Item::node);
//
// Init
//
// Initialize system
//
void Init()
{
ASSERT(!initialized)
ASSERT(!items.GetCount())
PTree pTree;
// Process the configuration
if (pTree.AddFile(configName))
{
FScope *fScope = pTree.GetGlobalScope();
FScope *sScope;
while ((sScope = fScope->NextFunction()) != NULL)
{
switch (sScope->NameCrc())
{
case 0x64FFFFD7: // "Place"
{
// Load the data
const char *type = StdLoad::TypeString(sScope);
F32 direction = StdLoad::TypeCompassAngle(sScope);
F32 distance = StdLoad::TypeF32(sScope);
F32 orientation = StdLoad::TypeCompassAngle(sScope);
// Create the item
items.Append(new Item(type, direction, distance, orientation));
break;
}
}
}
}
// System now initialized
initialized = TRUE;
}
//
// Done
//
// Shutdown system
//
void Done()
{
ASSERT(initialized)
// Delete all items
items.DisposeAll();
//.........这里部分代码省略.........
示例10: values
//.........这里部分代码省略.........
#endif
cmsg.inFunError("Record::In: Value list is of kind atom but "
"a list is expected! ");
return w;
}
// case 2
if (nl->ListLength(instance) != nl->ListLength(nl->Rest(typeInfo))) {
#ifdef RECORD_DEBUG
cerr << "Record::In: different number of elements in "
"type list and value list " << endl;
#endif
cmsg.inFunError("Record::In: different number of elements in "
"type list and Value list ");
return w;
}
}
// create type and value list iteratoren
ListIterator typeIter = nl->Rest(typeInfo);
ListIterator valueIter = instance;
// variables used inside the iteration loop
string elemName;
string elemTypeName;
int elemAlgebraId;
int elemTypeId;
Word elemWord;
Attribute* elem;
// iterate synchrone through the type and value list elements
while(typeIter.HasNext() && valueIter.HasNext()) {
// assign the current type list element
NList curType = typeIter.NextNList();
// assign the current value list element
ListExpr curValue;
if (hasValueList) {
curValue = valueIter.NextListExpr();
} else {
curValue = nl->OneElemList(nl->SymbolAtom(nullSymbol));
}
#ifdef RECORD_DEBUG
cerr << "Record::In: curType=" << curType.convertToString() << endl;
cerr << "Record::In: curValue=" << nl->ToString(curValue) << endl;
#endif
// the current type list has to contain 2 elements
// case 1: (string (int int))
// 1. element name
// 2. element type list with two integer values
// 2.1 algebraId
// 2.2 typeId
// case 2: (string ((int int) ...))
// 1. element name
// 2. element type as list, first list item contains
// two integer values
if ( !( curType.length() == 2
&& curType.second().length() == 2
&& curType.second().first().isInt()
&& curType.second().second().isInt())
&& !( curType.length() == 2
&& curType.second().length() > 0
&& curType.second().first().length() == 2
&& curType.second().first().first().isInt()
示例11: CoreGameBabel
//.........这里部分代码省略.........
break;
case 0x88AD3389: // "Trap"
newType = new TrapObjType(name, fScope);
break;
case 0x93515F2D: // "Wall"
newType = new WallObjType(name, fScope);
break;
case 0xDC7624D3: // "Parasite"
newType = new ParasiteObjType(name, fScope);
break;
case 0xB1A0801B: // "Marker"
newType = new MarkerObjType(name, fScope);
break;
}
return (newType);
}
// Is system initialized
static Bool sysInit = FALSE;
// Used for callback registration
struct BabelData
{
// The babel function
BabelCallBack *callBack;
// NList node
NList<BabelData>::Node node;
};
// List of all registered babels
static NList<BabelData> babels(&BabelData::node);
//
// RegisterBabel
//
// Register a babel callback
//
void RegisterBabel(BabelCallBack *callBack)
{
ASSERT(sysInit);
// Create new babel data
BabelData *babel = new BabelData;
// Set the callback
babel->callBack = callBack;
// Add to the list
babels.Prepend(babel);
}
//
// NewGameObjectType
//
// Returns a new object type instance, or NULL if the class id is not recognized
//
GameObjType* NewGameObjType(GameIdent &classId, const char *name, FScope *fScope)
{
示例12:
NLocalisationList::NLocalisationList(const NList<NLocalisationEntry *> & entries)
{
m_Entries = new NList<NLocalisationEntry *>();
for (nlong i = 0; i < entries.getSize(); i++)
m_Entries->add(entries.get(i));
}
示例13: NUserData
NUserDataList::NUserDataList(const NList<NUserData *> & users)
{
m_Users = new NList<NUserData *>();
for (nlong i = 0; i < users.getSize(); i++)
m_Users->add(new NUserData(*users.get(i)));
}
示例14: record
//
// Constructor
//
Item::Item(Record *record, void *data) : record(record), data(data)
{
items.Append(this);
// Update cache size
curCacheSize += record->fastFind->Size();
}
示例15: ASSERT
//
// Destructor
//
Item::~Item()
{
ASSERT(curCacheSize - record->fastFind->Size() >= 0);
curCacheSize -= record->fastFind->Size();
items.Unlink(this);
AIL_mem_free_lock(data);
}