Esempio n. 1
0
		boost::shared_ptr<LineString> Edge::getRealGeometry(
		) const	{
			if(getGeometry().get())
			{
				return getGeometry();
			}

			assert(getFromVertex());
			const GeometryFactory& geometryFactory(
				CoordinatesSystem::GetDefaultGeometryFactory()
			);

			if(	getParentPath() &&
				getParentPath()->getEdge(getRankInPath()) == this &&
				getParentPath()->getEdges().size() > getRankInPath()+1 &&
				getFromVertex()->hasGeometry() &&
				getParentPath()->getEdge(getRankInPath() + 1)->getFromVertex()->hasGeometry()
			){
				CoordinateSequence* cs(geometryFactory.getCoordinateSequenceFactory()->create(0, 2));
				cs->add(*getFromVertex()->getGeometry()->getCoordinate(), false);
				cs->add(*getParentPath()->getEdge(getRankInPath() + 1)->getFromVertex()->getGeometry()->getCoordinate(), false);
				if(cs->size() != 2)
				{
					return boost::shared_ptr<LineString>();
				}
				else
				{
					return boost::shared_ptr<LineString>(geometryFactory.createLineString(cs));
				}
			}

			return boost::shared_ptr<LineString>(geometryFactory.createLineString());
		}
Esempio n. 2
0
bool FileUtils::hasParentDirectory(const QString & path)
{
    QString parentPath = getParentPath(path);

    if (parentPath.length() > 0)
    {
        QDir parentDir(parentPath);
        return parentDir.exists();
    }

    return false;
}
Esempio n. 3
0
bool CCUtils::createIntermediateFolders(string path) {
	string parent = getParentPath(path);
	bool exist = isPathExistent(parent);
	bool success = true;
	if(!exist) {
		createIntermediateFolders(parent);
		success = createFolder(parent);
	}
	
	// return success flag
	return success;
}
Esempio n. 4
0
const Location &Location::getParent() const {
	if ( mData->mParent.isNull() ) {
		QString path = getParentPath();

		// If the path is empty, it's a New File, so just return a copy of this Location
		if ( path.isEmpty() ) {
			mData->mParent = Location( *this );
		} else {
			mData->mParent = Location( path );
		}
	}

	return mData->mParent;
}
Esempio n. 5
0
std::string Path::resolveSymlinks(const std::string &path)
{
    /* Does not fully resolve the path like realpath/boost::canonical would.
     * It doesn't resolve path elements (including "." or ".."), but only
     * resolves the entire path (it does that recursively). */
    std::string result(path);
#ifndef GMX_NATIVE_WINDOWS
    char        buf[GMX_PATH_MAX];
    int         length;
    while ((length = readlink(result.c_str(), buf, sizeof(buf)-1)) > 0)
    {
        buf[length] = '\0';
        if (isAbsolute(buf))
        {
            result = buf;
        }
        else
        {
            result = join(getParentPath(result), buf);
        }
    }
#endif
    return result;
}
Esempio n. 6
0
bool FileUtils::createParentDirectory(const QString & path)
{
    QString parentPath = getParentPath(path);
    QDir parentDir;
    return parentDir.mkpath(parentPath);
}
Esempio n. 7
0
		void Edge::_updateServiceIndex(
			bool RTData
		) const {

			boost::recursive_mutex::scoped_lock lock(_indexMutex);
			boost::shared_lock<util::shared_recursive_mutex> sharedServicesLock(
						*getParentPath()->sharedServicesMutex
			);

			const ServiceSet& services(getParentPath()->getServices());
			size_t numHour;

			// Reset
			for ( numHour = 0; numHour < INDICES_NUMBER; ++numHour)
			{
				_departureIndex[numHour].set(RTData, services.end());
				_arrivalIndex[numHour].set(RTData, services.rend());
			}
			if(RTData)
			{
				_RTserviceIndexUpdateNeeded = false;
			}
			else
			{
				_serviceIndexUpdateNeeded = false;
			}

			if(services.empty()) return;

			// Departures
			for(ServiceSet::const_iterator it(services.begin()); it!=services.end(); ++it)
			{
				const Service* service = *it;
				time_duration endHour(service->getDepartureEndScheduleToIndex(RTData, getRankInPath()));
				size_t endHours(std::min((size_t)endHour.hours(), (size_t)23));
				time_duration beginHour(service->getDepartureBeginScheduleToIndex(RTData, getRankInPath()));

				for (numHour = 0; numHour <= endHours; ++numHour)
				{
					if(	_departureIndex[numHour].get(RTData) == services.end() ||
						(*_departureIndex[numHour].get(RTData)) \
							->getDepartureBeginScheduleToIndex(RTData, getRankInPath()) > endHour
					){
						_departureIndex[numHour].set(RTData, it);
					}
				}
				if (endHour < beginHour)
				{
					for (numHour = endHours; numHour < 24; ++numHour)
					{
						if(	_departureIndex[numHour].get(RTData) == services.end())
						{
							_departureIndex[numHour].set(RTData, it);
						}
					}
				}
			}

			// Arrivals
			for(ServiceSet::const_reverse_iterator it(services.rbegin()); it != services.rend(); ++it)
			{
				const Service* service = *it;
				time_duration endHour(service->getArrivalEndScheduleToIndex(RTData, getRankInPath()));
				time_duration beginHour(service->getArrivalBeginScheduleToIndex(RTData, getRankInPath()));
				size_t beginHours(std::min((size_t)beginHour.hours(), (size_t)23));

				for (numHour = 23; numHour >= beginHours; --numHour)
				{
					if(	_arrivalIndex[numHour].get(RTData) == services.rend()	||
						(*_arrivalIndex[numHour].get(RTData))->getArrivalBeginScheduleToIndex(RTData, getRankInPath()) < beginHour
					){
						_arrivalIndex[numHour].set(RTData, it);						
					}
					if(numHour == 0) break;
				}
				if (endHour < beginHour)
				{
					for (numHour = endHour.hours(); true; --numHour)
					{
						if(	_arrivalIndex[numHour].get(RTData) == services.rend())
						{
							_arrivalIndex[numHour].set(RTData, it);
						}
						if(numHour == 0) break;
					}
				}
			}
		}
