oct-group.h

Go to the documentation of this file.
00001 /*
00002 
00003 Copyright (C) 1996-2012 John W. Eaton
00004 
00005 This file is part of Octave.
00006 
00007 Octave is free software; you can redistribute it and/or modify it
00008 under the terms of the GNU General Public License as published by the
00009 Free Software Foundation; either version 3 of the License, or (at your
00010 option) any later version.
00011 
00012 Octave is distributed in the hope that it will be useful, but WITHOUT
00013 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
00014 FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
00015 for more details.
00016 
00017 You should have received a copy of the GNU General Public License
00018 along with Octave; see the file COPYING.  If not, see
00019 <http://www.gnu.org/licenses/>.
00020 
00021 */
00022 
00023 #if !defined (octave_group_h)
00024 #define octave_group_h 1
00025 
00026 #include <string>
00027 
00028 #include <sys/types.h>
00029 
00030 #include "str-vec.h"
00031 
00032 class
00033 OCTAVE_API
00034 octave_group
00035 {
00036 public:
00037 
00038   octave_group (void)
00039     : gr_name (), gr_passwd (), gr_gid (0), gr_mem (), valid (false)
00040   { }
00041 
00042   octave_group (const octave_group& gr)
00043     : gr_name (gr.gr_name), gr_passwd (gr.gr_passwd),
00044       gr_gid (gr.gr_gid), gr_mem (gr.gr_mem), valid (gr.valid)
00045   { }
00046 
00047   octave_group& operator = (const octave_group& gr)
00048   {
00049     if (this != &gr)
00050       {
00051         gr_name  = gr.gr_name;
00052         gr_passwd = gr.gr_passwd;
00053         gr_gid = gr.gr_gid;
00054         gr_mem = gr.gr_mem;
00055         valid = gr.valid;
00056       }
00057 
00058     return *this;
00059   }
00060 
00061   std::string name (void) const;
00062 
00063   std::string passwd (void) const;
00064 
00065   gid_t gid (void) const;
00066 
00067   string_vector mem (void) const;
00068 
00069   bool ok (void) const { return valid; }
00070 
00071   operator bool () const { return ok (); }
00072 
00073   static octave_group getgrent (void);
00074   static octave_group getgrent (std::string& msg);
00075 
00076   static octave_group getgrgid (gid_t gid);
00077   static octave_group getgrgid (gid_t gid, std::string& msg);
00078 
00079   static octave_group getgrnam (const std::string& nm);
00080   static octave_group getgrnam (const std::string& nm, std::string& msg);
00081 
00082   static int setgrent (void);
00083   static int setgrent (std::string& msg);
00084 
00085   static int endgrent (void);
00086   static int endgrent (std::string& msg);
00087 
00088 private:
00089 
00090   // The group name.
00091   std::string gr_name;
00092 
00093   // The group password.
00094   std::string gr_passwd;
00095 
00096   // The numeric group id.
00097   gid_t gr_gid;
00098 
00099   // The members of the group;
00100   string_vector gr_mem;
00101 
00102   // Flag that says whether we have been properly initialized.
00103   bool valid;
00104 
00105   // This is how we will create an octave_group object from a pointer
00106   // to a struct group.
00107   octave_group (void *p, std::string& msg);
00108 
00109   void gripe_invalid (void) const;
00110 };
00111 
00112 #endif
 All Classes Files Functions Variables Typedefs Enumerations Enumerator Friends Defines