source: CMT/HEAD/source/cmt_group.cxx @ 679

Last change on this file since 679 was 400, checked in by arnault, 17 years ago

Text formatting
Sending warnings & errors to stderr
Using internally PWD for every cd/pwd
CL 327

  • Property svn:eol-style set to native
File size: 3.8 KB
RevLine 
[2]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_group.h"
13#include "cmt_database.h"
14
15/*----------------------------------------------------------*/
16/*                                                          */
17/*  Operations on Groups                                    */
18/*                                                          */
19/*----------------------------------------------------------*/
20
21//----------------------------------------------------------
22Group* Group::find (const cmt_string& name)
[400]23  //----------------------------------------------------------
[2]24{
25  static GroupVector& Groups = groups ();
26
27  for (int i = 0; i < Groups.size (); i++)
28    {
29      Group& v = Groups[i];
30
31      if (v.m_name == name) return (&v);
32    }
33
34  return (0);
35}
36
37//----------------------------------------------------------
38Group* Group::add (const cmt_string& name)
[400]39  //----------------------------------------------------------
[2]40{
41  static GroupVector& Groups = groups ();
42
43  {
44    Group* group;
45
46    group = find (name);
47    if (group != 0) return (group);
48  }
49
50  Group& group = Groups.add ();
51  group.set (name);
52
53  return (&group);
54}
55
56//----------------------------------------------------------
57Group::GroupVector& Group::groups ()
[400]58  //----------------------------------------------------------
[2]59{
60  static Database& db = Database::instance ();
61  static GroupVector& Groups = db.groups ();
62
63  return (Groups);
64}
65
66/*----------------------------------------------------------*/
67void Group::clear_all ()
[400]68  /*----------------------------------------------------------*/
[2]69{
70  static GroupVector& Groups = groups ();
71
72  for (int i = 0; i < Groups.size (); i++)
73    {
74      Group& group = Groups[i];
75      group.clear ();
76    }
77
78  Groups.clear ();
79}
80
81/*----------------------------------------------------------*/
82void Group::show_all ()
[400]83  /*----------------------------------------------------------*/
[2]84{
85  static GroupVector& Groups = groups ();
86
87  for (int i = 0; i < Groups.size (); i++)
88    {
89      Group& group = Groups[i];
90      cout << group.m_name << endl;
91    }
92}
93
94//----------------------------------------------------------
95Group::Group ()
[400]96  //----------------------------------------------------------
[2]97{
98}
99
100//----------------------------------------------------------
101Group::Group (const cmt_string& name) : m_name (name)
[400]102  //----------------------------------------------------------
[2]103{
104}
105
106//----------------------------------------------------------
107const cmt_string& Group::name () const
[400]108  //----------------------------------------------------------
[2]109{
110  return (m_name);
111}
112
113//----------------------------------------------------------
114void Group::set (const cmt_string& name)
[400]115  //----------------------------------------------------------
[2]116{
117  m_name = name;
118}
119
120//----------------------------------------------------------
121void Group::clear ()
[400]122  //----------------------------------------------------------
[2]123{
124  m_name = "";
125}
126
127//----------------------------------------------------------
128Group& Group::operator = (const Group& other)
[400]129  //----------------------------------------------------------
[2]130{
131  m_name = other.m_name;
132
133  return (*this);
134}
135
136//----------------------------------------------------------
137bool Group::operator == (const cmt_string& name) const
[400]138  //----------------------------------------------------------
[2]139{
140  return ((m_name == name));
141}
142
143//----------------------------------------------------------
144bool Group::operator != (const cmt_string& name) const
[400]145  //----------------------------------------------------------
[2]146{
147  return ((m_name != name));
148}
149
Note: See TracBrowser for help on using the repository browser.