Esempio n. 8
0
		ServicePointer Edge::getPreviousService(const AccessParameters& accessParameters,
			ptime arrivalMoment,
			const ptime& minArrivalMoment,
			bool checkIfTheServiceIsReachable,
			optional<ArrivalServiceIndex::Value>& maxPreviousServiceIndex,
			bool inverted,
			bool ignoreReservation,
			bool allowCanceled,
			bool enableTheoretical,
			bool enableRealTime
		) const {
			boost::shared_lock<util::shared_recursive_mutex> sharedServicesLock(
						*getParentPath()->sharedServicesMutex
			);
			const ServiceSet& services(getParentPath()->getServices());

			if(services.empty())
			{
				return ServicePointer();
			}

			bool RTData(enableRealTime && arrivalMoment < posix_time::second_clock().local_time() + posix_time::hours(23));

			ArrivalServiceIndex::Value previous(getArrivalFromIndex(RTData, arrivalMoment.time_of_day().hours()));

			if(	maxPreviousServiceIndex &&
				(*maxPreviousServiceIndex == services.rend() || services.value_comp()(**maxPreviousServiceIndex, *previous))
			){
				previous = *maxPreviousServiceIndex;
			}

			while ( arrivalMoment >= minArrivalMoment )  // Loop over dates
			{
				if(	getParentPath()->isActive(arrivalMoment.date()))
				{
					for (; previous != services.rend(); ++previous)  // Loop over services
					{
						// Saving of the used service
						ServicePointer servicePointer(
							(*previous)->getFromPresenceTime(
								accessParameters,
								enableTheoretical,
								RTData,
								false,
								*this,
								arrivalMoment,
								checkIfTheServiceIsReachable,
								inverted,
								ignoreReservation,
								allowCanceled
							)
						);

						if (!servicePointer.getService())
							continue;

						// Check of validity of departure date time
						if (servicePointer.getArrivalDateTime() + servicePointer.getServiceRange() < minArrivalMoment)
						{
							return ServicePointer();
						}

						// Limitation of the continuous service range at the specified bounds
						if(servicePointer.getArrivalDateTime() < minArrivalMoment)
						{
							time_duration toShift(minArrivalMoment - servicePointer.getArrivalDateTime());
							servicePointer.shift(toShift);
							servicePointer.setServiceRange(servicePointer.getServiceRange() - toShift);
						}

						// Store service rank in edge
						maxPreviousServiceIndex = previous;

						// The service is now returned
						return servicePointer;
				}	}

				arrivalMoment = ptime(arrivalMoment.date(), -seconds(1));
				previous = _arrivalIndex[INDICES_NUMBER - 1].get(RTData);
			}

			return ServicePointer();
		}
