SASC
DVBSoftCAM

cConfig< T > Class Template Reference

#include <config.h>

Inheritance diagram for cConfig< T >:

List of all members.

Public Member Functions

 cConfig (void)
virtual ~cConfig ()
const char * FileName (void)
bool Load (const char *FileName=NULL, bool AllowComments=false, bool MustExist=false)
bool Save (void)
 cConfig (void)
virtual ~cConfig ()
const char * FileName (void)
bool Load (const char *FileName=NULL, bool AllowComments=false, bool MustExist=false)
bool Save (void)

Detailed Description

template<class T>
class cConfig< T >

Definition at line 78 of file config.h.


Constructor & Destructor Documentation

template<class T>
cConfig< T >::cConfig ( void  ) [inline]

Definition at line 89 of file config.h.

{ fileName = NULL; }
template<class T>
virtual cConfig< T >::~cConfig ( ) [inline, virtual]

Definition at line 90 of file config.h.

{ free(fileName); }
template<class T>
cConfig< T >::cConfig ( void  ) [inline]

Definition at line 89 of file config.h.

{ fileName = NULL; }
template<class T>
virtual cConfig< T >::~cConfig ( ) [inline, virtual]

Definition at line 90 of file config.h.

{ free(fileName); }

Member Function Documentation

template<class T>
const char* cConfig< T >::FileName ( void  ) [inline]

Definition at line 91 of file config.h.

Referenced by cConfig< cTimer >::Load().

{ return fileName; }
template<class T>
const char* cConfig< T >::FileName ( void  ) [inline]

Definition at line 91 of file config.h.

{ return fileName; }
template<class T>
bool cConfig< T >::Load ( const char *  FileName = NULL,
bool  AllowComments = false,
bool  MustExist = false 
) [inline]

Reimplemented in cChannels.

Definition at line 92 of file config.h.

  {
    cConfig<T>::Clear();
    if (FileName) {
       free(fileName);
       fileName = strdup(FileName);
       allowComments = AllowComments;
       }
    bool result = !MustExist;
    if (fileName && access(fileName, F_OK) == 0) {
       isyslog("loading %s", fileName);
       FILE *f = fopen(fileName, "r");
       if (f) {
          char *s;
          int line = 0;
          cReadLine ReadLine;
          result = true;
          while ((s = ReadLine.Read(f)) != NULL) {
                line++;
                if (allowComments) {
                   char *p = strchr(s, '#');
                   if (p)
                      *p = 0;
                   }
                stripspace(s);
                if (!isempty(s)) {
                   T *l = new T;
                   if (l->Parse(s))
                      Add(l);
                   else {
                      esyslog("ERROR: error in %s, line %d", fileName, line);
                      delete l;
                      result = false;
                      break;
                      }
                   }
                }
          fclose(f);
          }
       else {
          LOG_ERROR_STR(fileName);
          result = false;
          }
       }
    if (!result)
       fprintf(stderr, "vdr: error while reading '%s'\n", fileName);
    return result;
  }
template<class T>
bool cConfig< T >::Load ( const char *  FileName = NULL,
bool  AllowComments = false,
bool  MustExist = false 
) [inline]

Reimplemented in cChannels.

Definition at line 92 of file config.h.

  {
    cConfig<T>::Clear();
    if (FileName) {
       free(fileName);
       fileName = strdup(FileName);
       allowComments = AllowComments;
       }
    bool result = !MustExist;
    if (fileName && access(fileName, F_OK) == 0) {
       isyslog("loading %s", fileName);
       FILE *f = fopen(fileName, "r");
       if (f) {
          char *s;
          int line = 0;
          cReadLine ReadLine;
          result = true;
          while ((s = ReadLine.Read(f)) != NULL) {
                line++;
                if (allowComments) {
                   char *p = strchr(s, '#');
                   if (p)
                      *p = 0;
                   }
                stripspace(s);
                if (!isempty(s)) {
                   T *l = new T;
                   if (l->Parse(s))
                      Add(l);
                   else {
                      esyslog("ERROR: error in %s, line %d", fileName, line);
                      delete l;
                      result = false;
                      break;
                      }
                   }
                }
          fclose(f);
          }
       else {
          LOG_ERROR_STR(fileName);
          result = false;
          }
       }
    if (!result)
       fprintf(stderr, "vdr: error while reading '%s'\n", fileName);
    return result;
  }
template<class T>
bool cConfig< T >::Save ( void  ) [inline]

Reimplemented in cSetup, and cSetup.

Definition at line 140 of file config.h.

  {
    bool result = true;
    T *l = (T *)this->First();
    cSafeFile f(fileName);
    if (f.Open()) {
       while (l) {
             if (!l->Save(f)) {
                result = false;
                break;
                }
             l = (T *)l->Next();
             }
       if (!f.Close())
          result = false;
       }
    else
       result = false;
    return result;
  }
template<class T>
bool cConfig< T >::Save ( void  ) [inline]

Reimplemented in cSetup, and cSetup.

Definition at line 140 of file config.h.

  {
    bool result = true;
    T *l = (T *)this->First();
    cSafeFile f(fileName);
    if (f.Open()) {
       while (l) {
             if (!l->Save(f)) {
                result = false;
                break;
                }
             l = (T *)l->Next();
             }
       if (!f.Close())
          result = false;
       }
    else
       result = false;
    return result;
  }

The documentation for this class was generated from the following files:
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines