Ejemplo n.º 1
0
void SaveISISNexus::instrument() {
  NXmakegroup(handle, "instrument", "NXinstrument");
  NXopengroup(handle, "instrument", "NXinstrument");
  saveCharOpen("name", &m_isisRaw->i_inst, 8);
  putAttr("short_name", m_isisRaw->hdr.inst_abrv, 3);
  close();
  dae();
  detector_1();
  moderator();
  source();
  NXclosegroup(handle);
}
Ejemplo n.º 2
0
int main(int argc, char* argv[])
{
    
    //struct timeval currentTime;
    //ProtoSystemTime(currentTime);
    //srand(currentTime.tv_usec);
    
    
    TestTree testTree;
    
    int i = 0;
    for (i = i; i <= 20; i++)
    {
        TestItem* item = new TestItem((UINT32)rand());
        //TestItem* item = new TestItem((UINT32)i);
        if (!testTree.Insert(*item))
        {
            delete item;
            i--;
        }
    }
    
    TestItem* savedItem = NULL;
    TestItem* item;
    TestItem* pitem;
    TestTree::Iterator it(testTree, true);
    
    for (i = 1; i <= 10; i++)
    {
        pitem = it.PeekPrevItem();
        item = it.GetPrevItem();
        TRACE("item %d value %lu (pitem value %lu)\n", i, item->GetValue(), pitem->GetValue());
    }
    savedItem = item;
    for (i = 9; i >= 5; i--)
    {
        pitem = it.PeekNextItem();
        item = it.GetNextItem();
        TRACE("item %d value %lu (pitem value %lu)\n", i, item->GetValue(), pitem->GetValue());
    }
    for (i = 6; i <= 20; i++)
    {
        pitem = it.PeekPrevItem();
        item = it.GetPrevItem();
        TRACE("item %d value %lu (pitem value %lu)\n", i, item->GetValue(), pitem->GetValue());
    }
    
    
    TRACE("setting cursor to %lu\n", savedItem->GetValue());
    it.SetCursor(*savedItem);
            
    TestItem* prev = static_cast<TestItem*>(it.prev);
    TestItem* next = static_cast<TestItem*>(it.next);
    TestItem* curr = static_cast<TestItem*>(it.curr_hop);
    TRACE("iterator prev:%lu next:%lu curr:%lu\n",
            prev ? prev->GetValue() : 0, 
            next ? next->GetValue() : 0,
            curr ? curr->GetValue() : 0);
    
    
    TRACE("removing item %lu ...\n", savedItem->GetValue());
    testTree.Remove(*savedItem);
            
    prev = static_cast<TestItem*>(it.prev);
    next = static_cast<TestItem*>(it.next);
    curr = static_cast<TestItem*>(it.curr_hop);
    TRACE("iterator prev:%lu next:%lu curr:%lu\n",
            prev ? prev->GetValue() : 0, 
            next ? next->GetValue() : 0,
            curr ? curr->GetValue() : 0);
    
    
    /*
    it.GetNextItem();
    ProtoTree::Item* snext = it.prev;
    TRACE("\ngot one item\n");
    prev = static_cast<TestItem*>(it.prev);
    next = static_cast<TestItem*>(it.next);
    curr = static_cast<TestItem*>(it.curr_hop);
    TRACE("iterator prev:%lu next:%lu curr:%lu\n",
            prev ? prev->GetValue() : 0, 
            next ? next->GetValue() : 0,
            curr ? curr->GetValue() : 0);
    
    
    it.GetNextItem();
    TRACE("\ngot another item\n");
    prev = static_cast<TestItem*>(it.prev);
    next = static_cast<TestItem*>(it.next);
    curr = static_cast<TestItem*>(it.curr_hop);
    TRACE("iterator prev:%lu next:%lu curr:%lu\n",
            prev ? prev->GetValue() : 0, 
            next ? next->GetValue() : 0,
            curr ? curr->GetValue() : 0);
    
    //
    //it.prev = sprev;
    //it.next = snext;
    //it.reversed = true;
    //it.GetPrevItem();
    //it.reversed = true;
    it.GetPrevItem();
    
    //item = it.GetNextItem();
    
    //TRACE("next item = %lu\n", item->GetValue());
    TRACE("\nready to go ...\n");
    prev = static_cast<TestItem*>(it.prev);
    next = static_cast<TestItem*>(it.next);
    curr = static_cast<TestItem*>(it.curr_hop);
    TRACE("iterator prev:%lu next:%lu curr:%lu\n",
            prev ? prev->GetValue() : 0, 
            next ? next->GetValue() : 0,
            curr ? curr->GetValue() : 0);
    */
    for (i = 1; i <= 20; i++)
    {
        pitem = it.PeekPrevItem();
        item = it.GetPrevItem();
        if ((NULL == pitem) || (NULL == item)) break;
        TRACE("item %d value %lu (pitem value %lu)\n", i, item->GetValue(), pitem->GetValue());
    }
    TRACE("\n");
    
    i = 0;
    TestTree::SimpleIterator sit(testTree);
    while (NULL != (item = sit.GetNextItem()))
    {
        i++;
        //TRACE("stem %d value %lu\n", i, item->GetValue());
    }
    
    
    //return 0;
    
    
    // Instantiate our various queues
    ProductList productList;
    ProductNameQueue nameList;
    ProductModelQueue modelList;
    ProductCostQueue costList;
    
    TRACE("ProtoList::Item  size = %d bytes\n", sizeof(ProtoList::Item));
    TRACE("ProtoTree::Item  size = %d bytes\n", sizeof(ProtoTree::Item));
    TRACE("ProductList container size = %d bytes\n", sizeof(ProductList::Container));
    TRACE("ProductNameQueue container size = %d bytes\n", sizeof(ProductNameQueue::Container));
    TRACE("ProductCostQueue container size = %d bytes\n", sizeof(ProductCostQueue::Container));
    
    // Randomly generate some products
    for (int i = 0; i < 10 ; i++)
    {
        char name[9];
        for (int j = 0; j < 8; j++)
            name[j] = (rand() % 26) + 'a';
        name[8] = '\0';
        unsigned int model = (unsigned int)rand();
        double cost = 100.0 * ((double)rand()/(double) RAND_MAX);
        
        TRACE("creating product name:\"%s\" model:%u cost:%lf\n", name, model, cost);
        
        ProductRecord* product = new ProductRecord(name, model, cost);
        productList.Append(*product);
        nameList.Insert(*product);
        modelList.Insert(*product);
        ProductModelQueue::Iterator moderator(modelList);
        costList.Insert(*product);
    }
    
    ProductRecord* product;
    
    // Test iteration manipulation stuff
    ProductList::Iterator iterator(productList);
    product = productList.RemoveHead();
    if (NULL != product)
        TRACE("Removed head name:\"%s\" model:%u cost:%lf\n", 
                  product->GetName(), product->GetModel(), product->GetCost());
    while (NULL != (product = iterator.GetNextItem()))
    {
        TRACE("   name:\"%s\" model:%u cost:%lf\n", 
              product->GetName(), product->GetModel(), product->GetCost()); 
    } 
    product = productList.RemoveTail();
    if (NULL != product)
        TRACE("Removed tail name:\"%s\" model:%u cost:%lf\n", 
                  product->GetName(), product->GetModel(), product->GetCost()); 
    while (NULL != (product = iterator.GetPrevItem()))
    {
        TRACE("   name:\"%s\" model:%u cost:%lf\n", 
              product->GetName(), product->GetModel(), product->GetCost()); 
    } 
    //while (NULL != (product = iterator.GetNextItem()))
    //    delete product;
    
    //return 0;
    
    TRACE("\nProduct List Iteration:\n");   
    ProductList::Iterator listerator(productList);
    while (NULL != (product = listerator.GetNextItem()))
    {
        TRACE("   name:\"%s\" model:%u cost:%lf\n", 
              product->GetName(), product->GetModel(), product->GetCost()); 
    }  
    
    //nameList.Destroy();
    
    TRACE("\nProduct Name Iteration:\n");   
    ProductNameQueue::Iterator namerator(nameList);
    while (NULL != (product = namerator.GetNextItem()))
    {
        TRACE("   name:\"%s\" model:%u cost:%lf\n", 
              product->GetName(), product->GetModel(), product->GetCost()); 
    }  
    
    TRACE("\nProduct Model Iteration:\n");   
    ProductModelQueue::Iterator moderator(modelList);
    while (NULL != (product = moderator.GetNextItem()))
    {
        TRACE("   name:\"%s\" model:%u cost:%lf\n", 
              product->GetName(), product->GetModel(), product->GetCost()); 
    }
    
    TRACE("\nProduct Cost Iteration:\n");   
    ProductCostQueue::Iterator costerator(costList);
    while (NULL != (product = costerator.GetNextItem()))
    {
        TRACE("   name:\"%s\" model:%u cost:%lf\n", 
              product->GetName(), product->GetModel(), product->GetCost()); 
    }  
    
}  // end main()
Ejemplo n.º 3
0
QString AFormatter::normalizeBody (const QString& body, const QString& nick)
{
	QString data = body;

	// отбрасываем "[tagline]" и "[moderator]"
	QRegExp tagline("\\[tagline\\](.+)\\[/tagline\\]",       Qt::CaseInsensitive);
	QRegExp moderator("\\[moderator\\](.+)\\[/moderator\\]", Qt::CaseInsensitive);

	tagline.setMinimal(true);
	moderator.setMinimal(true);

	data.replace(tagline,   "");
	data.replace(moderator, "");

	// удаляем img с даными вместо ссылки (например, см. http://www.rsdn.ru/forum/flame.comp/4077971.1.aspx)
	QRegExp img1("\\[img\\]data:(\\S+)\\[/img\\]", Qt::CaseInsensitive);
	img1.setMinimal(true);
	data.replace(img1, "");

	// заменяем [img]...[/img] на ссылку
	QRegExp img2("\\[img\\](\\S+)\\[/img\\]", Qt::CaseInsensitive);
	img2.setMinimal(true);
	data.replace(img2, QString::fromUtf8("[url=\\1]\\1[/url]"));

	// укорачивание длинных ссылок (например, см. http://www.rsdn.ru/forum/web/4086359.1.aspx)
	QRegExp url1("\\[url=data:(\\S+)\\](.+)\\[/url\\]", Qt::CaseInsensitive);
	url1.setMinimal(true);
	data.replace(url1, "[url=bad%20link]\\2[/url]");

	// удаление тэга цитирования
	QRegExp q1("(^|[^\\[])\\[q\\]", Qt::CaseInsensitive);
	q1.setMinimal(true);
	data.replace(q1, "\\1");

	QRegExp q2("(^|[^\\[])\\[/q\\]", Qt::CaseInsensitive);
	q2.setMinimal(true);
	data.replace(q2, "\\1");

	// удаление таблиц из цитирования
	QRegExp table("(^|[^\\[])\\[t\\](.+)\\[/t\\]", Qt::CaseInsensitive);
	table.setMinimal(true);
	data.replace(table, "\\1");

	// удаление тэгов [h1]..[h6] из цитирования
	for (int i = 1; i < 7; i++)
	{
		QRegExp h1("(^|[^\\[])\\[h" + QString::number(i) + "\\]", Qt::CaseInsensitive);
		h1.setMinimal(true);
		data.replace(h1, "\\1");

		QRegExp h2("(^|[^\\[])\\[/h" + QString::number(i) + "\\]", Qt::CaseInsensitive);
		h2.setMinimal(true);
		data.replace(h2, "\\1");
	}

	data = data.trimmed();

	// разбиение
	QStringList source = data.split("\n");

	QString nick_3 = AFormatter::nick3(nick);

	// добавление квотинга к строкам
	for (int i = 0; i < source.size(); i++)
		if (source[i].trimmed().length())
			source[i] = nick_3 + "> " + source[i];

	// удаление дублирующихся пустых строк
	int index = 0;

	// регексп для приветствий в квотинге
	QRegExp hello(QString::fromUtf8(">\\s{0,}Здравствуйте,\\s.+,\\sВы писали:"));

	while (index < source.size() - 1)
	{
		if (source.at(index).trimmed().length() == 0 && source.at(index + 1).trimmed().length() == 0)
		{
			source.removeAt(index);
			continue;
		}
		else if (source.at(index).indexOf(hello) != -1)
		{
			source.removeAt(index);

			if (index > 0)
				index--;

			continue;
		}

		index++;
	}

	// вычисление уровня квотинга
	QList<int> quoting_level;

	int size = source.size();

	for (int i = 0; i < size; i++)
	{
		QString temp = source.at(i).trimmed();

		int level = 0;

		for (int j = 0; j < temp.length() - 3; j++)
		{
			if (temp[j] == ' ' && !(temp[j + 1] == '&' || temp[j + 2] == '&' || temp[j + 3] == '&'))
				break;
			else if (temp[j] == '&' && temp[j + 1] == 'g' && temp[j + 2] == 't' && temp[j + 3] == ';')
			{
				level++;
				j += 3;
			}
			else if (temp[j] == '&' && temp[j + 1] == 'l' && temp[j + 2] == 't' && temp[j + 3] == ';')
				break;
		}

		quoting_level.append(level);

		source[i] = temp;
	}

	// вставка пустых строк между разными уровнями квотинга
	for (int i = 0; i < size - 1; i++)
	{
		if (source[i].length() == 0)
			continue;

		if (quoting_level.at(i) != quoting_level.at(i + 1) && source[i + 1].length() /*&& (quoting_level.at(i) == 0 || quoting_level.at(i + 1) == 0)*/)
			source[i] = source[i] + "\r\n";
	}

	data = source.join("\r\n").trimmed();

	// замена HTML спец-символов
	data.replace("&gt;",  ">");
	data.replace("&lt;",  "<");
	data.replace("&amp;", "&");

	return data;
}