当前位置: 首页>>代码示例>>C++>>正文


C++ NList::first方法代码示例

本文整理汇总了C++中NList::first方法的典型用法代码示例。如果您正苦于以下问题:C++ NList::first方法的具体用法?C++ NList::first怎么用?C++ NList::first使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在NList的用法示例。


在下文中一共展示了NList::first方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1:

/*
~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;
}
开发者ID:awarematics,项目名称:SECONDO,代码行数:59,代码来源:Record.cpp

示例2: values

/*
~In~ function to create a record instance through a nested list.

According to the assigned type and value list the record is created.
Before that the lists are checked regarding there correctness in
the following order:

  1 check whether the given type list is a record type list at all

  2 check if in case of a non empty value list the two lists
  have the same number of elements.

  3 If the value list is empty an empty record with only the given
  element types is created

In all other cases an appropriate error message is populated and
the creation aborts.

After preliminary research both lists will be run through parallel
in order to create the single elements. To simplify the parallel
run through a list iterator ~ListIterator~ class has been created.
More information about the iterator can be found in ~ListIterator.h~
document.

At the run through the following cases have to be differentiated:

First of all the current type list has to contain 2 elements. Example:

  * case 1: (string (int int))

    1 element name

    1 element type list, with two integer values

      1.1 algebraId

      1.2 typeId

or

  * case 2: (string ((int int) ...))

    2 element name

    2 element type as list, first list item contains
    two integer values (see above)

The first possibility reflects a simple Secondo type whereas the second
illustrates a complex type likewise a ~record~.

The element name has to start with a capital letter.

The list elements have to conform these guidelines otherwise an error is
detected.

Once the list item is correct the new element is created. Therefore the
belonging algebraId and typeId is read out from the
Secondo catalogue.

Elements that are marked with NULL are created as well but are ~undefined~.

After the successful element creation this element is appended to the
record by AppendElement method.

The whole procedure is repeated as long as element information is
available in the given ~typeInfo~ list.

*/
Word
Record::In(const ListExpr typeInfo, const ListExpr instance,
           const int errorPos, ListExpr& errorInfo, bool& correct)
{
#ifdef RECORD_DEBUG
  cerr << "Record::In(" << nl->ToString(typeInfo) << ", "
       << nl->ToString(instance) << ", ..., ..., " << correct << ")" << endl;
#endif

  Word w = SetWord(Address(0));
  correct = false;
  const string nullSymbol = "NULL";

  if (Record::IsRecordTypeList(typeInfo)) {
    // create an empty record instance
    Record* record = new Record(0);

    bool hasValueList;

    if(listutils::isSymbolUndefined(instance)){ // an undefined record:
      record->SetDefined(false);
      correct = true;
      return w;
    }
    // in case of a not empty value list:
    // case 1: value list has to be a list
    // case 2: type list and value list have to be of the same length
    if (nl->ListLength(instance) == 0) {
      hasValueList = false;
    } else {
      hasValueList = true;

//.........这里部分代码省略.........
开发者ID:awarematics,项目名称:SECONDO,代码行数:101,代码来源:Record.cpp


注:本文中的NList::first方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。