File: command.h

package info (click to toggle)
xd 3.11.0-1
  • links: PTS
  • area: main
  • in suites: squeeze
  • size: 304 kB
  • ctags: 102
  • sloc: cpp: 703; makefile: 139
file content (75 lines) | stat: -rw-r--r-- 1,801 bytes parent folder | download
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
#ifndef _INCLUDED_COMMAND_H_
#define _INCLUDED_COMMAND_H_

#include <string>
#include <vector>

// determine the command as received and the kind of action according to
// the received pattern.

class Command: public std::vector<std::string> 
                       // stores the elements of the pattern
{
    std::string d_arguments;
    static char const *s_action[];
    static char const s_separators[];   // separating parts of nested dir
                                        // names 
    public:
        // modify commanddata.cc if Action is modified
        enum Action                     // starting point as determined 
        {                               // by the first arg-character
            FROM_CONFIG,                // default: determined by config
            FROM_HOME,
            FROM_ROOT,
            FROM_CWD,
            FROM_PARENT,                // relative to CWD
        };

    private:
        Action d_action;
        size_t d_parent;                

    public:
        Command();

        inline std::string const &accumulate() const;
        inline size_t parent() const;
        inline Action action() const;
        
    private:
        void concatArgs();
        inline static void catArg(char const *arg, std::string &dest);

        bool determineAction();
        
        inline static void add(char ch, std::vector<std::string> &cmd);
};

size_t Command::parent() const
{
    return d_parent;
}

Command::Action Command::action() const
{
    return d_action;
}

void Command::catArg(char const *arg, std::string &dest)
{
    dest += arg;
    dest += '/';
}

void Command::add(char ch, std::vector<std::string> &cmd)
{
    cmd.push_back(std::string(1, ch));
}

std::string const &Command::accumulate() const
{
    return d_arguments;
}


#endif