/** 
 * File: NetworkReader.h
 * 
 * A NetworkReader reads in data about the traffic network from a specified
 * xml file.
 * 
 * A NetworkReader contains two public methods 'getLines' and 'getLoops',
 * which are getters for the list of FEP_LINES, and STATIONS, respectively.
 * 
 * Example XML file:
 * <code>
 * <Network>
 * <Line>
 *   <Line_Num>5</Line_Num>
 *   <Count>20</Count>
 *   <Schedule>1</Schedule>
 *   <Line_Info>1</Line_Info>
 *   <System_Key>1123005673</System_Key>
 *   <Global_Seq>1357648</Global_Seq>
 *   <Schedule_Seq>26492</Schedule_Seq>
 *   <Stations>
 *     <Station>
 *       <LDS_ID>1205270</LDS_ID>
 *       <Line_Num>5</Line_Num>
 *       <Drop>19</Drop>
 *       <Location>MAIN 1</Location>
 *       <Post_Mile>33.0</Post_Mile>
 *       <Direction>S</Direction>
 *       <Freeway>5</Freeway>
 *       <ML_Tot_Vol>0</ML_Tot_Vol>
 *       <Opp_Tot_Vol>0</Opp_Tot_Vol>
 *       <Loops>
 *         <Loop>
 *           <Loop_ID>1205272</Loop_ID>
 *           <Loop_Location>RAMP_ON</Loop_Location>
 *           <Lane_Num>1</Lane_Num>
 *           <Vol>0</Vol>
 *           <Occ>0</Occ>
 *           <Spd>0</Spd>
 *         </Loop>
 *          .......
 * </code>
 * 
 * @author John A. Torres
 * @verions 9/08/2017
 */

// Include guard
#ifndef __NETWORKREADER_H_INCLUDED__
#define __NETWORKREADER_H_INCLUDED__

// Included dependencies
#include "network.h"
#include <vector>
#include <string.h>
#include <iostream>
#include "tinyxml.h"
#include "DataPacker.h"

class NetworkReader {
public:
    /**
     * Constructor
     * @param xml Highway Status XML data
     */
    NetworkReader(const char * xml);
    
    /**
     * Destructor: no cleaning necessary
     */
    ~NetworkReader();
    
    /**
     * Returns FEP_LINE list.
     * 
     * @return List of FEP_LINES
     */
    vector<FEP_LINE*> getLines();
    
    /**
     * Returns STATIONS list.
     * @return List of STATIONs
     */
    vector<STATION*> getStations();
    
private:
    vector<FEP_LINE*> lines;
    vector<STATION*> stations;
    int ldsIndex;
    
    /**
     * Loads Highway Status data from xml.
     * 
     * @param xml Highway Status XML.
     */
    void loadLines(const char * networkFileName);
    
    /**
     * Parses a single LOOP
     * @param loopElem TinyXML loop elem
     * @return LOOP
     */
    LOOP * parseLoop(TiXmlElement * loopElem);
    
    /**
     * Parses a single STATION
     * 
     * @param TinyXML station element
     * @param the parent FEP_LINE
     * @return STATION
     */
    STATION * parseStation(TiXmlElement *stationElem, FEP_LINE *line);
    
    /**
     * Parses a single FEP_LINE
     * @param TinyXML line element
     * @return FEP_LINE
     */
    FEP_LINE * parseLine(TiXmlElement *lineElem);
};

#endif
