Ejemplo n.º 1
0
SDTSAttrRecord *SDTSAttrReader::GetNextAttrRecord()

{
    DDFRecord   *poRawRecord;
    DDFField    *poATTRField;
    SDTSModId   oModId;
    SDTSAttrRecord *poAttrRecord;

    poATTRField = GetNextRecord( &oModId, &poRawRecord, TRUE );

    if( poATTRField == NULL )
        return NULL;

    poAttrRecord = new SDTSAttrRecord();

    poAttrRecord->poWholeRecord = poRawRecord;
    poAttrRecord->poATTR = poATTRField;
    memcpy( &(poAttrRecord->oModId), &oModId, sizeof(SDTSModId) );

    return poAttrRecord;
}
void
GAddressBookMgr::AddAddressBook
	(
	const JCharacter*	name,
	JTree*				tree
	)
{
	if (!JFileExists(name))
		{
		return;
		}
	JDirEntry* dirEntry = new JDirEntry(name);
	assert(dirEntry != NULL);
	JTreeNode* jbase = tree->GetRoot();
	JNamedTreeNode* base = dynamic_cast<JNamedTreeNode*>(jbase);
	assert(base != NULL);
	GAddressBookTreeNode* book = new
		GAddressBookTreeNode(dirEntry, base, dirEntry->GetName());
	assert(book != NULL);
	std::ifstream is(name);
	while (is.good())
		{
		JString line = JReadLine(is);
		GAddressBookEntry* entry = new GAddressBookEntry();
		assert( entry != NULL );

		JString name;
		if (GetNextRecord(line, name, is))
			{
			GetNextRecord(line, entry->fullname, is);
			if (GetNextRecord(line, entry->address, is))
				{
				GetNextRecord(line, entry->fcc, is);
				GetNextRecord(line, entry->comment, is);
				itsAddresses->SetElement(name, entry, JPtrArrayT::kDelete);

				GAddressEntryTreeNode* aEntry =
					new GAddressEntryTreeNode(book, entry->fullname);
				assert(aEntry != NULL);
				GAddressItemTreeNode* item =
					new GAddressItemTreeNode(GAddressItemTreeNode::kName,
											 aEntry, name, kJFalse);
				assert(item != NULL);

				JString address = entry->address;
				if (address.BeginsWith("(") && address.GetLength() > 2)
					{
					address = address.GetSubstring(2, address.GetLength() - 1);
					JPtrArray<JString> list(JPtrArrayT::kForgetAll);
					GParseNameList(address, list);
					const JSize count = list.GetElementCount();
					for (JSize i = count; i >= 1; i--)
						{
						item =
							new GAddressItemTreeNode(GAddressItemTreeNode::kEMail,
													 aEntry, *(list.NthElement(i)), kJFalse);
						assert(item != NULL);
						}
					list.DeleteAll();
					}
				else
					{
					item =
						new GAddressItemTreeNode(GAddressItemTreeNode::kEMail,
												 aEntry, address, kJFalse);
					}

				if (!entry->comment.IsEmpty())
					{
					item =
						new GAddressItemTreeNode(GAddressItemTreeNode::kComment,
												 aEntry, entry->comment, kJFalse);
					assert(item != NULL);
					}

				if (!entry->fcc.IsEmpty())
					{
					item =
						new GAddressItemTreeNode(GAddressItemTreeNode::kFcc,
												 aEntry, entry->fcc, kJFalse);
					assert(item != NULL);
					}

				book->InsertSorted(aEntry);

				continue;
				}
			}
		delete entry;
		}
}
Ejemplo n.º 3
0
bool DjikstraTripModel::SetProgress(float & fTime, short iSpeed, unsigned int & iNextRecord)
{
	if (m_iCurrentRecord == (unsigned)-1 || m_iCRShapePoint == (unsigned)-1)
		return false;

	// find distance to next shape point
	MapRecord * pRecord = g_pMapDB->GetRecord(m_iCurrentRecord);
	float fRemaining = 0.f, fPart = 0.f, fDistance = (fTime * iSpeed) / SECSPERHOUR;

	if ((signed)m_iCRShapePoint < pRecord->nShapePoints - 1)
	{
		Coords c0 = pRecord->pShapePoints[m_iCRShapePoint], c1 = pRecord->pShapePoints[m_iCRShapePoint + 1];

		fPart = Distance(c0, c1);
		if (m_listPathRecords.empty() && m_iCRShapePoint == m_iEndShapePoint)
		{
			if (m_bForwards)
				fRemaining = fPart * (m_fEndProgress - m_fCRProgress);
			else
				fRemaining = fPart * (m_fCRProgress - m_fEndProgress);
		}
		else
		{
			if (m_bForwards)
				fRemaining = fPart * (1 - m_fCRProgress);
			else
				fRemaining = fPart * m_fCRProgress;
		}
	}

	if (fDistance < fRemaining && fPart > 0.f)
	{
		// we're still on the same part of the record
		if (m_bForwards)
			m_fCRProgress += fDistance / fPart;
		else
			m_fCRProgress -= fDistance / fPart;
		fTime = 0.f;
	}
	else
	{
		// we've passed the end of this shape point
		if (iSpeed > 0)
			fTime -= (fRemaining * SECSPERHOUR) / iSpeed;
		else
			fTime = 0.f;
		if (m_bForwards) {
			if ((signed)m_iCRShapePoint < (m_listPathRecords.empty() ? (signed)m_iEndShapePoint : (pRecord->nShapePoints - 1)))
			{
				m_iCRShapePoint++;
				m_fCRProgress = 0.f;
//				return SetProgress(fTime, iSpeed, iNextRecord);
				return true;
			}
			else
			{
				// check to see if we're stopped for a traffic light
				if (!g_pMapDB->UseTrafficLights() || CanCarGoThrough(g_pMapDB->GetVertex(pRecord->pVertices[pRecord->nVertices - 1]), m_iCurrentRecord))
				{
					// go to next record and return with the unused time
					iNextRecord = GetNextRecord(pRecord->pVertices[pRecord->nVertices - 1], m_iCurrentRecord);
					if (iNextRecord != (unsigned)-1)
					{
						m_iCurrentRecord = iNextRecord;
						if (g_pMapDB->GetRecord(m_iCurrentRecord)->pVertices[0] == pRecord->pVertices[pRecord->nVertices - 1]) {
							m_bForwards = true;
							m_iCRShapePoint = 0;
							m_fCRProgress = 0.f;
						} else {
							m_bForwards = false;
							m_iCRShapePoint = g_pMapDB->GetRecord(m_iCurrentRecord)->nShapePoints - 1;
							m_fCRProgress = 0.f;
						}
						return true;
					}
				}
				else
				{
					// we're stopped here!
					fTime = 0.f;
					m_fCRProgress = 1.f;
				}
			}
		} else {
			if (m_iCRShapePoint > (m_listPathRecords.empty() ? m_iEndShapePoint : 0))
			{
				m_iCRShapePoint--;
				m_fCRProgress = 1.f;
//				return SetProgress(fTime, iSpeed, iNextRecord);
				return true;
			}
			else
			{
				// check to see if we're stopped for a traffic light
				if (!g_pMapDB->UseTrafficLights() || CanCarGoThrough(g_pMapDB->GetVertex(pRecord->pVertices[0]), m_iCurrentRecord))
				{
					// go to next record
					iNextRecord = GetNextRecord(pRecord->pVertices[0], m_iCurrentRecord);
					if (iNextRecord != (unsigned)-1)
					{
						m_iCurrentRecord = iNextRecord;
						if (g_pMapDB->GetRecord(m_iCurrentRecord)->pVertices[0] == pRecord->pVertices[0]) {
							m_bForwards = true;
							m_iCRShapePoint = 0;
							m_fCRProgress = 0.f;
						} else {
							m_bForwards = false;
							m_iCRShapePoint = g_pMapDB->GetRecord(m_iCurrentRecord)->nShapePoints - 1;
							m_fCRProgress = 0.f;
						}
						return true;
					}
				}
				else
				{
					// we're stopped here!
					fTime = 0.f;
					m_fCRProgress = 0.f;
				}
			}
		}
	}
	return false;
}