Ejemplo n.º 1
0
 /// <summary>
 /// Creates a new transit db.
 /// </summary>
 public TransitDb()
 {
     _agencyAttributes = new AttributesIndex(AttributesIndexMode.ReverseStringIndex);
     _connectionsDb    = new ConnectionsDb();
     _stopsDb          = new StopsDb();
     _stopAttributes   = new AttributesIndex(AttributesIndexMode.ReverseStringIndex);
     _tripsDb          = new TripsDb();
     _tripAttributes   = new AttributesIndex(AttributesIndexMode.ReverseStringIndex);
     _transfersDbs     = new Dictionary <string, TransfersDb>();
     _schedulesDb      = new SchedulesDb();
     _shapesDb         = new ShapesDb();
 }
Ejemplo n.º 2
0
        /// <summary>
        /// Deserializes from stream.
        /// </summary>
        public static TransitDb Deserialize(Stream stream)
        {
            var version = stream.ReadByte();

            if (version > 2)
            {
                throw new Exception("Cannot deserialize db, version # doesn't match.");
            }

            // read agencies attributes.
            var agencyAttributes = AttributesIndex.Deserialize(new LimitedStream(stream), true);

            // read connections db.
            var connectionsDb = ConnectionsDb.Deserialize(stream);

            // read schedules db.
            var schedulesDb = SchedulesDb.Deserialize(stream);

            // read stop attributes.
            var stopAttributes = AttributesIndex.Deserialize(new LimitedStream(stream), true);

            // read stop db.
            var stopsDb = StopsDb.Deserialize(stream);

            // read transfer db's.
            var transferDbsCount = stream.ReadByte();
            var transferDbs      = new Dictionary <string, TransfersDb>();

            for (var i = 0; i < transferDbsCount; i++)
            {
                var profileName = stream.ReadWithSizeString();
                var transferDb  = TransfersDb.Deserialize(stream);

                transferDbs.Add(profileName, transferDb);
            }

            // read trip attributes.
            var tripAttributes = AttributesIndex.Deserialize(new LimitedStream(stream), true);

            // write trips db.
            var tripsDb = TripsDb.Deserialize(stream);

            ShapesDb shapesDb = null;

            if (version != 1)
            { // write shapes db.
                shapesDb = ShapesDb.Deserialize(stream);
            }

            return(new TransitDb(agencyAttributes, connectionsDb, schedulesDb, stopAttributes, stopsDb, transferDbs,
                                 tripAttributes, tripsDb, shapesDb));
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Searches all trips.
        /// </summary>
        public static HashSet <uint> SearchAll(this TripsDb tripsDb, AttributesIndex tripAttributes, Func <IAttributeCollection, bool> filter)
        {
            var ids = new HashSet <uint>();

            var enumerator = tripsDb.GetEnumerator();

            while (enumerator.MoveUntil(tripAttributes, filter))
            {
                ids.Add(enumerator.Id);
            }

            return(ids);
        }
Ejemplo n.º 4
0
 /// <summary>
 /// Creates a new transit db.
 /// </summary>
 private TransitDb(AttributesIndex agencyAttributes, ConnectionsDb connectionsDb, SchedulesDb schedulesDb, AttributesIndex stopAttributes,
                   StopsDb stopsDb, Dictionary <string, TransfersDb> transferDbs, AttributesIndex tripAttributes, TripsDb tripsDb, ShapesDb shapesDb)
 {
     _agencyAttributes = agencyAttributes;
     _connectionsDb    = connectionsDb;
     _schedulesDb      = schedulesDb;
     _stopAttributes   = stopAttributes;
     _stopsDb          = stopsDb;
     _transfersDbs     = transferDbs;
     _tripAttributes   = tripAttributes;
     _tripsDb          = tripsDb;
     _shapesDb         = shapesDb;
 }