00001 #include <stdio.h>
00002 #include <stdlib.h>
00003 #include <string.h>
00004 #include <ctype.h>
00005
00006 #include "cmt_branch.h"
00007 #include "cmt_database.h"
00008
00009
00010
00011
00012
00013
00014
00015
00016 void Branch::action (const CmtSystem::cmt_string_vector& words)
00017
00018 {
00019 for (int i = 1; i < words.size (); i++)
00020 {
00021 const cmt_string& name = words[i];
00022 if (name == "") return;
00023
00024 add (name);
00025 }
00026 }
00027
00028
00029 Branch* Branch::find (const cmt_string& name)
00030
00031 {
00032 static BranchVector& Branches = branches ();
00033
00034 int branch_index;
00035
00036 if (Branches.size () == 0) return (0);
00037
00038 for (branch_index = 0;
00039 branch_index < Branches.size ();
00040 branch_index++)
00041 {
00042 Branch& branch = Branches[branch_index];
00043
00044 if (branch.name () == name)
00045 {
00046 return (&branch);
00047 }
00048 }
00049
00050 return (0);
00051 }
00052
00053
00054 void Branch::add (const cmt_string& name)
00055
00056 {
00057 static BranchVector& Branches = branches ();
00058
00059 {
00060 Branch* branch;
00061
00062 branch = find (name);
00063 if (branch != 0) return;
00064 }
00065
00066 Branch& branch = Branches.add ();
00067
00068 branch.m_name = name;
00069 }
00070
00071
00072 void Branch::print_all (PrintMode mode)
00073
00074 {
00075 static BranchVector& Branches = branches ();
00076
00077 int number;
00078
00079 for (number = 0; number < Branches.size (); number++)
00080 {
00081 if (number > 0) cout << " ";
00082 Branches[number].print (mode);
00083 }
00084 if (number > 0) cout << endl;
00085 }
00086
00087
00088 void Branch::clear_all ()
00089
00090 {
00091 static BranchVector& Branches = branches ();
00092
00093 int number;
00094
00095 for (number = 0; number < Branches.size (); number++)
00096 {
00097 Branch& b = Branches[number];
00098
00099 b.m_name = "";
00100 }
00101
00102 Branches.clear ();
00103 }
00104
00105
00106 Branch::BranchVector& Branch::branches ()
00107
00108 {
00109 static Database& db = Database::instance ();
00110 static BranchVector& Branches = db.branches ();
00111
00112 return (Branches);
00113 }
00114
00115
00116 Branch::Branch ()
00117
00118 {
00119 }
00120
00121
00122 Branch::~Branch ()
00123
00124 {
00125 }
00126
00127
00128 const cmt_string& Branch::name () const
00129
00130 {
00131 return (m_name);
00132 }
00133
00134
00135 void Branch::print (PrintMode mode) const
00136
00137 {
00138 cout << m_name;
00139 }
00140