-
-
-
Wie ktoś jak sie wczytuje pliki w C++? Albo moze ktoś podać mi żródła gdzie to znalesc w jakich ksiazkach lub gdzie w necie?
Z gory dzieki!
d41d8cd98f00b204e9800998ecf8427e
-
-
-
d41d8cd98f00b204e9800998ecf8427e
-
-
-
A możesz mi podać konkretny przyklad wczytywania? Bo jednak mi nie dziala to wczytywanie z tej strony co podałeś.
d41d8cd98f00b204e9800998ecf8427e
-
-
-
Z tego co pamietam Rataj w swoim wykladzie podal przyklady operacji na plikach.
d41d8cd98f00b204e9800998ecf8427e
-
-
-
A jaki to przedmiot i gdzie to szukac bo ja z Ratajem nic nie mam?
d41d8cd98f00b204e9800998ecf8427e
-
-
-
Jeśli to C++, to musi działać, inaczej robisz coś bardzo głupiego. Już lepiej pochwal się kawałkiem kodu.
A Grey czytać nie umie, bo Rataj się zajmuje Javą u nas na wydziale.
d41d8cd98f00b204e9800998ecf8427e
-
-
-
d41d8cd98f00b204e9800998ecf8427e
-
-
-
McMonster napisał/a: | Jeśli to C++, to musi działać, inaczej robisz coś bardzo głupiego. Już lepiej pochwal się kawałkiem kodu.
A Grey czytać nie umie, bo Rataj się zajmuje Javą u nas na wydziale. |
Prawda moj blad Ale Rataj kiedys prowadzil C++ wiec moze daloby rade znalesc co nie zmienia faktu ze nie chodzilo mi o 'te' wyklady ; )
d41d8cd98f00b204e9800998ecf8427e
-
-
-
Dzieki wam! a dokladnie chodzi mi o wczytywanie plikow MP.
Tu taki kod mam do wczytywania:
// GPSMapEdit
// Polish format parser.
//
# include "StdAfx.h"
# include "Polish.h"
# include "Status.h"
# include "Map.h"
# include "Types.h"
# include "GarminTypes.h"
# include "NavitelTypes.h"
# include "RussaTypes.h"
# include "Load.h"
# include "Log.h"
# include <Core/Strings/Convert.h>
# include <Core/Strings/Parse.h>
# include <Map/Layers/FeatureLayer.h>
# include <Map/Layers/RasterLayer.h>
# include <Map/MpFile/Section.h>
# include <Map/PostalAddress/AddressItems.h>
# include <Map/RoutingGraph/Node.h>
# include <Map/Types/TypeSetRegistrator.h>
# include <Math/Fast/fast_floor.h>
# include <Math/Geodesy/Datum.h>
# include <Math/Geodesy/DatumTransform.h>
# include <Math/Geodesy/Ellipsoid.h>
# include <Math/Geometry/PtAlgo.h>
# include <Dialogs/MessageBoxes.h>
# include <FileSystem/FileSystem.h>
# include <FileSystem/WorkingDirectorySelector.h>
# include <Map/PointExtra.h>
# include <Map/Rgn.h>
# include <Map/RgnElement.h>
# include <Map/RgnElementExtra.h>
# include <Map/RgnExtra.h>
# include <Map/RgnOrigin.h>
# include <Map/ZoomLevel.h>
# include <Processing/TrackCancel.h>
# include <Referencies/TextFileReference.h>
# include <boost/scoped_ptr.hpp>
static
size_t _ParseUIntSeries (const char * _p, const char * _pEnd, size_t _cExpectedUInts, ...) {
const char * p = _p;
va_list vl;
va_start (vl, _cExpectedUInts);
size_t c;
for (c = 0; c < _cExpectedUInts; ++ c) {
OmitSpaces (& p, _pEnd);
if (c != 0) {
if (* p == ',')
++ p;
else
break;
OmitSpaces (& p, _pEnd);
}
unsigned long ul = 0;
if (! ParseDecU (p, _pEnd, & p, ul))
break;
unsigned int * const pUInt = va_arg (vl, unsigned int *);
* pUInt = ul;
}
va_end (vl);
return c;
}
///////////////////////////////////////////////////////////
const char c_strAbbrevDelimiter [] = "~[0x1d]";
class CTxtLoader : public CMapLoader {
public:
CTxtLoader ()
: m_pMap (NULL), m_TypeSets (GetTypeSetRegistrator ())
{}
// Override.
virtual bool IsValid (const char * _pData, size_t _cFileSize) const;
virtual LoadStatus Load (const char * _pData, size_t _cFileSize, const std::wstring & _FileName, map_t * _pMap, volatile Processing::ITrackCancel & _trackCancel);
private:
enum SectionType {
ST_NONE, ST_NONE_START,
ST_IMG_ID,
ST_POI, ST_RGN20, ST_POLYLINE, ST_POLYGON,
ST_PLT, ST_WPT, ST_SHP, ST_DBX, ST_FILE, ST_DICTIONARY, ST_MAP, ST_BACKGROUND, ST_DEFINITIONS,
ST_COUNTRIES, ST_REGIONS, ST_CITIES, ST_HIGHWAYS, ST_ZIPCODES, ST_RESTRICTION,
ST_UNKNOWN
} m_GroupType;
bool ParseCustomDatum (const char * _pValue, const char * _pEnd);
bool ParseType (const char * _pValue, const char * _pEnd, const char ** _ppEnd, unsigned long & _ulType);
bool ParseReal (const char * _pValue, const char * _pEnd, const char ** _ppEnd, double & _fRet);
bool ParsePoint (const char * _pValue, const char * _pEnd, point_t & _pt, const char ** _ppEnd);
void ParsePoints (const char * _pValue, const char * _pEnd, points_t & _points);
bool ParseRouteParam (const char * _pValue, const char * _pEnd, rgn_extra_t & _extra);
bool ParseEntryPoint (const char * _pValue, const char * _pEnd, rgn_extra_t & _extra);
void ParseLine (const char * _p, const char * _pNextLine, volatile Processing::ITrackCancel & _trackCancel);
void AddRgn (SectionType _gt, RGN_KIND _Kind, const char * _p);
void DetectHoles (rgn_elements_t & _elements);
rgnode_t * ParseRGNode (const char * _pLine, const char * _pNextLine, const char * & _p, size_t _cPoints, size_t & _cPoint);
void ParseNumbers (const char * _pLine, const char * _pNextLine, const char * & _p, size_t _cElement);
void ParseHLevel (const char * _pLine, const char * _pNextLine, const char * & _p, size_t _cElement);
void UpdateNumbers (rgn_t & _rgn);
void AssignCity (rgn_t & _rgn);
void _BuildFullCityName (const std::string & _strCityName, std::string & _strRegionName, std::string & _strCountryName, std::string & _strFullName);
city_t * _GetCity (const std::string & _strCityName, std::string & _strRegionName, std::string & _strCountryName, bool _bStrict);
city_t * _GetCity (const char * & _p, const char * _pNextLine);
zip_t * _GetZip (const char * _strZipCode, size_t _cLen);
bool OmitComma (const char * & _p, const char * _pEnd);
map_t * m_pMap;
// m.u.s begin
const Map::Types::TypeSetRegistrator & m_TypeSets;
boost::scoped_ptr<map_t> m_pAttachmentsMap;
// m.u.s end
size_t m_cOffset;
size_t m_cFileSize;
file_ref_t * m_pFileRef;
// The layer of the current region.
RGN_KIND m_Kind;
// The counter of current line.
size_t m_cFileLine;
// The counter of regions.
size_t m_cOrdinal;
// True if [IMG ID] is defined.
bool m_bHeader;
// Characters per point in source text.
size_t m_cPointLen;
// Offset of object begin.
size_t m_cObjectBegin;
// The inter-section multi-line comment, w/o semicolons.
std::string m_strComment;
// Last unsupported section.
std::string m_strUnsupportedSection;
bool m_bUnsupportedSection;
// The max number of digits in mantissa.
size_t m_cPrecOrder;
// The counter used to omit some SetProgress() calls.
size_t m_cSetProgress;
bool m_bPolish074;
// The buffer of elements used for allocation optimization.
std::vector<rgn_element_t> m_elements;
size_t m_cElements;
// Postal address data.
std::vector<country_t *> m_vecCountries;
std::vector<region_t *> m_vecRegions;
std::vector<city_t *> m_vecCities;
std::vector<zip_t *> m_vecZips;
std::vector<highway_t *> m_vecHighways;
size_t m_cCountryIndex;
size_t m_cRegionIndex;
size_t m_cCityIndex;
size_t m_cZipIndex;
size_t m_cHighwayIndex;
typedef std::map<std::string, city_t *> name2city_t;
name2city_t m_name2city;
typedef std::map<std::string, zip_t *> name2zip_t;
name2zip_t m_name2zip;
std::string m_strCityName;
std::string m_strRegionName;
std::string m_strCountryName;
std::string m_strDefaultCityName;
std::string m_strDefaultRegionName;
std::string m_strDefaultCountryName;
void _ParseAbbrevName (const char * _strBegin, const char * _strEnd, std::string & _strName, std::string & _strAbbrevName);
// Routing data.
typedef std::map<DWORD, rgn_t *> RoadID2Object_t;
RoadID2Object_t m_RoadID2Object;
// m.u.s begin
struct nodes_pair_t {
rgnode_t * pFromNode;
rgnode_t * pToNode;
};
typedef std::map<rgrestriction_t *, nodes_pair_t> Restriction2nodes_pair_t;
Restriction2nodes_pair_t m_Restriction2nodes_pair;
void RegisterRestrictionNodes (rgrestriction_t * _pRestriction, rgnode_t * _pFromNode, rgnode_t * _pToNode) {
nodes_pair_t pair;
pair.pFromNode = _pFromNode;
pair.pToNode = _pToNode;
m_Restriction2nodes_pair [_pRestriction] = pair;
}
bool GetRestrictionNodes (rgrestriction_t * _pRestriction, nodes_pair_t & _pair) {
const Restriction2nodes_pair_t::const_iterator i = m_Restriction2nodes_pair.find (_pRestriction);
if (i == m_Restriction2nodes_pair.end ()) {
_pair.pFromNode = NULL;
_pair.pToNode = NULL;
return false;
}
_pair = i->second;
return true;
}
// m.u.s end
typedef std::map<DWORD, rgnode_t *> NodeID2Node_t;
NodeID2Node_t m_NodeID2Node;
rgnode_t * GetRGNode (DWORD _dwNodeID) {
const NodeID2Node_t::const_iterator i = m_NodeID2Node.find (_dwNodeID);
if (i == m_NodeID2Node.end ()) {
rgnode_t & rgnode = m_pMap->CreateNode (_dwNodeID);
m_NodeID2Node [_dwNodeID] = & rgnode;
return & rgnode;
} else
return i->second;
}
rgrestriction_t * m_pLastRestriction;
bool m_bTurnRestrictionsProcessed;
void _PostProcessTurnRestrictions ();
Math::Geometry::TransformPtr m_pDatumTransformation;
};
DECLARE_MAP_LOADER2 (CTxtLoader, L"polish", L"mp;txt", L"Polish format (*.mp;*.txt)", ftiDefault | ftiMapFileByParts);
static
const char * _GetValue (const char * _pKey, const char * _pEnd) {
if (_pKey >= _pEnd)
return _pEnd;
const char * const p = reinterpret_cast<const char *> (::memchr (_pKey, '=', _pEnd - _pKey));
return p ? p + 1 : _pEnd;
}
static
const char * _FindDelimiter (const char * _pBegin, const char * _pEnd, const char * _strDelimiter, size_t _cDelimiterLen) {
assert (_cDelimiterLen >= 2);
assert (_pBegin <= _pEnd);
if (_pBegin >= _pEnd)
return _pEnd;
const char * p = _pBegin;
while (p + _cDelimiterLen <= _pEnd) {
p = reinterpret_cast<const char *> (::memchr (p, * _strDelimiter, _pEnd - p));
if (p == NULL)
return _pEnd;
if (::_strnicmp (p + 1, _strDelimiter + 1, _cDelimiterLen - 1) == 0)
return p;
++ p;
}
return _pEnd;
}
bool CTxtLoader::OmitComma (const char * & _p, const char * _pEnd) {
OmitSpaces (& _p, _pEnd);
if (* _p != ',')
return false;
++ _p;
OmitSpaces (& _p, _pEnd);
return true;
}
bool CTxtLoader::ParseCustomDatum (const char * _pValue, const char * _pEnd) {
const char * p = _pValue;
OmitSpaces (& p, _pEnd);
// DX
double fDX = 0;
if (! ParseReal (p, _pEnd, & p, fDX))
return false;
if (! OmitComma (p, _pEnd))
return false;
// DY
double fDY = 0;
if (! ParseReal (p, _pEnd, & p, fDY))
return false;
if (! OmitComma (p, _pEnd))
return false;
// DZ
double fDZ = 0;
if (! ParseReal (p, _pEnd, & p, fDZ))
return false;
if (! OmitComma (p, _pEnd))
return false;
// The ellipsoid semi-major axis.
double fA = 0;
if (! ParseReal (p, _pEnd, & p, fA))
return false;
if (::fabs (fA - 6400000) > 500000)
ReportWarning (m_cOffset, "The semi-major axis is expected to be about 6400000 m.");
if (! OmitComma (p, _pEnd))
return false;
// The ellipsoid flattening.
double fInvFlattening = 0;
if (! ParseReal (p, _pEnd, & p, fInvFlattening))
return false;
if (::fabs (fInvFlattening - 300) > 10)
ReportWarning (m_cOffset, "The inverse flattening is expected to be about 300.");
CEllipsoid e (NULL, fA, 1/fInvFlattening);
m_pDatumTransformation.reset (new CMolodenskyTransformation (e, c_eWGS84, fDX, fDY, fDZ));
return true;
}
bool CTxtLoader::ParseType (const char * _pValue, const char * _pEnd, const char ** _ppEnd, unsigned long & _ulType) {
const char * p = _pValue;
// Omit spaces.
while (p < _pEnd && * p == ' ')
++ p;
if (p + 1 < _pEnd && p [0] == '0' && (p [1] == 'x' || p [1] == 'X'))
return ParseHex (p + 2, _pEnd, _ppEnd, _ulType);
else
return ParseDecU (p, _pEnd, _ppEnd, _ulType);
}
bool CTxtLoader::ParseReal (const char * _pValue, const char * _pEnd, const char ** _ppEnd, double & _fRet) {
double r = 0;
bool bMinus = false;
bool bHasDigits = false;
const char * p = _pValue;
// Get sign.
if (p < _pEnd && * p == '-') {
++ p;
bMinus = true;
}
// Get whole part of the digit.
while (p < _pEnd && '0' <= * p && * p <= '9') {
r *= 10;
r += (* p) - '0';
bHasDigits = true;
++ p;
}
// Get decimal dot.
if (p < _pEnd && * p != '.') {
* _ppEnd = p;
_fRet = bMinus ? -r : r;
return bHasDigits;
}
++ p;
const char * pFraction = p;
// Get fractional part of the digit.
double f = 0;
double pw = 1;
while (p < _pEnd && '0' <= * p && * p <= '9') {
f *= 10;
f += ((* p) - '0');
pw *= 10;
bHasDigits = true;
++ p;
}
// Update max precision.
if ((int) m_cPrecOrder < p - pFraction)
m_cPrecOrder = p - pFraction;
* _ppEnd = p;
_fRet = bMinus ? -(r + f/pw) : (r + f/pw);
return bHasDigits;
}
bool CTxtLoader::ParsePoint (const char * _pValue, const char * _pEnd, point_t & _pt, const char ** _ppEnd) {
const char * p = _pValue;
// Omit spaces.
while (p < _pEnd && * p == ' ')
++ p;
// Get opening bracket.
if (p >= _pEnd || * p != '(') {
* _ppEnd = _pEnd;
return false;
}
++ p;
while (p < _pEnd && * p == ' ')
++ p;
// Get latitude.
if (! ParseReal (p, _pEnd, & p, _pt.y)) {
ReportWarning (m_cOffset, "Latitude value is expected. The point will be ignored.");
* _ppEnd = _pEnd;
return false;
}
// Omit spaces.
while (p < _pEnd && * p == ' ')
++ p;
// Get delimiting comma.
if (p >= _pEnd || * p != ',') {
ReportWarning (m_cOffset, "Comma between latitude and longitude is expected. The point will be ignored.");
* _ppEnd = _pEnd;
return false;
}
++ p;
// Omit spaces.
while (p < _pEnd && * p == ' ')
++ p;
// Get longitude.
if (! ParseReal (p, _pEnd, & p, _pt.x)) {
ReportWarning (m_cOffset, "Longitude value is expected. The point will be ignored.");
* _ppEnd = _pEnd;
return false;
}
// Omit spaces.
while (p < _pEnd && * p == ' ')
++ p;
// Get closing bracket.
if (p >= _pEnd || * p != ')') {
ReportWarning (m_cOffset, "Closing bracket for point is expected. The point will be ignored.");
* _ppEnd = _pEnd;
return false;
}
++ p;
* _ppEnd = p;
// Check coordinates.
if (90 <= _pt.y || _pt.y <= -90) {
ReportWarning (m_cOffset, "Invalid latitude value: %0.5f. The point will be ignored.", _pt.y);
return false;
}
if (200 < _pt.x || _pt.x < -200) {
ReportWarning (m_cOffset, "Invalid longitude value: %0.5f. The point will be ignored.", _pt.x);
return false;
}
return true;
}
void CTxtLoader::ParsePoints (const char * _pValue, const char * _pEnd, points_t & _points) {
for (const char * p = _pValue; p < _pEnd; ++ p) {
point_t pt;
if (ParsePoint (p, _pEnd, pt, & p))
_points.push_back (pt);
// Get point-delimiting comma.
while (p < _pEnd && * p != ',')
++ p;
}
}
bool CTxtLoader::ParseRouteParam (const char * _pValue, const char * _pEnd, rgn_extra_t & _extra) {
const char * p = _pValue;
// Speed limit.
unsigned long ulSpeedLimit = 0;
if (! ParseDecU (p, _pEnd, & p, ulSpeedLimit))
return false;
if (ulSpeedLimit > 7) {
ReportWarning (m_cOffset, "'RouteParam' - unexpected value for speed limit. Reset to 7 (no limit).");
ulSpeedLimit = 7;
}
if (! OmitComma (p, _pEnd))
return false;
// Route class.
unsigned long ulRouteClass = 0;
if (! ParseDecU (p, _pEnd, & p, ulRouteClass))
return false;
if (ulRouteClass > 4) {
ReportWarning (m_cOffset, "'RouteParam' - unexpected value for route class. Reset to 4.");
ulRouteClass = 4;
}
if (! OmitComma (p, _pEnd))
return false;
// One way.
const bool bOneWay = * (p ++) != '0';
if (! OmitComma (p, _pEnd))
return false;
// Toll.
const bool bToll = * (p ++) != '0';
if (! OmitComma (p, _pEnd))
return false;
// No emergency.
const bool bNoEmergency = * (p ++) != '0';
if (! OmitComma (p, _pEnd))
return false;
// No delivery.
const bool bNoDelivery = * (p ++) != '0';
if (! OmitComma (p, _pEnd))
return false;
// No car.
const bool bNoCar = * (p ++) != '0';
if (! OmitComma (p, _pEnd))
return false;
// No bus.
const bool bNoBus = * (p ++) != '0';
if (! OmitComma (p, _pEnd))
return false;
// No taxi.
const bool bNoTaxi = * (p ++) != '0';
if (! OmitComma (p, _pEnd))
return false;
// No pedestrian.
const bool bNoPedestrian = * (p ++) != '0';
if (! OmitComma (p, _pEnd))
return false;
// No bicycle.
const bool bNoBicycle = * (p ++) != '0';
if (! OmitComma (p, _pEnd))
return false;
// No truck.
const bool bNoTruck = * (p ++) != '0';
_extra.fSpeedLimit = ulSpeedLimit;
_extra.fRouteClass = ulRouteClass;
_extra.bOneWay = bOneWay;
_extra.bToll = bToll;
_extra.bNoEmergency = bNoEmergency;
_extra.bNoDelivery = bNoDelivery;
_extra.bNoCar = bNoCar;
_extra.bNoBus = bNoBus;
_extra.bNoTaxi = bNoTaxi;
_extra.bNoPedestrian = bNoPedestrian;
_extra.bNoBicycle = bNoBicycle;
_extra.bNoTruck = bNoTruck;
return true;
}
bool CTxtLoader::ParseEntryPoint (const char * _pValue, const char * _pEnd, rgn_extra_t & _extra) {
_extra.bEntryPointDefined = true;
const char * pEnd;
return ParsePoint (_pValue, _pEnd, _extra.ptEntryPoint, &pEnd);
}
void CTxtLoader::AssignCity (rgn_t & _rgn) {
if (m_strCityName.empty ()) {
if (m_strDefaultCityName.empty ())
return;
m_strCityName = m_strDefaultCityName;
}
_rgn.GetExtra ().pCity = _GetCity (m_strCityName, m_strRegionName, m_strCountryName, true);
m_strCityName .clear ();
m_strRegionName .clear ();
m_strCountryName.clear ();
}
void CTxtLoader::_BuildFullCityName (const std::string & _strCityName, std::string & _strRegionName, std::string & _strCountryName, std::string & _strFullName) {
_strFullName = _strCityName;
if (_strRegionName.empty ())
_strRegionName = m_strDefaultRegionName;
if (! _strRegionName.empty ()) {
_strFullName.append (1, '|');
_strFullName.append (_strRegionName);
}
if (_strCountryName.empty ())
_strCountryName = m_strDefaultCountryName;
if (! _strCountryName.empty ()) {
_strFullName.append (1, '|');
_strFullName.append (_strCountryName);
}
}
city_t * CTxtLoader::_GetCity (const std::string & _strCityName, std::string & _strRegionName, std::string & _strCountryName, bool _bStrict) {
if (m_name2city.empty () && ! m_pMap->Cities.empty ()) {
// Fill m_name2city with data previously loaded from [CITIES].
for (cities_t::iterator cti = m_pMap->Cities.begin (); cti != m_pMap->Cities.end (); ++ cti) {
city_t & city = * cti;
if (city.IsDeleted ())
continue;
std::string strRegionName = city.pRegion->strName;
if (! city.pRegion->strAbbrevName.empty ()) {
strRegionName.append (c_strAbbrevDelimiter);
strRegionName.append (city.pRegion->strAbbrevName);
}
std::string strCountryName = city.pRegion->pCountry->strName;
if (! city.pRegion->pCountry->strAbbrevName.empty ()) {
strCountryName.append (c_strAbbrevDelimiter);
strCountryName.append (city.pRegion->pCountry->strAbbrevName);
}
std::string strFullName;
_BuildFullCityName (city.strName, strRegionName, strCountryName, strFullName);
m_name2city.insert (name2city_t::value_type (strFullName, & city));
}
}
std::string strFullName;
_BuildFullCityName (_strCityName, _strRegionName, _strCountryName, strFullName);
if (strFullName.empty () || _strRegionName.empty () || _strCountryName.empty ())
return NULL;
const name2city_t::const_iterator i = m_name2city.find (strFullName);
if (i != m_name2city.end ())
return i->second;
bool bFullNameIsValid = true;
// Find country.
std::string strCountryName, strCountryAbbrevName;
_ParseAbbrevName (_strCountryName.c_str (), _strCountryName.c_str () + _strCountryName.size (), strCountryName, strCountryAbbrevName);
country_t * pCountry = NULL;
for (countries_t::iterator ci = m_pMap->Countries.begin (); ci != m_pMap->Countries.end (); ++ ci) {
country_t & country = * ci;
if (country.IsDeleted ())
continue;
if (country.strName == strCountryName && country.strAbbrevName == strCountryAbbrevName) {
pCountry = & country;
break;
}
}
if (pCountry == NULL && ! _bStrict && strCountryAbbrevName.empty ()) {
// Find country, non strict.
for (countries_t::iterator ci = m_pMap->Countries.begin (); ci != m_pMap->Countries.end (); ++ ci) {
country_t & country = * ci;
if (country.IsDeleted ())
continue;
if (country.strName == strCountryName) {
pCountry = & country;
bFullNameIsValid = false;
break;
}
}
}
if (pCountry == NULL) {
// Create country.
m_pMap->Countries.push_back (country_t ());
pCountry = & m_pMap->Countries.back ();
pCountry->strName .swap (strCountryName);
pCountry->strAbbrevName.swap (strCountryAbbrevName);
}
// Find region.
std::string strRegionName, strRegionAbbrevName;
_ParseAbbrevName (_strRegionName.c_str (), _strRegionName.c_str () + _strRegionName.size (), strRegionName, strRegionAbbrevName);
region_t * pRegion = NULL;
for (regions_t::iterator ri = m_pMap->Regions.begin (); ri != m_pMap->Regions.end (); ++ ri) {
region_t & region = * ri;
if (region.IsDeleted ())
continue;
if (region.strName == strRegionName && region.strAbbrevName == strRegionAbbrevName && region.pCountry == pCountry) {
pRegion = & region;
break;
}
}
if (pRegion == NULL && ! _bStrict && strCountryAbbrevName.empty ()) {
// Find region, non strict.
for (regions_t::iterator ri = m_pMap->Regions.begin (); ri != m_pMap->Regions.end (); ++ ri) {
region_t & region = * ri;
if (region.IsDeleted ())
continue;
if (region.strName == strRegionName && region.pCountry == pCountry) {
pRegion = & region;
bFullNameIsValid = false;
break;
}
}
}
if (pRegion == NULL) {
// Create region.
m_pMap->Regions.push_back (region_t ());
pRegion = & m_pMap->Regions.back ();
pRegion->pCountry = pCountry;
pRegion->strName .swap (strRegionName);
pRegion->strAbbrevName.swap (strRegionAbbrevName);
}
// Rebuild full name, if required (due to non-strict search).
if (! bFullNameIsValid) {
strRegionName = pRegion->strName;
if (! pRegion->strAbbrevName.empty ()) {
strRegionName.append (c_strAbbrevDelimiter);
strRegionName.append (pRegion->strAbbrevName);
}
strCountryName = pCountry->strName;
if (! pCountry->strAbbrevName.empty ()) {
strCountryName.append (c_strAbbrevDelimiter);
strCountryName.append (pCountry->strAbbrevName);
}
_BuildFullCityName (_strCityName, strRegionName, strCountryName, strFullName);
const name2city_t::const_iterator i = m_name2city.find (strFullName);
if (i != m_name2city.end ())
return i->second;
}
// Create city.
m_pMap->Cities.push_back (city_t ());
city_t & city = m_pMap->Cities.back ();
city.strName = _strCityName;
city.pRegion = pRegion;
m_name2city.insert (name2city_t::value_type (strFullName, & city));
return & city;
}
void CTxtLoader::AddRgn (SectionType _gt, RGN_KIND _Kind, const char * _p) {
if (! m_bHeader)
ReportWarning (m_cOffset, "[IMG ID] section should be defined first.");
m_GroupType = _gt;
m_Kind = _Kind;
// Create new rgn.
rgn_t & rgn = m_pMap->CreateFeature (_Kind);
rgn.pFileRef = m_pFileRef;
rgn.cBeginPos = m_cObjectBegin == -1 ? m_cOffset : m_cObjectBegin;
rgn.cFileLine = m_cFileLine;
// rgn.cOrdinal = m_cOrdinal ++;
rgn.strComment.swap (m_strComment);
}
void CTxtLoader::DetectHoles (rgn_elements_t & _elements) {
size_t cOuterElement = 0;
const size_t cElements = _elements.size ();
for (size_t cElement = 0; cElement < cElements; ++ cElement) {
rgn_element_t & element = _elements [cElement];
const points_t & points = element.points;
const size_t cPoints = points.size ();
// NOTE: count element's area before 'holes' detection.
element.fLengthOrArea = GetArea (points);
if (cElement > 0 && cPoints >= 3) {
if (element.IsHoleOf (_elements [cOuterElement])) {
element.bHole = true;
} else {
element.bHole = false;
cOuterElement = cElement;
}
} else
element.bHole = false;
}
}
rgnode_t * CTxtLoader::ParseRGNode (const char * _pLine, const char * _pNextLine, const char * & _p, size_t _cPoints, size_t & _cPoint) {
unsigned long ulPoint = 0;
if (! ParseDecU (_p, _pNextLine, & _p, ulPoint)) {
ReportWarning (m_cOffset, "Unexpected point index.");
return NULL;
}
if (ulPoint >= _cPoints) {
ReportWarning (m_cOffset, "Unexpected index of point.");
return NULL;
}
OmitComma (_p, _pNextLine);
unsigned long ulNodeID = 0;
if (! ParseDecU (_p, _pNextLine, & _p, ulNodeID)) {
ReportWarning (m_cOffset, "Unexpected node ID.");
return NULL;
}
bool bIsExternal = false;
if (OmitComma (_p, _pNextLine)) {
unsigned long ulIsExternal = 0;
if (ParseDecU (_p, _pNextLine, & _p, ulIsExternal))
bIsExternal = ulIsExternal != 0;
else
ReportWarning (m_cOffset, "Unexpected format of 'NodX'.");
}
rgnode_t * const pNode = GetRGNode (ulNodeID);
assert (pNode != NULL);
if (pNode != NULL)
pNode->bIsExternal = bIsExternal;
_cPoint = ulPoint;
return pNode;
}
static
void _FindNextDelimiter (const char * & _p, const char * _pNextLine) {
while (_p < _pNextLine && * _p != ',' && * _p != ')' && * _p != '\r' && * _p != '\n')
++ _p;
}
static
bool _ParseNumber (const char * & _p, const char * _pEnd, unsigned long & _ulNumber) {
if (_p [0] == '-') {
++ _p;
_FindNextDelimiter (_p, _pEnd);
_ulNumber = 0;
return true;
}
if (! ParseDecU (_p, _pEnd, & _p, _ulNumber))
return false;
return true;
}
void CTxtLoader::ParseNumbers (const char * _pLine, const char * _pNextLine, const char * & _p, size_t _cElement) {
if (m_elements.empty ())
return;
const size_t cPoints = m_elements [_cElement].points.size ();
// Point.
unsigned long ulPoint = 0;
if (! ParseDecU (_p, _pNextLine, & _p, ulPoint)) {
ReportWarning (m_cOffset, "Unexpected point index.");
return;
}
if (ulPoint >= cPoints) {
ReportWarning (m_cOffset, "Unexpected index of point.");
return;
}
point_extras_t & PointExtras = m_elements [_cElement].GetExtra ().PointExtras;
if (cPoints >= PointExtras.size ())
PointExtras.resize (cPoints);
numbers_t & Numbers = PointExtras [ulPoint].Numbers;
OmitComma (_p, _pNextLine);
// Left parity.
switch (* _p) {
case 'N':
case 'n': Numbers.wLeftParity = 0; break;
case 'E':
case 'e': Numbers.wLeftParity = 1; break;
case 'O':
case 'o': Numbers.wLeftParity = 2; break;
case 'B':
case 'b': Numbers.wLeftParity = 3; break;
default:
ReportWarning (m_cOffset, "Unexpected format.");
return;
}
++ _p;
OmitComma (_p, _pNextLine);
// Left from.
unsigned long ulLeftFrom = 0;
if (! _ParseNumber (_p, _pNextLine, ulLeftFrom)) {
ReportWarning (m_cOffset, "Unexpected format.");
return;
}
Numbers.wLeftAfter = ulLeftFrom;
OmitComma (_p, _pNextLine);
// Left to.
unsigned long ulLeftTo = 0;
if (! _ParseNumber (_p, _pNextLine, ulLeftTo)) {
ReportWarning (m_cOffset, "Unexpected format.");
return;
}
Numbers.wLeftBefore = ulLeftTo; // NOTE: to be copied to previous node later.
Numbers.bHasNumbers = 1;
OmitComma (_p, _pNextLine);
// Right parity.
switch (* _p) {
case 'N':
case 'n': Numbers.wRightParity = 0; break;
case 'E':
case 'e': Numbers.wRightParity = 1; break;
case 'O':
case 'o': Numbers.wRightParity = 2; break;
case 'B':
case 'b': Numbers.wRightParity = 3; break;
default:
ReportWarning (m_cOffset, "Unexpected format.");
return;
}
++ _p;
OmitComma (_p, _pNextLine);
// Right from.
unsigned long ulRightFrom = 0;
if (! _ParseNumber (_p, _pNextLine, ulRightFrom)) {
ReportWarning (m_cOffset, "Unexpected format.");
return;
}
Numbers.wRightAfter = ulRightFrom;
OmitComma (_p, _pNextLine);
// Right to.
unsigned long ulRightTo = 0;
if (! _ParseNumber (_p, _pNextLine, ulRightTo)) {
ReportWarning (m_cOffset, "Unexpected format.");
return;
}
Numbers.wRightBefore = ulRightTo; // NOTE: to be copied to previous node later.
OmitComma (_p, _pNextLine);
// Left zip.
const char * const strZipLeft = _p;
_FindNextDelimiter (_p, _pNextLine);
Numbers.pZipLeftAfter = _GetZip (strZipLeft, _p - strZipLeft);
OmitComma (_p, _pNextLine);
// Right zip.
const char * const strZipRight = _p;
_FindNextDelimiter (_p, _pNextLine);
Numbers.pZipRightAfter = _GetZip (strZipRight, _p - strZipRight);
OmitComma (_p, _pNextLine);
// Left city.
Numbers.pCityLeftAfter = _GetCity (_p, _pNextLine);
OmitComma (_p, _pNextLine);
// Right city.
Numbers.pCityRightAfter = _GetCity (_p, _pNextLine);
}
void CTxtLoader::ParseHLevel (const char * _pLine, const char * _pNextLine, const char * & _p, size_t _cElement) {
if (m_elements.empty ())
return;
const size_t cPoints = m_elements [_cElement].points.size ();
// Point.
unsigned long ulPoint = 0;
if (! ParseDecU (_p, _pNextLine, & _p, ulPoint)) {
ReportWarning (m_cOffset, "Unexpected point index.");
return;
}
if (ulPoint >= cPoints) {
ReportWarning (m_cOffset, "Unexpected index of point.");
return;
}
point_extras_t & pointExtras = m_elements [_cElement].GetExtra ().PointExtras;
if (cPoints >= pointExtras.size ())
pointExtras.resize (cPoints);
OmitComma (_p, _pNextLine);
bool bHasHLevel = false;
signed char nHLevel = 0;
double temp = 0;
if (::ParseReal (_p, _pNextLine, & _p, temp)) {
nHLevel = signed char (fast_floor (temp + .5f));
bHasHLevel = true;
} else
ReportWarning (m_cOffset, "Unexpected 3D-level value.");
if (bHasHLevel)
pointExtras [ulPoint].SetHLevel (nHLevel);
}
void CTxtLoader::UpdateNumbers (rgn_t & _rgn) {
assert (_rgn.GetKind () == m_Kind);
if (_rgn.GetKind () != rkPolyline)
return;
const size_t cElements = _rgn.elements.size ();
for (size_t cElement = 0; cElement < cElements; ++ cElement) {
rgn_element_t & element = _rgn.elements [cElement];
if (! element.HasExtra ())
continue;
point_extras_t & PointExtras = element.GetExtra ().PointExtras;
if (! HasNumbers (PointExtras))
continue;
const int nPoints = (int) PointExtras.size ();
if (nPoints == 0)
continue;
numbers_t * pNextNumbers = NULL;
for (int nPoint = nPoints - 1; nPoint >= 0; -- nPoint) {
numbers_t & Numbers = PointExtras [nPoint].Numbers;
if (! Numbers.bHasNumbers && nPoint != nPoints - 1)
continue;
if (pNextNumbers) {
pNextNumbers->wLeftBefore = Numbers.wLeftBefore;
pNextNumbers->wRightBefore = Numbers.wRightBefore;
}
pNextNumbers = & Numbers;
}
numbers_t & NumbersFirst = PointExtras [0].Numbers;
NumbersFirst.wLeftBefore = 0;
NumbersFirst.wRightBefore = 0;
numbers_t & NumbersLast = PointExtras [nPoints - 1].Numbers;
NumbersLast.bHasNumbers = true;
NumbersLast.wLeftParity = 0;
NumbersLast.wRightParity = 0;
}
}
city_t * CTxtLoader::_GetCity (const char * & _p, const char * _pNextLine) {
// City.
const char * const strCity0 = _p;
_FindNextDelimiter (_p, _pNextLine);
if (_p == strCity0 + 2 && strCity0 [0] == '-' && strCity0 [1] == '1')
return NULL;
std::string strCity (strCity0, _p);
OmitComma (_p, _pNextLine);
// Region.
const char * const strRegion0 = _p;
_FindNextDelimiter (_p, _pNextLine);
std::string strRegion (strRegion0, _p);
OmitComma (_p, _pNextLine);
// Country.
const char * const strCountry0 = _p;
_FindNextDelimiter (_p, _pNextLine);
std::string strCountry (strCountry0, _p);
OmitComma (_p, _pNextLine);
return _GetCity (strCity, strRegion, strCountry, false);
}
A ma być to wczytywanie map wektorowych czy co stakiego!
d41d8cd98f00b204e9800998ecf8427e
-
-
-
Wszyscy czytają "twój" kod i myślę, że całkiem za darmo na jutro będziesz miał tutaj 5 gotowych rozwiązań.
Jak ty nie potrafisz użyć choćby nopaste, to i przy zadaniu, w którym sam nie wiesz co masz zrobić nikt ci nie pomoże raczej,
d41d8cd98f00b204e9800998ecf8427e
-
-
-
Ale moze ktoś by mógł wyjaśnić szczególowo jak sie wczytuje pliki, mapy itp. musi dać sie to wyjasnic i nauczyc.
d41d8cd98f00b204e9800998ecf8427e
-
-
-
Człowieku! Czy ty słyszałeś kiedyś o serwisach w rodzaju wklej.org? Odechciewa się pomagać ludziom, którzy potrafią wstawić kilka ekranów kodu żywcem w poście. Do tego trzeba było pokazać tylko te fragmenty kodu, w których tkwi problem, a nie cały kod.
d41d8cd98f00b204e9800998ecf8427e
-
-
-
Heh kolega Miluszek chcialby pomocy lecz nie wie w czym O_O
Stary idea wczytywania czegos z pliku jest latwa wiec nie trzeba tego tlumaczyc osobno do wszystkich rzeczy ktore mozna z niego wczytac najpierw zacznij od poczytania co to sa mapy etc. bo wnioskuje ze nie wiesz a pozniej zastanow sie jak to wczytac korzystajac z linkow podanych przez kolegow.
d41d8cd98f00b204e9800998ecf8427e
Powered by phpBB modified by Przemo © 2003 phpBB Group. Then, after many years modified again, this time by Piotrek © 2014 Strona wygenerowana w 23,4ms. Zapytań do SQL: 16
|