profile.h Source File

Main Page Modules Class Hierarchy Compound List File List Compound Members File Members

# profile.h

    00001 /* MuSE - Multiple Streaming Engine
    00002  * Copyright (C) 2000-2002 Denis Rojo aka jaromil <jaromil@dyne.org>
    00003  *
    00004  * This source code is free software; you can redistribute it and/or
    00005  * modify it under the terms of the GNU Public License as published
    00006  * by the Free Software Foundation; either version 2 of the License,
    00007  * or (at your option) any later version.
    00008  *
    00009  * This source code is distributed in the hope that it will be useful,
    00010  * but WITHOUT ANY WARRANTY; without even the implied warranty of
    00011  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
    00012  * Please refer to the GNU Public License for more details.
    00013  *
    00014  * You should have received a copy of the GNU Public License along with
    00015  * this source code; if not, write to:
    00016  * Free Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
    00017  *
    00018  * $Id: profile.h,v 1.1.1.1 2003/12/08 12:20:33 jaromil Exp $
    00019  *
    00020  */
    00021
    00022 #ifndef __PROFILE_H__
    00023 #define __PROFILE_H__
    00024
    00025 #include <stdio.h>
    00026 #include <stdlib.h>
    00027 #include <generic.h>
    00028 #include <config.h>
    00029
    00030 #define MAX_SECTION_SIZE 128
    00031 #define MAX_OPTION_SIZE 128
    00032 #define MAX_VALUE_SIZE 128
    00033 #define MAX_LINE_SIZE MAX_PATH_SIZE
    00034
    00035 enum cfgTYPE { cfgNULL, cfgINT, cfgSTR, cfgFLOAT };
    00036
    00037 struct settings {
    00038   const char *name;
    00039   void *var;
    00040   enum cfgTYPE type;
    00041   const char *defval;
    00042 };
    00043
    00044 class Profile {
    00045
    00046  private:
    00047   char *res[2];
    00048   char *is_a_section(char *str);
    00049   char **parse_option(char *str);
    00050   off_t find_section(FILE *fp, const char *section);
    00051   off_t find_option(FILE *fp, const char *option, char *value, off_t section_offset);
    00052
    00053  protected:
    00054   int cfg_check(const char *file, int output);
    00055   bool cfg_read(const char *file, const char *section, const char *option, char *value);
    00056   bool cfg_write(const char *file, const char *section, const char *option, const char *value);
    00057   bool cfg_erase(const char *file, const char *section, const char *option);
    00058   int cfg_get_sections(const char *file, char *dest);
    00059
    00060   char profile_path[MAX_PATH_SIZE];
    00061
    00062   void setup(struct settings *conf) { cfg = conf; }
    00063
    00064  public:
    00065   Profile(char *name);
    00066   virtual ~Profile();
    00067
    00068   /* HERE IS THE PROFILE API
    00069      if you're doing a GUI, those are the functions */
    00070   bool create_default_profile(); /* creates a default profile
    00071                                     and sets default values */
    00072   bool load_profile(const char *section);
    00073   bool write_profile(const char *section);
    00074   virtual bool apply_profile() =0;
    00075
    00076   /* =-----= */
    00077   int list_profiles(char *str) {
    00078     return cfg_get_sections(profile_path,str); }
    00079
    00080   /* loads default settings from the conf file
    00081      if the file is not existing calls create_profile()
    00082      then calls apply_profile() */
    00083   bool default_profile();
    00084
    00085   int read_int(const char *section, const char *option);
    00086   bool write_int(const char *section, const char *option, const int value);
    00087   bool read_str(const char *section, const char *option, char *store);
    00088   bool write_str(const char *section, const char *option, const char *value);
    00089   float read_float(const char *section, const char *option);
    00090   bool write_float(const char *section, const char *option, const float value);
    00091
    00092   struct settings *cfg;
    00093 };
    00094
    00095 #endif