home *** CD-ROM | disk | FTP | other *** search
/ linuxmafia.com 2016 / linuxmafia.com.tar / linuxmafia.com / pub / palmos / bart-1.3b2.tar.gz / bart-1.3b2.tar / bart-1.3b2 / bart.h < prev    next >
C/C++ Source or Header  |  2000-01-12  |  8KB  |  224 lines

  1. /* BART Scheduler Palm Pilot App
  2.  *    
  3.  * Copyright (c) 1999, 2000 Michael Wittman
  4.  * 
  5.  * Permission is hereby granted, free of charge, to any person obtaining a
  6.  * copy of this software and associated documentation files (the "Software"),
  7.  * to deal in the Software without restriction, including without limitation
  8.  * the rights to use, copy, modify, merge, publish, distribute, sublicense,
  9.  * and/or sell copies of the Software, and to permit persons to whom the
  10.  * Software is furnished to do so, subject to the following conditions:
  11.  * 
  12.  * The above copyright notice and this permission notice shall be included
  13.  * in all copies or substantial portions of the Software.
  14.  * 
  15.  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  16.  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  17.  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
  18.  * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
  19.  * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
  20.  * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
  21.  * OTHER DEALINGS IN THE SOFTWARE.
  22.  *    
  23.  */
  24.  
  25. /* bart.h contains data types and declarations shared between the two C
  26.    files, as well as all #define options. */
  27.  
  28. #include "bartRsc.h"
  29.  
  30. /* Set to 1 to enable timing for tuning purposes, or 0 to turn off.
  31.    When enabled, the data displayed is determined by the number (0-9)
  32.    entered as grafitti in the main form.  Zero (the default) disables
  33.    the display of info.  See the FindTrips function for the results of
  34.    the other settings. */
  35. #define TUNING            0
  36.  
  37. /* The results popup window and selection pop up when the pen goes
  38.    down on a table entry.  They remain up until RESULTS_POPUP_TIME1
  39.    seconds after the pen went down, or RESULTS_POPUP_TIME2 seconds
  40.    after it subsequently goes up, whichever is later.  The effect is
  41.    that the user can hold the pen down to keep the popup window on the
  42.    screen (like in the week view of Datebook).  Set both of these to 0
  43.    to disable the popup window (and save 1.5k of precious memory), but
  44.    remember to modify the help info for the results window in
  45.    bart.rcp! */
  46. #define RESULTS_POPUP_TIME1    5
  47. #define RESULTS_POPUP_TIME2    1
  48.  
  49. #if RESULTS_POPUP_TIME1 || RESULTS_POPUP_TIME2
  50. #define RESULTS_POPUP        1
  51. #else
  52. #define RESULTS_POPUP        0
  53. #endif
  54.  
  55. /* Max number of transfers allowed in a single trip. This is dictated
  56.    by the number of columns in the table. It should not be an issue
  57.    for vanilla BART scheduling though. */
  58. #define MAX_TRANSFERS        2
  59.  
  60. /* The maximum number of different line combinations making up a trip
  61.    that will be found for a search.  Sixteen should be more than
  62.    sufficient (hopefully)... */
  63. #define MAX_TRIP_TYPES        16
  64.  
  65. /* The maximum number of distinct trips (includes time info) that will
  66.    be found. */
  67. #define MAX_TRIPS        8
  68.  
  69. /* The maximum number of distinct trips that will be displayed.
  70.    MAX_TRIPS_DISPLAYED is less than MAX_TRIPS so we can weed out trips
  71.    well before and after that take more time than necessary.  We will
  72.    need twice this number of rows in the table to display the trips if
  73.    subsequent trips go through different stations. */
  74. #define MAX_TRIPS_DISPLAYED    4
  75.  
  76. /* Format of the station bike restrictions in the database; the struct
  77.    says that no bikes are allowed in or out of the station between the
  78.    two times (it's OK for bikes to be on trains going through the
  79.    stations though). */
  80. typedef struct {
  81.    Byte station;
  82.    Byte junk;            /* for alignment */
  83.    UInt time_start;
  84.    UInt time_end;
  85. } StationBikeRestrictionType;
  86.  
  87. extern Byte station_bike_restrictions;
  88. extern StationBikeRestrictionType *station_bike_restriction;
  89.  
  90.  
  91. /* TABLE_ROWS needs to be at least 2*MAX_TRIPS_DISPLAYED.
  92.    TABLE_COLUMNS needs to be at least 2*(MAX_TRANSFERS+1).  These
  93.    numbers must also match the dimensions in the .rcp file. */
  94. #define TABLE_ROWS        8
  95. #define TABLE_COLUMNS        6
  96.  
  97. typedef struct {
  98.    Byte type;
  99.    union ResultsCellDataType {
  100.       /* nothing to store for an empty cell or a "to" cell */
  101.       struct ResultsCellDataStationType {
  102.      Byte number;
  103.       } station;
  104.       struct ResultsCellDataTimeType {
  105.      UInt time;
  106.       } time;
  107. #if TUNING
  108.       struct ResultsCellDataNumber {
  109.      ULong number;
  110.       } number;
  111. #endif
  112.    } data;
  113. } ResultsCellType;
  114.  
  115. #define resultsCellEmpty    0x00
  116. #define resultsCellStation    0x01
  117. #define resultsCellTime        0x02
  118. #if TUNING
  119. #define resultsCellNumber    0x03
  120. #endif
  121.  
  122. #if TUNING
  123. extern Int tuningSetting;
  124. extern Int miscSetting;
  125. #endif
  126.  
  127. extern Int useSourceForDestination;
  128.  
  129.  
  130. /* represents a "block" of trains with the same characteristics */
  131. typedef struct {
  132.    /* number of trains represented by this structure */
  133.    Byte trains;
  134.    /* time difference between departures at initial valid stations */
  135.    SByte time_diff;
  136.    /* index into inc_vector array */
  137.    Byte inc_vector_idx;
  138.    /* applicable bike restriction pair; 0xff == no restrictions */
  139.    Byte nobike_pair_idx;
  140. } TrainBlockType;
  141.  
  142.  
  143. /* gives a pointer to inc_vector i in the given lineinfo.  this is
  144.    still valid, but no longer used. */
  145. #define inc_vector_ptr(lineinfo,i) ((lineinfo)->inc_vector+(i)*(lineinfo).stations)
  146.  
  147. /* transfers, as they are layed out in the database */
  148. typedef struct {
  149.    /* station at which the transfer is made */ 
  150.    Byte station;
  151.    /* line to which the transfer is made */
  152.    Byte new_line;
  153.    /* amount of time necessary to make the transfer; if there is not
  154.       this amount of time between the two trains, we don't consider
  155.       the transfer possible */
  156.    UInt time;
  157. } TransferInfoType;
  158.  
  159. typedef struct {
  160.    /* record handle for this line */
  161.    VoidHand record_handle;
  162.  
  163.    /* Info from and pointers to info in the record: */
  164.  
  165.    /* station numbers (in order of appearance) for stations on this line */
  166.    Byte stations;
  167.    Byte *station;
  168.    
  169.    /* Increment vectors represent difference between the time a train
  170.       is at a given station on the line and the time it is at the
  171.       first station.  In theory, a small number of increment vectors
  172.       will describe all trains on a line. */
  173.    Byte inc_vectors;
  174.    Byte *inc_vector;
  175.    
  176.    /* "No bike pairs" are the first and last stations of a bike
  177.       restriction.  In theory, a small number of "no bike pairs" will
  178.       describe all bike restrictions on a line. */
  179.    Byte nobike_pairs;
  180.    Byte (*nobike_pair)[2];
  181.    
  182.    /* Time of initial train on this line at its initial valid station. */
  183.    Word initial_time;
  184.  
  185.    /* train blocks described above... */
  186.    Byte train_blocks;
  187.    TrainBlockType *train_block;
  188.  
  189.    /* transfers for all stations on this line */
  190.    Byte transfers;
  191.    TransferInfoType *transfer;
  192.  
  193.    /* number of trains on this line */
  194.    Byte trains;
  195.  
  196.    /* These are for the train block data uncompressed into linear
  197.       arrays (indexed by train number) and are dynamically allocated
  198.       when they are needed. */
  199.    VoidHand departure_time_handle;
  200.    VoidHand inc_vector_idx_handle;
  201.    VoidHand nobike_pair_idx_handle;
  202. } LineDataType;
  203.  
  204. extern Byte currentLines;
  205. extern LineDataType *lineInfo;
  206.  
  207. #define INVALID_STATION        0xff
  208. #define INVALID_TRANSFER    0xff
  209. #define INVALID_BIKEPAIR    0xff
  210. #define INVALID_TRAIN        0xff
  211. #define INVALID_INC        0xff
  212.  
  213.  
  214. void AllocateDepartureTimes(LineDataType *line);
  215. void DeallocateDepartureTimes(LineDataType *line);
  216.  
  217.  
  218. #define DebugPrintF(format, args...)            \
  219. do {                            \
  220.    char string[100];                    \
  221.    StrPrintF(string,format,##args);            \
  222.    FrmCustomAlert(ID_Debug_Alert,string,NULL,NULL);    \
  223. } while (0)
  224.