summaryrefslogtreecommitdiffstats
path: root/ue3/mycpu/cprogram.h
blob: 25d0ce23cf03bb028a482d00bbbf00865dede1db (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
/**
 * @module cprogram
 * @author Guenther Neuwirth (0626638), Manuel Mausz (0728348)
 * @brief  class for parsing and saving the program instuctions.
 * @date   17.04.2009
 */

#ifndef CPROGRAM_H
#define CPROGRAM_H

#include <stdexcept>
#include <string>
#include <vector>
#include <map>
#ifdef DEBUG
# include <iostream>
#endif
#include "cdat.h"
/**
 * @class CProgram
 *
 * Parses a simple line based scriptfile with some limitations:
 * first function (starting a block) must be a read-command,
 * last must be a write-command (ending this block).
 *
 * read- and write-commands have hard coded parameters, number#1 being a filetype.
 * Classes handling certain filetypes must be of type CFile.
 * Custom functions will be passed to CFile::callFunc().
 *
 * On error ParserError will be thrown.
 */
class CProgram
{
  public:

    /**
     * @method CProgram
     * @brief  Default ctor
     * @param  programfile filename 
     * @return -
     * @globalvars none
     * @exception  bad_alloc
     * @conditions none
     */
    CProgram(const std::string& progfile);

    /**
     * @method ~CScriptparser
     * @brief  Default dtor
     * @param  -
     * @return -
     * @globalvars none
     * @exception  none
     * @conditions none
     */
    ~CProgram();

    CDat getMaxProgramCount()
    {
      return CDat(m_progsource.size());
    }
    
    std::vector<std::string>& getInstruction(CDat linenr)
    {
         return m_progsource[linenr.getTypeValue()];
    }
    
    std::map<std::string, unsigned int>& getJumpAddrs()
    {
      return m_jumpaddr;
    }
#ifdef DEBUG
    /**
     * @method dump
     * @brief  Dumps the program source to ostream
     * @param  out output stream
     * @return -
     * @globalvars
     * @exception
     * @conditions
     */
    void dump(std::ostream& out);
#endif

  protected:
    /**
     * @method parse
     * @brief  parse the program file
     * @param  -
     * @return -
     * @globalvars none
     * @exception  ParserError
     * @conditions none
     */
     void parse();
     
  private:
    /* members */
    std::string m_programfile;
    std::vector<std::vector<std::string> > m_progsource;
    std::map<std::string, unsigned int> m_jumpaddr;
};

#endif

/* vim: set et sw=2 ts=2: */