1 | #include <stdio.h> |
---|
2 | #include <stdlib.h> |
---|
3 | #include <string.h> |
---|
4 | #include <ctype.h> |
---|
5 | |
---|
6 | #include "cmt_branch.h" |
---|
7 | #include "cmt_database.h" |
---|
8 | |
---|
9 | /*----------------------------------------------------------*/ |
---|
10 | /* */ |
---|
11 | /* Operations on Branches */ |
---|
12 | /* */ |
---|
13 | /*----------------------------------------------------------*/ |
---|
14 | |
---|
15 | /*----------------------------------------------------------*/ |
---|
16 | void Branch::action (const CmtSystem::cmt_string_vector& words) |
---|
17 | /*----------------------------------------------------------*/ |
---|
18 | { |
---|
19 | for (int i = 1; i < words.size (); i++) |
---|
20 | { |
---|
21 | const cmt_string& name = words[i]; |
---|
22 | if (name == "") return; |
---|
23 | |
---|
24 | add (name); |
---|
25 | } |
---|
26 | } |
---|
27 | |
---|
28 | /*----------------------------------------------------------*/ |
---|
29 | Branch* Branch::find (const cmt_string& name) |
---|
30 | /*----------------------------------------------------------*/ |
---|
31 | { |
---|
32 | static BranchVector& Branches = branches (); |
---|
33 | |
---|
34 | int branch_index; |
---|
35 | |
---|
36 | if (Branches.size () == 0) return (0); |
---|
37 | |
---|
38 | for (branch_index = 0; |
---|
39 | branch_index < Branches.size (); |
---|
40 | branch_index++) |
---|
41 | { |
---|
42 | Branch& branch = Branches[branch_index]; |
---|
43 | |
---|
44 | if (branch.name () == name) |
---|
45 | { |
---|
46 | return (&branch); |
---|
47 | } |
---|
48 | } |
---|
49 | |
---|
50 | return (0); |
---|
51 | } |
---|
52 | |
---|
53 | /*----------------------------------------------------------*/ |
---|
54 | void Branch::add (const cmt_string& name) |
---|
55 | /*----------------------------------------------------------*/ |
---|
56 | { |
---|
57 | static BranchVector& Branches = branches (); |
---|
58 | |
---|
59 | { |
---|
60 | Branch* branch; |
---|
61 | |
---|
62 | branch = find (name); |
---|
63 | if (branch != 0) return; |
---|
64 | } |
---|
65 | |
---|
66 | Branch& branch = Branches.add (); |
---|
67 | |
---|
68 | branch.m_name = name; |
---|
69 | } |
---|
70 | |
---|
71 | /*----------------------------------------------------------*/ |
---|
72 | void Branch::print_all (PrintMode mode) |
---|
73 | /*----------------------------------------------------------*/ |
---|
74 | { |
---|
75 | static BranchVector& Branches = branches (); |
---|
76 | |
---|
77 | int number; |
---|
78 | |
---|
79 | for (number = 0; number < Branches.size (); number++) |
---|
80 | { |
---|
81 | if (number > 0) cout << " "; |
---|
82 | Branches[number].print (mode); |
---|
83 | } |
---|
84 | if (number > 0) cout << endl; |
---|
85 | } |
---|
86 | |
---|
87 | /*----------------------------------------------------------*/ |
---|
88 | void Branch::clear_all () |
---|
89 | /*----------------------------------------------------------*/ |
---|
90 | { |
---|
91 | static BranchVector& Branches = branches (); |
---|
92 | |
---|
93 | int number; |
---|
94 | |
---|
95 | for (number = 0; number < Branches.size (); number++) |
---|
96 | { |
---|
97 | Branch& b = Branches[number]; |
---|
98 | |
---|
99 | b.m_name = ""; |
---|
100 | } |
---|
101 | |
---|
102 | Branches.clear (); |
---|
103 | } |
---|
104 | |
---|
105 | /*----------------------------------------------------------*/ |
---|
106 | Branch::BranchVector& Branch::branches () |
---|
107 | /*----------------------------------------------------------*/ |
---|
108 | { |
---|
109 | static Database& db = Database::instance (); |
---|
110 | static BranchVector& Branches = db.branches (); |
---|
111 | |
---|
112 | return (Branches); |
---|
113 | } |
---|
114 | |
---|
115 | /*----------------------------------------------------------*/ |
---|
116 | Branch::Branch () |
---|
117 | /*----------------------------------------------------------*/ |
---|
118 | { |
---|
119 | } |
---|
120 | |
---|
121 | /*----------------------------------------------------------*/ |
---|
122 | Branch::~Branch () |
---|
123 | /*----------------------------------------------------------*/ |
---|
124 | { |
---|
125 | } |
---|
126 | |
---|
127 | /*----------------------------------------------------------*/ |
---|
128 | const cmt_string& Branch::name () const |
---|
129 | /*----------------------------------------------------------*/ |
---|
130 | { |
---|
131 | return (m_name); |
---|
132 | } |
---|
133 | |
---|
134 | /*----------------------------------------------------------*/ |
---|
135 | void Branch::print (PrintMode mode) const |
---|
136 | /*----------------------------------------------------------*/ |
---|
137 | { |
---|
138 | cout << m_name; |
---|
139 | } |
---|
140 | |
---|