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