00001 //----------------------------------------------------------- 00002 // Copyright Christian Arnault LAL-Orsay CNRS 00003 // arnault@lal.in2p3.fr 00004 // See the complete license in cmt_license.txt "http://www.cecill.info". 00005 //----------------------------------------------------------- 00006 00007 #include <stdio.h> 00008 #include <stdlib.h> 00009 #include <string.h> 00010 #include <ctype.h> 00011 00012 #include "cmt_group.h" 00013 #include "cmt_database.h" 00014 00015 /*----------------------------------------------------------*/ 00016 /* */ 00017 /* Operations on Groups */ 00018 /* */ 00019 /*----------------------------------------------------------*/ 00020 00021 //---------------------------------------------------------- 00022 Group* Group::find (const cmt_string& name) 00023 //---------------------------------------------------------- 00024 { 00025 static GroupVector& Groups = groups (); 00026 00027 for (int i = 0; i < Groups.size (); i++) 00028 { 00029 Group& v = Groups[i]; 00030 00031 if (v.m_name == name) return (&v); 00032 } 00033 00034 return (0); 00035 } 00036 00037 //---------------------------------------------------------- 00038 Group* Group::add (const cmt_string& name) 00039 //---------------------------------------------------------- 00040 { 00041 static GroupVector& Groups = groups (); 00042 00043 { 00044 Group* group; 00045 00046 group = find (name); 00047 if (group != 0) return (group); 00048 } 00049 00050 Group& group = Groups.add (); 00051 group.set (name); 00052 00053 return (&group); 00054 } 00055 00056 //---------------------------------------------------------- 00057 Group::GroupVector& Group::groups () 00058 //---------------------------------------------------------- 00059 { 00060 static Database& db = Database::instance (); 00061 static GroupVector& Groups = db.groups (); 00062 00063 return (Groups); 00064 } 00065 00066 /*----------------------------------------------------------*/ 00067 void Group::clear_all () 00068 /*----------------------------------------------------------*/ 00069 { 00070 static GroupVector& Groups = groups (); 00071 00072 for (int i = 0; i < Groups.size (); i++) 00073 { 00074 Group& group = Groups[i]; 00075 group.clear (); 00076 } 00077 00078 Groups.clear (); 00079 } 00080 00081 /*----------------------------------------------------------*/ 00082 void Group::show_all () 00083 /*----------------------------------------------------------*/ 00084 { 00085 static GroupVector& Groups = groups (); 00086 00087 for (int i = 0; i < Groups.size (); i++) 00088 { 00089 Group& group = Groups[i]; 00090 cout << group.m_name << endl; 00091 } 00092 } 00093 00094 //---------------------------------------------------------- 00095 Group::Group () 00096 //---------------------------------------------------------- 00097 { 00098 } 00099 00100 //---------------------------------------------------------- 00101 Group::Group (const cmt_string& name) : m_name (name) 00102 //---------------------------------------------------------- 00103 { 00104 } 00105 00106 //---------------------------------------------------------- 00107 const cmt_string& Group::name () const 00108 //---------------------------------------------------------- 00109 { 00110 return (m_name); 00111 } 00112 00113 //---------------------------------------------------------- 00114 void Group::set (const cmt_string& name) 00115 //---------------------------------------------------------- 00116 { 00117 m_name = name; 00118 } 00119 00120 //---------------------------------------------------------- 00121 void Group::clear () 00122 //---------------------------------------------------------- 00123 { 00124 m_name = ""; 00125 } 00126 00127 //---------------------------------------------------------- 00128 Group& Group::operator = (const Group& other) 00129 //---------------------------------------------------------- 00130 { 00131 m_name = other.m_name; 00132 00133 return (*this); 00134 } 00135 00136 //---------------------------------------------------------- 00137 bool Group::operator == (const cmt_string& name) const 00138 //---------------------------------------------------------- 00139 { 00140 return ((m_name == name)); 00141 } 00142 00143 //---------------------------------------------------------- 00144 bool Group::operator != (const cmt_string& name) const 00145 //---------------------------------------------------------- 00146 { 00147 return ((m_name != name)); 00148 } 00149