Example #1
0
void ImageInfo::Assign(const pvdInfoImage2& InfoImage)
{
	bPageInfoLoaded = false;

	// Инициализируется только в pvdInfoPage2
	lWidth = 0;
	lHeight = 0;
	nBPP = 0;

	// Инициализация количества страниц
	nPage = 0;
	nPages = InfoImage.nPages;
	Animation = InfoImage.Flags & PVD_IIF_ANIMATED/* 1 */;

	// Если есть формат/сжатие/комментарий - запомним
	if (InfoImage.pFormatName)
		lstrcpyn(FormatName, InfoImage.pFormatName, sizeofarray(FormatName));
	else
		*FormatName = 0;

	if (InfoImage.pCompression)
		lstrcpyn(Compression, InfoImage.pCompression, sizeofarray(Compression));
	else
		*Compression = 0;

	if (InfoImage.pComments)
		lstrcpyn(Comments, InfoImage.pComments, sizeofarray(Comments));
	else
		*Comments = 0;
		
	// Сброс остальных полей
	*Comments = 0;
}
Example #2
0
File: schur2.cpp Project: pzinn/M2
engine_RawArrayPairOrNull SchurRing2::list_form(const Ring *coeffR, const ring_elem f) const
{
  if (coeffR != coefficientRing)
    {
      ERROR("expected coefficient ring of Schur ring");
      return 0;
    }
  const schur_poly *f1 = f.schur_poly_val;
  int n = static_cast<int>(f1->size()); // this is here because the lengths of arrays for M3 front end use int as length field.
  engine_RawMonomialArray monoms = GETMEM(engine_RawMonomialArray, sizeofarray(monoms,n));
  engine_RawRingElementArray coeffs = GETMEM(engine_RawRingElementArray, sizeofarray(coeffs,n));
  monoms->len = n;
  coeffs->len = n;
  engine_RawArrayPair result = newitem(struct engine_RawArrayPair_struct);
  result->monoms = monoms;
  result->coeffs = coeffs;

  // Loop through the terms
  intarray vp;
  schur_poly::iterator i = f1->begin();
  for (int next=0; next<n; ++i, ++next)
    {
      coeffs->array[next] = RingElement::make_raw(coefficientRing, i.getCoefficient());
      toVarpower(i.getMonomial(), vp);
      monoms->array[next] = Monomial::make(vp.raw());
      vp.shrink(0);
    }
  return result;
}
Example #3
0
int TradingPeriod::Now(Time now, Time *remaining, Time delayed) { 
    int ret = NONE, wall_st_hours_from_gmt, hours_to_wall_st = WallStHoursFromLocal(&wall_st_hours_from_gmt);
    Time days_away = Time(0);
    struct tm t;

    for (;; days_away += Hours(24)) {

        // Find next trading day
        for (;; days_away += Hours(24)) {
            WallStTime(now + days_away, &t, hours_to_wall_st);
            bool week_day = t.tm_wday >= 1 && t.tm_wday <= 5;
            if (week_day && !TradingHoliday(t.tm_year+1900, t.tm_mon+1, t.tm_mday)) break;
        }
        if (days_away != Time(0)) days_away -= SinceDayBegan(now + days_away, wall_st_hours_from_gmt);
        Time trading_day_elapsed = SinceDayBegan(now + days_away, wall_st_hours_from_gmt);

        // Find next trading period
        static int  trading_period_id  [] = { NONE,     PRE_MARKET,           MARKET,    AFTER_MARKET };
        static Time trading_period_time[] = { Hours(4), Hours(9)+Minutes(30), Hours(16), Hours(20),   };
        for (int i=0, l=sizeofarray(trading_period_id); i<l; i++) 
            if (trading_day_elapsed < (trading_period_time[i] + delayed)) {
                if (remaining) *remaining = (trading_period_time[i] + delayed - trading_day_elapsed) + days_away;
                return trading_period_id[i];
            }
    }
}
Example #4
0
M2_arrayint M2_makearrayint(int n)
{
  M2_arrayint z = (M2_arrayint)getmem_atomic(sizeofarray(z,n));
  z->len = n;
  //GC_CHECK_CLOBBER(z);
  return z; /* Note that getmem_atomic returns zeroed memory */
}
Example #5
0
bool TradingHoliday(int month, int day, int year) {
    if (year == 2013) {
        static int holidays[][2] = { { 1, 1 }, { 1, 21 }, { 2, 18 }, { 3, 28 }, { 3, 29 }, { 5, 24 }, { 5, 27 }, { 7, 3 }, { 7, 4 }, { 9, 2 }, { 10, 14 }, { 11, 11 }, { 11, 28 }, { 11, 29 }, { 12, 24 }, { 12, 25 }, { 12, 31 } };
        for (int i=0, l=sizeofarray(holidays); i<l; i++) if (holidays[i][0] == month && holidays[i][1] == year) return true;
    }
    return false;
}
Example #6
0
void ImageInfo::Assign(const pvdInfoPage2& InfoPage)
{
	bPageInfoLoaded = true;
	
	lWidth = InfoPage.lWidth;
	lHeight = InfoPage.lHeight;
	nBPP = InfoPage.nBPP;

	// Обновляем только если передали, иначе сохраняем то что было в pvdInfoImage2
	if (InfoPage.pFormatName)
		lstrcpyn(FormatName, InfoPage.pFormatName, sizeofarray(FormatName));

	// Обновляем только если передали, иначе сохраняем то что было в pvdInfoImage2
	if (InfoPage.pCompression)
		lstrcpyn(Compression, InfoPage.pCompression, sizeofarray(Compression));
}
Example #7
0
M2_string M2_tostringn(char *s, int n)
{
    M2_string p = (M2_string)getmem_atomic(sizeofarray(p,n));
    p->len = n;
    memcpy(p->array,s,n);
    //GC_CHECK_CLOBBER(p);
    return p;
}
Example #8
0
int32_t MINFBox::parse()
{
    boxReader reader;
    uint32_t fboxes[] = { DINF_BOX, STBL_BOX };
    mde_log(MDE_LOG_DEBUG, "isom: parsing MINF box (size: %d bytes).\n", box.header.size);
    boxes = reader.parseBoxes(ctx, buffer, fboxes, sizeofarray(fboxes));
    mde_log(MDE_LOG_DEBUG, "isom: MINF box, found %d inner boxes.\n", boxes.size());
    return 0;
}
Example #9
0
static M2_string fromdatum(datum y) {
     M2_string x;
     if (y.dptr == NULL) return NULL;
     x = (M2_string)getmem(sizeofarray(x,y.dsize));
     x->len = y.dsize;
     memcpy(x->array, y.dptr, y.dsize);
     free(y.dptr);
     return x;
     }