Esempio n. 9
0
		ServicePointer Edge::getNextService(const AccessParameters& accessParameters,
			ptime departureMoment,
			const ptime& maxDepartureMoment,
			bool checkIfTheServiceIsReachable,
			optional<DepartureServiceIndex::Value>& minNextServiceIndex,
			bool inverted,
			bool ignoreReservation,
			bool allowCanceled,
			bool enableTheoretical,
			bool enableRealTime
		) const	{
			boost::shared_lock<util::shared_recursive_mutex> sharedServicesLock(
						*getParentPath()->sharedServicesMutex
			);
			const ServiceSet& services(getParentPath()->getServices());

			if(services.empty() || (!enableTheoretical && !enableRealTime))
			{
				return ServicePointer();
			}

			bool RTData(enableRealTime && departureMoment < posix_time::second_clock().local_time() + posix_time::hours(23));

			// Search schedule
			DepartureServiceIndex::Value next(getDepartureFromIndex(RTData, departureMoment.time_of_day().hours()));

			if(	minNextServiceIndex &&
				(*minNextServiceIndex == services.end() || services.value_comp()(*next, **minNextServiceIndex))
			){
				next = *minNextServiceIndex;
			}

			while ( departureMoment <= maxDepartureMoment )  // boucle sur les dates
			{
				// Look in schedule for when the line is in service
				if(	getParentPath()->isActive(departureMoment.date()))
				{
					for (; next != services.end(); ++next)  // boucle sur les services
					{
						// Saving of the used service
						ServicePointer servicePointer(
							(*next)->getFromPresenceTime(
								accessParameters,
								enableTheoretical,
								RTData,
								true,
								*this,
								departureMoment,
								checkIfTheServiceIsReachable,
								inverted,
								ignoreReservation,
								allowCanceled
							)
						);

						if (!servicePointer.getService())
							continue;

						// Check of validity of departure date time
						if (servicePointer.getDepartureDateTime() > maxDepartureMoment )
						{
							return ServicePointer();
						}

						// Limitation of the continuous service range at the specified bounds
						if(servicePointer.getDepartureDateTime() + servicePointer.getServiceRange() > maxDepartureMoment)
						{
							servicePointer.setServiceRange(maxDepartureMoment - servicePointer.getDepartureDateTime());
						}

						// Store the service rank in edge
						minNextServiceIndex = next;

						// The service is now returned
						return servicePointer;
				}	}

				if (departureMoment.time_of_day().hours() < 3)
					departureMoment = ptime(departureMoment.date(), hours(3));
				else
					departureMoment = ptime(departureMoment.date(), hours(27));

				next = _departureIndex[0].get(RTData);
			}

			return ServicePointer();
		}