Example #10
0
M2_string M2_join(M2_string x, M2_string y)
{
  M2_string p;
  p = (M2_string) getmem_atomic(sizeofarray(p,x->len+y->len));
  p->len = x->len + y->len;
  memcpy(p->array,x->array,x->len);
  memcpy(p->array+x->len,y->array,y->len);
  //GC_CHECK_CLOBBER(p);
  return p;
}
Example #11
0
void ImageInfo::Assign(const pvdInfoDecode2& DecodeInfo, const wchar_t* pNamePart /*= NULL*/)
{
	if (DecodeInfo.pFormatName)
		lstrcpyn(FormatName, DecodeInfo.pFormatName, sizeofarray(FormatName));
	
	if (DecodeInfo.pCompression)
		lstrcpyn(Compression, DecodeInfo.pCompression, sizeofarray(Compression));
	
	if (!FormatName[0] && pNamePart)
	{
		const wchar_t* pszExt = wcsrchr(pNamePart, L'.');
		if (pszExt)
		{
			FormatName[0] = L'[';
			lstrcpyn(FormatName+1, pszExt+1, sizeofarray(FormatName)-3);
			lstrcat(FormatName, L"]");
		}
	}
}
Example #12
0
chunk *STCOBox::dumpBox(dictionary *inputParams)
{
    uint32_t size;
    box.fullbox.header.type = htonl(STCO_BOX);
    box.fullbox.version = 0;
    box.fullbox.flags[0] = 0;
    box.fullbox.flags[1] = 0;
    box.fullbox.flags[2] = 0;
    box.entry_count = htonl(boxes.size());
    size = estimateSize(inputParams);
    chunk *c = new chunk(size, false);
    size = htonl(size);
    box.entry_count = 0;
    c->append((uint8_t *) &size, sizeof(size));
    c->append((uint8_t *) &box.fullbox.header.type, sizeof(box.fullbox.header.type));
    c->append((uint8_t *) &box.fullbox.version, sizeof(box.fullbox.version));
    c->append((uint8_t *) box.fullbox.flags, sizeofarray(box.fullbox.flags) * sizeof(uint8_t));
    c->append((uint8_t *) &box.entry_count, sizeof(box.entry_count));
    return c;
}
Example #13
0
int RFC822Day(const char *text) {
    static const char *dn[] = { "Sun", "Mon", "Tue", "Wed", "Thr", "Fri", "Sat" };
    for (int i=0, l=sizeofarray(dn); i<l; i++) if (!strcmp(text, dn[i])) return i;
    return 0;
}
Example #14
0
void ImageInfo::InitDecoder(CModuleInfo *pDecoder)
{
	lstrcpyn(DecoderName, pDecoder->pPlugin->pName, sizeofarray(DecoderName));
	lWidth = lHeight = nBPP = 0;
	nPages = 0; Animation = false;
}
Example #15
0
bool TProtocolPokey::Encode(const TJob& Job,Array<char>& Output)
{
	//	job to command id
	auto Command = TPokeyCommand::ToType( Job.mParams.mCommand );
	
	unsigned char tempOut[64-8];	//	gr: was 64, but their code NEVER uses more than 56 (64-8)
	unsigned char data2,data3,data4,data5;
	
	switch ( Command )
	{
		case TPokeyCommand::GetDeviceMeta:
		case TPokeyCommand::GetDeviceState:
			data2 = 0;
			data3 = 0;
			data4 = 0;
			data5 = 0;
			break;
			
			//	special case where we send zero bytes
		case TPokeyCommand::Discover:
			Output.PushBack(0xff);
			//Soy::Assert( Output.GetDataSize() == 0, "should send zero bytes for discovery");
			return true;
			
		default:
			return false;
	};
	
	auto RequestId = mRequestCounter++;
	unsigned char Header[8];
	
	Header[0] = 0xBB;
	Header[1] = Command;
	Header[2] = data2;
	Header[3] = data3;
	Header[4] = data4;
	Header[5] = data5;
	Header[6] = RequestId;
	Header[7] = TPokeyCommand::CalculateChecksum(Header);
	
	Output.PushBackArray( GetRemoteArray( reinterpret_cast<const char*>(Header), sizeofarray(Header) ) );
	Output.PushBackArray( GetRemoteArray( reinterpret_cast<const char*>(tempOut), sizeofarray(tempOut) ) );
	
	if ( !Soy::Assert( Output.GetDataSize()==64, "Always send 64 bytes" ) )
		return false;
	
	/*
	 
		// Wait for the response
		while(1)
		{
	 result = recv(comSocket, (char *)rxBuffer, 64, 0);
	 
	 // 64 bytes received?
	 if (result == 64)
	 {
	 if (rxBuffer[0] == 0xAA && rxBuffer[6] == RequestID)
	 {
	 if (rxBuffer[7] == CalculateChecksum(rxBuffer))
	 {
	 memcpy(Response, rxBuffer, 64);
	 return 0;
	 }
	 }
	 }
	 else if (result == 0)
	 printf("Connection closed\n");
	 else
	 printf("recv failed: %d\n", WSAGetLastError());
	 
	 
	 if (++retries1 > 10) break;
		}
		
		if (retries2++ > 3) break;
	 }
	 
	 return -1;
	 
	 
	 // Get serial number and versions
	 if (SendRequest(0x00, 0, 0, 0, 0, tempOut, tempIn) != 0) return -1;
	 deviceStat->DeviceData.SerialNumber = (int)(tempIn[2]) * 256 + (int)tempIn[3];
	 deviceStat->DeviceData.FirmwareVersionMajor = tempIn[4];
	 deviceStat->DeviceData.FirmwareVersionMinor = tempIn[5];
	 */
	return true;
}
	extern GAIA::N32 t_math_cookies_mtx44(GAIA::FSYS::File& file, GAIA::STREAM::StreamBase& stm)
	{
		GAIA::N32 nRet = 0;

		typedef GAIA::REAL __DataType;
		typedef GAIA::MATH::VEC3<__DataType> __VecType;
		typedef GAIA::MATH::MTX44<__DataType> __MtxType;

		static const __DataType DATA_LIST[] = 
		{
			0.0F, 1.0F, 2.0F, 3.0F,
			4.0F, 5.0F, 6.0F, 7.0F, 
			8.0F, 9.0F, 10.0F, 11.0F,
			12.0F, 13.0F, 14.0F, 15.0F,
		};

		__VecType pos;
		__MtxType mtx, mtx1, mtxResult;
		if(mtx.size() != 16)
		{
			GTLINE2("MTX44 size error!");
			++nRet;
		}
		if(mtx.sizex() != 4)
		{
			GTLINE2("MTX44 sizex error!");
			++nRet;
		}
		if(mtx.sizey() != 4)
		{
			GTLINE2("MTX44 sizey error!");
			++nRet;
		}
		if(mtx.isidentity())
		{
			GTLINE2("New MTX44 is identity!");
			++nRet;
		}
		mtx.identity();
		if(!mtx.isfinited())
		{
			GTLINE2("MTX44 is finited after identity!");
			++nRet;
		}
		if(!mtx.isidentity())
		{
			GTLINE2("MTX44 is not identity after identity!");
			++nRet;
		}

		mtx = GAIA::MATH::xsqrt(-1.0F);
		if(mtx.isfinited())
		{
			GTLINE2("MTX44 isfinite error!");
			++nRet;
		}

		mtx = 10.0F;
		for(GAIA::SIZE x = 0; x < mtx.size(); ++x)
		{
			if(mtx[x] != 10.0F)
			{
				GTLINE2("MTX44 operator = const value error!");
				++nRet;
				break;
			}
		}
		mtx1 = mtx;
		for(GAIA::SIZE x = 0; x < mtx1.size(); ++x)
		{
			if(mtx1[x] != 10.0F)
			{
				GTLINE2("MTX44 operator = const value error!");
				++nRet;
				break;
			}
		}

		mtx = DATA_LIST;
		for(GAIA::SIZE x = 0; x < sizeofarray(DATA_LIST); ++x)
		{
			if(mtx[x] != DATA_LIST[x])
			{
				GTLINE2("MTX44 operator = const datapointer error!");
				++nRet;
				break;
			}
		}
		mtx1 = mtx;
		for(GAIA::SIZE x = 0; x < sizeofarray(DATA_LIST); ++x)
		{
			if(mtx1[x] != DATA_LIST[x])
			{
				GTLINE2("MTX44 operator = const datapointer error!");
				++nRet;
				break;
			}
		}
		
		mtx = DATA_LIST;
		mtx.transpose();
		if(mtx == DATA_LIST)
		{
			GTLINE2("MTX44 operator = data pointer error!");
			++nRet;
		}
		mtx.transpose();
		if(mtx != DATA_LIST)
		{
			GTLINE2("MTX44 transpose error!");
			++nRet;
		}

		mtx.identity();
		mtx.translate(1.1F, 2.2F, 3.3F);
		if(mtx.isidentity())
		{
			GTLINE2("MTX44 translate error!");
			++nRet;
		}
		pos = mtx.position();
		if(pos.x != 1.1F || pos.y != 2.2F || pos.z != 3.3F)
		{
			GTLINE2("MTX44 translate error!");
			++nRet;
		}
		mtx1.isidentity();
		mtx1.translate(-1.1F, -2.2F, -3.3F);
		mtxResult = mtx * mtx1;
		if(!mtxResult.isalmostidentity())
		{
			GTLINE2("MTX44 translate error!");
			++nRet;
		}

		mtx.identity();
		mtx.rotatex(1.23F);
		if(mtx.isidentity())
		{
			GTLINE2("MTX44 rotatex error!");
			++nRet;
		}
		pos = mtx.position();
		if(pos != 0.0F)
		{
			GTLINE2("MTX44 rotatex error!");
			++nRet;
		}
		mtx1.isidentity();
		mtx1.rotatex(-1.23F);
		mtxResult = mtx * mtx1;
		if(!mtxResult.isalmostidentity())
		{
			GTLINE2("MTX44 rotatex error!");
			++nRet;
		}

		mtx.identity();
		mtx.rotatey(1.23F);
		if(mtx.isidentity())
		{
			GTLINE2("MTX44 rotatey error!");
			++nRet;
		}
		pos = mtx.position();
		if(pos != 0.0F)
		{
			GTLINE2("MTX44 rotatey error!");
			++nRet;
		}
		mtx1.isidentity();
		mtx1.rotatey(-1.23F);
		mtxResult = mtx * mtx1;
		if(!mtxResult.isalmostidentity())
		{
			GTLINE2("MTX44 rotatey error!");
			++nRet;
		}

		mtx.identity();
		mtx.rotatez(1.23F);
		if(mtx.isidentity())
		{
			GTLINE2("MTX44 rotatez error!");
			++nRet;
		}
		pos = mtx.position();
		if(pos != 0.0F)
		{
			GTLINE2("MTX44 rotatez error!");
			++nRet;
		}
		mtx1.isidentity();
		mtx1.rotatez(-1.23F);
		mtxResult = mtx * mtx1;
		if(!mtxResult.isalmostidentity())
		{
			GTLINE2("MTX44 rotatez error!");
			++nRet;
		}

		mtx.identity();
		mtx.rotate(__VecType(1.1F, 2.2F, 3.3F), 4.56F);
		if(mtx.isidentity())
		{
			GTLINE2("MTX44 rotate error!");
			++nRet;
		}
		pos = mtx.position();
		if(pos != 0.0F)
		{
			GTLINE2("MTX44 rotate error!");
			++nRet;
		}
		mtx1 = mtx;
		mtx1.inverse();
		mtxResult = mtx * mtx1;
		if(!mtxResult.isalmostidentity())
		{
			GTLINE2("MTX44 rotate error!");
			++nRet;
		}

		mtx.identity();
		mtx.scale(1.1F, 2.2F, 3.3F);
		if(mtx.isidentity())
		{
			GTLINE2("MTX44 scale error!");
			++nRet;
		}
		mtx1.isidentity();
		mtx1.scale(1.0F / 1.1F, 1.0F / 2.2F, 1.0F / 3.3F);
		mtxResult = mtx * mtx1;
		if(!mtxResult.isalmostidentity())
		{
			GTLINE2("MTX44 scale error!");
			++nRet;
		}

		mtx = DATA_LIST;
		mtx1 = DATA_LIST;
		mtx1[2] *= 2.0F;
		if(mtx == mtx1)
		{
			GTLINE2("MTX44 operator == MTX44 error!");
			++nRet;
		}
		if(!(mtx != mtx1))
		{
			GTLINE2("MTX44 operator != MTX44 error!");
			++nRet;
		}
		if(mtx >= mtx1)
		{
			GTLINE2("MTX44 operator >= MTX44 error!");
			++nRet;
		}
		if(!(mtx <= mtx1))
		{
			GTLINE2("MTX44 operator <= MTX44 error!");
			++nRet;
		}
		if(mtx > mtx1)
		{
			GTLINE2("MTX44 operator > MTX44 error!");
			++nRet;
		}
		if(!(mtx < mtx1))
		{
			GTLINE2("MTX44 operator < MTX44 error!");
			++nRet;
		}

		if(mtx == mtx1.front_ptr())
		{
			GTLINE2("MTX44 operator == data pointer error!");
			++nRet;
		}
		if(!(mtx != mtx1.front_ptr()))
		{
			GTLINE2("MTX44 operator != data pointer error!");
			++nRet;
		}
		if(mtx >= mtx1.front_ptr())
		{
			GTLINE2("MTX44 operator >= data pointer error!");
			++nRet;
		}
		if(!(mtx <= mtx1.front_ptr()))
		{
			GTLINE2("MTX44 operator <= data pointer error!");
			++nRet;
		}
		if(mtx > mtx1.front_ptr())
		{
			GTLINE2("MTX44 operator > data pointer error!");
			++nRet;
		}
		if(!(mtx < mtx1.front_ptr()))
		{
			GTLINE2("MTX44 operator < data pointer error!");
			++nRet;
		}

		return nRet;
	}
Example #17
0
int RFC822TimeZone(const char *text) {
    static const char *tzname[] = { "GMT", "EST", "EDT", "CST", "CDT", "MST", "MDT", "PST", "PDT", };
    static const int tzoffset[] = { 0,     -5,    -4,    -6,    -5,    -7,    -6,    -8,    -7     };
    for (int i=0, l=sizeofarray(tzname); i<l; i++) if (!strcmp(text, tzname[i])) return tzoffset[i];
    return 0;
}
Example #18
0
int RFC822Month(const char *text) {
    static const char *mn[] = { "Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec" };
    for (int i=0, l=sizeofarray(mn); i<l; i++) if (!strcmp(text, mn[i])) return i;
    return 0;
}
Example #19
0
	extern GAIA::N32 t_dataphase_xml(GAIA::FSYS::File& file, GAIA::STREAM::StreamBase& stm)
	{
		GAIA::N32 nRet = 0;

		typedef GAIA::DATAPHASE::XML<GAIA::TCH, GAIA::SIZE, GAIA::ALGO::TwiceSizeIncreaser<GAIA::SIZE> > __XMLType;

		__XMLType xml;
		__XMLType::__ConstCharPtrType nname, aname, avalue, cmnname, cmnvalue;

		if(xml.EnumNode(nname))
		{
			GTLINE2("New XML object must cannot EnumNode!");
			++nRet;
		}
		if(xml.EnumAttr(aname, avalue))
		{
			GTLINE2("New XML object must cannot EnumAttr!");
			++nRet;
		}
		if(xml.Enum(cmnname, cmnvalue))
		{
			GTLINE2("New XML object must cannot Enum!");
			++nRet;
		}
		if(xml.Change(_T("NodeName"), GNIL))
		{
			GTLINE2("New XML object cannot change node name!");
			++nRet;
		}
		if(xml.Change(_T("AttrName"), _T("AttrValue")))
		{
			GTLINE2("New XML object cannot change attr name and value!");
			++nRet;
		}
		if(!xml.IsResetCursor())
		{
			GTLINE2("New XML object must IsResetCallStack!");
			++nRet;
		}

		xml.Clear();
		if(xml.EnumNode(nname))
		{
			GTLINE2("XML object must cannot EnumNode after Clear!");
			++nRet;
		}
		if(xml.EnumAttr(aname, avalue))
		{
			GTLINE2("XML object must cannot EnumAttr after Clear!");
			++nRet;
		}
		if(xml.Enum(cmnname, cmnvalue))
		{
			GTLINE2("XML object must cannot Enum after Clear!");
			++nRet;
		}
		if(xml.Change(_T("NodeName"), GNIL))
		{
			GTLINE2("XML object cannot change node name after Clear!");
			++nRet;
		}
		if(xml.Change(_T("AttrName"), _T("AttrValue")))
		{
			GTLINE2("XML object cannot change attr name and value after Clear!");
			++nRet;
		}
		if(!xml.IsResetCursor())
		{
			GTLINE2("New XML object must IsResetCallStack after Clear!");
			++nRet;
		}

		xml.Destroy();
		if(xml.EnumNode(nname))
		{
			GTLINE2("XML object must cannot EnumNode after Destroy!");
			++nRet;
		}
		if(xml.EnumAttr(aname, avalue))
		{
			GTLINE2("XML object must cannot EnumAttr after Destroy!");
			++nRet;
		}
		if(xml.Enum(cmnname, cmnvalue))
		{
			GTLINE2("XML object must cannot Enum after Destroy!");
			++nRet;
		}
		if(xml.Change(_T("NodeName"), GNIL))
		{
			GTLINE2("XML object cannot change node name after Destroy!");
			++nRet;
		}
		if(xml.Change(_T("AttrName"), _T("AttrValue")))
		{
			GTLINE2("XML object cannot change attr name and value after Destroy!");
			++nRet;
		}

		if(!xml.IsResetCursor())
		{
			GTLINE2("New XML object must IsResetCallStack after Destroy!");
			++nRet;
		}
		if(!xml.WriteNode(_T("ROOT_NODE")))
		{
			GTLINE2("XML write node failed!");
			++nRet;
		}
		if(xml.IsResetCursor())
		{
			GTLINE2("XML IsResetCallStack error!");
			++nRet;
		}
		if(!xml.End())
		{
			GTLINE2("XML End failed!");
			++nRet;
		}
		if(xml.IsResetCursor())
		{
			GTLINE2("XML IsResetCallStack error!");
			++nRet;
		}
		if(xml.WriteNode(_T("ROOT_NODE1")))
		{
			GTLINE2("XML must have one root node only!");
			++nRet;
		}
		if(xml.IsResetCursor())
		{
			GTLINE2("XML IsResetCallStack error!");
			++nRet;
		}

		xml.Clear();
		if(!xml.WriteNode(_T("ROOT_NODE")))
		{
			GTLINE2("XML WriteNode failed!");
			++nRet;
		}
		if(!xml.WriteAttr(_T("AttrName1"), _T("AttrValue1")))
		{
			GTLINE2("XML WriteAttr failed!");
			++nRet;
		}
		if(!xml.WriteAttr(_T("AttrName2"), _T("AttrValue2")))
		{
			GTLINE2("XML WriteAttr failed!");
			++nRet;
		}
		if(!xml.WriteAttr(_T("AttrName3"), _T("AttrValue3")))
		{
			GTLINE2("XML WriteAttr failed!");
			++nRet;
		}
		if(xml.WriteAttr(_T("AttrName1"), _T("AttrValue1")))
		{
			GTLINE2("XML WriteAttr write same name attr!");
			++nRet;
		}
		if(xml.WriteAttr(_T("AttrName2"), _T("AttrValue2")))
		{
			GTLINE2("XML WriteAttr write same name attr!");
			++nRet;
		}
		if(xml.WriteAttr(_T("AttrName3"), _T("AttrValue3")))
		{
			GTLINE2("XML WriteAttr write same name attr!");
			++nRet;
		}
		if(xml.IsResetCursor())
		{
			GTLINE2("XML IsResetCallStack error!");
			++nRet;
		}
		for(GAIA::SIZE x = 0; x < 3; ++x)
		{
			if(xml.IsResetCursor())
			{
				GTLINE2("XML IsResetCallStack error!");
				++nRet;
				break;
			}
			if(!xml.WriteNode(_T("NODE")))
			{
				GTLINE2("XML WriteNode failed!"); 
				++nRet;
				break;
			}
			if(!xml.WriteAttr(_T("AttrName11"), _T("AttrValue11")))
			{
				GTLINE2("XML WriteAttr failed!");
				++nRet;
				break;
			}
			if(!xml.WriteAttr(_T("AttrName22"), _T("AttrValue22")))
			{
				GTLINE2("XML WriteAttr failed!");
				++nRet;
				break;
			}
			if(!xml.WriteAttr(_T("AttrName33"), _T("AttrValue33")))
			{
				GTLINE2("XML WriteAttr failed!");
				++nRet;
				break;
			}
			if(xml.WriteAttr(_T("AttrName11"), _T("AttrValue11")))
			{
				GTLINE2("XML WriteAttr write same name attr!");
				++nRet;
				break;
			}
			if(xml.WriteAttr(_T("AttrName22"), _T("AttrValue22")))
			{
				GTLINE2("XML WriteAttr write same name attr!");
				++nRet;
				break;
			}
			if(xml.WriteAttr(_T("AttrName33"), _T("AttrValue33")))
			{
				GTLINE2("XML WriteAttr write same name attr!");
				++nRet;
				break;
			}
			GAIA::BL bExistError = GAIA::False;
			for(GAIA::SIZE y = 0; y < 3; ++y)
			{
				if(xml.IsResetCursor())
				{
					GTLINE2("XML IsResetCallStack error!");
					++nRet;
					bExistError = GAIA::True;
					break;
				}
				if(!xml.WriteNode(_T("SUB_NODE")))
				{
					GTLINE2("XML WriteNode failed!"); 
					++nRet;
					bExistError = GAIA::True;
					break;
				}
				if(!xml.WriteAttr(_T("AttrName111"), _T("AttrValue111")))
				{
					GTLINE2("XML WriteAttr failed!");
					++nRet;
					bExistError = GAIA::True;
					break;
				}
				if(!xml.WriteAttr(_T("AttrName222"), _T("AttrValue222")))
				{
					GTLINE2("XML WriteAttr failed!");
					++nRet;
					bExistError = GAIA::True;
					break;
				}
				if(!xml.WriteAttr(_T("AttrName333"), _T("AttrValue333")))
				{
					GTLINE2("XML WriteAttr failed!");
					++nRet;
					bExistError = GAIA::True;
					break;
				}
				if(xml.WriteAttr(_T("AttrName111"), _T("AttrValue111")))
				{
					GTLINE2("XML WriteAttr write same name attr!");
					++nRet;
					bExistError = GAIA::True;
					break;
				}
				if(xml.WriteAttr(_T("AttrName222"), _T("AttrValue222")))
				{
					GTLINE2("XML WriteAttr write same name attr!");
					++nRet;
					bExistError = GAIA::True;
					break;
				}
				if(xml.WriteAttr(_T("AttrName333"), _T("AttrValue333")))
				{
					GTLINE2("XML WriteAttr write same name attr!");
					++nRet;
					bExistError = GAIA::True;
					break;
				}
				if(!xml.End())
				{
					GTLINE2("XML End failed!");
					++nRet;
					bExistError = GAIA::True;
					break;
				}
			}
			if(bExistError)
				break;
			if(!xml.End())
			{
				GTLINE2("XML End failed!");
				++nRet;
				break;
			}
		}
		if(!xml.End())
		{
			GTLINE2("XML End failed!");
			++nRet;
		}
		if(xml.IsResetCursor())
		{
			GTLINE2("XML IsResetCallStack error!");
			++nRet;
		}
		if(xml.WriteNode(_T("ROOT_NODE1")))
		{
			GTLINE2("XML must have one root node only!");
			++nRet;
		}
		if(xml.IsResetCursor())
		{
			GTLINE2("XML IsResetCallStack error!");
			++nRet;
		}

		GAIA::FSYS::File xmlfile;
		if(!xmlfile.Open(_T("../TESTRES/xmlfile.xml"), 
			GAIA::FSYS::File::OPEN_TYPE_READ |
			GAIA::FSYS::File::OPEN_TYPE_WRITE |
			GAIA::FSYS::File::OPEN_TYPE_CREATEALWAYS))
		{
			GTLINE2("Cannot open a file for save the xml.");
			++nRet;
		}
		else
		{
			typedef GAIA::CTN::Accesser<GAIA::TCH, GAIA::SIZE, GAIA::ALGO::TwiceSizeIncreaser<GAIA::SIZE> > __AccType;
			__AccType acc;
			acc.expandable(GAIA::True);
			if(!acc.bindfile(&xmlfile, __AccType::ACCESS_TYPE_READ | __AccType::ACCESS_TYPE_WRITE))
			{
				GTLINE2("Bind accesser to the file failed!");
				++nRet;
			}
			else
			{
				if(!xml.SaveText(acc, GAIA::CHARSET_TYPE_UTF16LE))
				{
					GTLINE2("Save xml to file failed!");
					++nRet;
				}
			}
		}
		xmlfile.Close();

		if(!xmlfile.Open(_T("../TESTRES/xmlfile.xml"),
			GAIA::FSYS::File::OPEN_TYPE_READ))
		{
			GTLINE2("Cannot open a file for load the xml.");
			++nRet;
		}
		else
		{
			typedef GAIA::CTN::Accesser<GAIA::TCH, GAIA::SIZE, GAIA::ALGO::TwiceSizeIncreaser<GAIA::SIZE> > __AccType;
			__AccType acc;
			if(!acc.bindfile(&xmlfile, __AccType::ACCESS_TYPE_READ))
			{
				GTLINE2("Bind accesser to file failed!");
				++nRet;
			}
			else
			{
				if(!xml.LoadText(acc))
				{
					GTLINE2("Load xml from file failed!");
					++nRet;
				}
			}
		}
		xmlfile.Close();

		GAIA::FSYS::File xmlbinaryfile;
		if(!xmlbinaryfile.Open(_T("../TESTRES/xmlfile.xml"), 
			GAIA::FSYS::File::OPEN_TYPE_READ |
			GAIA::FSYS::File::OPEN_TYPE_WRITE |
			GAIA::FSYS::File::OPEN_TYPE_CREATEALWAYS))
		{
			GTLINE2("Cannot open a file for save the xml.");
			++nRet;
		}
		else
		{
			typedef GAIA::CTN::Accesser<GAIA::TCH, GAIA::SIZE, GAIA::ALGO::TwiceSizeIncreaser<GAIA::SIZE> > __AccType;
			__AccType acc;
			acc.expandable(GAIA::True);
			if(!acc.bindfile(&xmlbinaryfile, __AccType::ACCESS_TYPE_READ | __AccType::ACCESS_TYPE_WRITE))
			{
				GTLINE2("Bind accesser to the file failed!");
				++nRet;
			}
			else
			{
				if(!xml.SaveBinary(acc))
				{
					GTLINE2("Save xml to file failed!");
					++nRet;
				}
			}
		}
		xmlbinaryfile.Close();

		if(!xmlbinaryfile.Open(_T("../TESTRES/xmlfile.xml"),
			GAIA::FSYS::File::OPEN_TYPE_READ))
		{
			GTLINE2("Cannot open a file for load the xml.");
			++nRet;
		}
		else
		{
			typedef GAIA::CTN::Accesser<GAIA::TCH, GAIA::SIZE, GAIA::ALGO::TwiceSizeIncreaser<GAIA::SIZE> > __AccType;
			__AccType acc;
			if(!acc.bindfile(&xmlbinaryfile, __AccType::ACCESS_TYPE_READ))
			{
				GTLINE2("Bind accesser to file failed!");
				++nRet;
			}
			else
			{
				if(!xml.LoadBinary(acc))
				{
					GTLINE2("Load xml from file failed!");
					++nRet;
				}
			}
		}
		xmlbinaryfile.Close();

		static const GAIA::TCH* CONTENT_GROUP[] = 
		{
			_T("ROOT_NODE"),
			_T("AttrName1"), _T("AttrValue1"),
			_T("AttrName2"), _T("AttrValue2"),
			_T("AttrName3"), _T("AttrValue3"),
				_T("NODE"),
				_T("AttrName11"), _T("AttrValue11"),
				_T("AttrName22"), _T("AttrValue22"),
				_T("AttrName33"), _T("AttrValue33"),
					_T("SUB_NODE"),
					_T("AttrName111"), _T("AttrValue111"),
					_T("AttrName222"), _T("AttrValue222"),
					_T("AttrName333"), _T("AttrValue333"),
					_T("SUB_NODE"),
					_T("AttrName111"), _T("AttrValue111"),
					_T("AttrName222"), _T("AttrValue222"),
					_T("AttrName333"), _T("AttrValue333"),
					_T("SUB_NODE"),
					_T("AttrName111"), _T("AttrValue111"),
					_T("AttrName222"), _T("AttrValue222"),
					_T("AttrName333"), _T("AttrValue333"),
				_T("NODE"),
				_T("AttrName11"), _T("AttrValue11"),
				_T("AttrName22"), _T("AttrValue22"),
				_T("AttrName33"), _T("AttrValue33"),
					_T("SUB_NODE"),
					_T("AttrName111"), _T("AttrValue111"),
					_T("AttrName222"), _T("AttrValue222"),
					_T("AttrName333"), _T("AttrValue333"),
					_T("SUB_NODE"),
					_T("AttrName111"), _T("AttrValue111"),
					_T("AttrName222"), _T("AttrValue222"),
					_T("AttrName333"), _T("AttrValue333"),
					_T("SUB_NODE"),
					_T("AttrName111"), _T("AttrValue111"),
					_T("AttrName222"), _T("AttrValue222"),
					_T("AttrName333"), _T("AttrValue333"),
				_T("NODE"),
				_T("AttrName11"), _T("AttrValue11"),
				_T("AttrName22"), _T("AttrValue22"),
				_T("AttrName33"), _T("AttrValue33"),
					_T("SUB_NODE"),
					_T("AttrName111"), _T("AttrValue111"),
					_T("AttrName222"), _T("AttrValue222"),
					_T("AttrName333"), _T("AttrValue333"),
					_T("SUB_NODE"),
					_T("AttrName111"), _T("AttrValue111"),
					_T("AttrName222"), _T("AttrValue222"),
					_T("AttrName333"), _T("AttrValue333"),
					_T("SUB_NODE"),
					_T("AttrName111"), _T("AttrValue111"),
					_T("AttrName222"), _T("AttrValue222"),
					_T("AttrName333"), _T("AttrValue333"),
		};
		xml.ResetCursor();
		if(!xml.IsResetCursor())
		{
			GTLINE2("XML IsResetCursor failed!");
			++nRet;
		}
		GAIA::SIZE index = 0;
		for(;;)
		{
			if(!xml.Enum(cmnname, cmnvalue))
			{
				GTLINE2("XML Enum failed!");
				++nRet;
				break;
			}
			if(GAIA::ALGO::strcmp(cmnname, CONTENT_GROUP[index++]) != 0)
			{
				GTLINE2("XML Enum content error!");
				++nRet;
				break;
			}
			if(cmnvalue != GNIL && GAIA::ALGO::strcmp(cmnvalue, CONTENT_GROUP[index++]) != 0)
			{
				GTLINE2("XML Enum content error!");
				++nRet;
				break;
			}
			if(index == sizeofarray(CONTENT_GROUP))
			{
				if(xml.Enum(cmnname, cmnvalue))
				{
					GTLINE2("XML Enum failed! all content has been enumed.");
					++nRet;
				}
				break;
			}
		}
		if(xml.IsResetCursor())
		{
			GTLINE2("XML Enum failed!");
			++nRet;
		}

		xml.ResetCursor();
		if(!xml.IsResetCursor())
		{
			GTLINE2("XML IsResetCursor failed!");
			++nRet;
		}

		return nRet;
	}
Example #20
0
static FILE *dbg_out = NULL;
bool _ul_debugging = false;
UL_LINKAGE void _ul_debug(const char *fmt, ...)
{
	assert(dbg_out);
	va_list ap;
	va_start(ap, fmt);
	vfprintf(dbg_out, fmt, ap);
	va_end(ap);
}

const char *_ul_symbols[] = {
	"m", "kg", "s", "A", "K", "mol", "Cd", "L",
};
static_assert(sizeofarray(_ul_symbols) == NUM_BASE_UNITS);

// The last error message
static char errmsg[1024];
UL_LINKAGE void _ul_set_error(const char *func, int line, const char *fmt, ...)
{
	size_t len = 0;
	if (_ul_debugging) {
		snprintf(errmsg, 1024, "[%s:%d] ", func, line);
		len = strlen(errmsg);
	}

	va_list ap;
	va_start(ap, fmt);
	vsnprintf(errmsg + len, 1024 - len, fmt, ap);
	va_end(ap);