Esempio n. 10
0
std::string getThisDllFolder()
{
    std::string dll = getThisDllPath();

    return dll.empty() ? "" : getParentPath(dll);
}
Esempio n. 11
0
//接收文件夹
int getDir(void *option, gsNode *gList)
{
  int sockfd, readBytes, headerSize, fileType, dirDepth=0, tmp;
  char buf[COMLEN], recvs[RECFRG], hSize[HSIZE], fullPath[2*FILENAME];
  filenode *head = (filenode*)option, *cur, fn;
  command com;
  struct sockaddr_in peer;
  long  offset=0, fileSize;
  FILE* recvFile;

  strncpy(fullPath, gList->targetDir, sizeof(fullPath));

  initCommand(&com, IPMSG_GETDIRFILES); //Direcotry

  snprintf(com.additional, MSGLEN, "%x:%x:%x", gList->packetNo, head->fileNo, offset);

  sockfd = socket(AF_INET, SOCK_STREAM, 0);

  bzero(&peer, sizeof(peer));
  peer.sin_family = AF_INET;
  peer.sin_port = htons(IPMSG_DEFAULT_PORT);
  memcpy(&peer.sin_addr, &gList->peer.sin_addr, sizeof(peer.sin_addr));

  if (connect(sockfd, (struct sockaddr*)&peer, sizeof(peer))<0)
  {
    printf("File connect error.\n");
    return -1;
  }

  msgCreater(buf, &com, sizeof(buf));

  if (writen(sockfd, buf, strlen(buf)+1)<0)
    return -1;

  do
  {
    tmp = strlen(fullPath);
    if (tmp+1>=sizeof(fullPath))
    {
      printf("getDir: target directory is too lang.\n");
      return -1;
    }
    if (fullPath[tmp-1]!='/')
    {
      fullPath[tmp] = '/';
      fullPath[tmp+1] = '\0';
    }

    readBytes = readDelimiter(sockfd, hSize, HSIZE, ':');
    sscanf(hSize, "%x", &headerSize);
    if (headerSize<=0 || headerSize<=readBytes || headerSize>RECFRG) //保护、防止溢出
      return -1;
    readn(sockfd, recvs, headerSize-readBytes);
    recvs[headerSize-readBytes]='\0';

    if (parseHeader(&fn, recvs)<0)
    {
      printf("getDir: Parse protocol failed.\n");
      return -1;
    }

    switch (fn.fileType & 0x03)
    {
    case IPMSG_FILE_REGULAR:

      strncat(fullPath, fn.fileName, sizeof(fullPath)-tmp-1);
      if ((recvFile = fopen(fullPath, "w+")) == NULL)
      {
        printf("Open error.\n");
        return -1;
      }

      sscanf(fn.fileSize, "%x", &fileSize);
      while (fileSize>0)
      {
        readBytes = fileSize < RECFRG ? fileSize:RECFRG;
        if ((readBytes = readn(sockfd, recvs, readBytes))<0) //RECFRG
        {
          printf("File read error.\n");
          return -1;
        }

        fwrite(recvs, 1, readBytes, recvFile);
        fileSize -= readBytes;
      }
      fclose(recvFile);
      getParentPath(fullPath, sizeof(fullPath));
      break;

    case IPMSG_FILE_DIR:
      strncat(fullPath, fn.fileName, sizeof(fullPath)-tmp-1);
      tmp = strlen(fullPath);
      if (tmp+1>=sizeof(fullPath))
      {
        printf("getDir: target directory is too lang.\n"
               "Filename(%s) has been truncated.\n", fn.fileName);
        fullPath[tmp-1] = '/';
      }
      else
      {
        fullPath[tmp] = '/';
        fullPath[tmp+1] = '\0';
      }

      if (mkdir(fullPath, S_IRUSR|S_IWUSR|S_IXUSR))
      {
        printf("getDir: mkdir failed.\n");
        return -1;
      }

      dirDepth++;
      break;

    case IPMSG_FILE_RETPARENT:
      getParentPath(fullPath, sizeof(fullPath));
      dirDepth--;
      break;

    default:
      printf("Unsupported file type.\n");
      break;
    }

  }while(dirDepth>0);

  //close(sockfd);
  shutdown(sockfd, SHUT_RDWR);
  return 0;
}