Back to index

nordugrid-arc-nox  1.1.0~rc6
Public Member Functions | Private Attributes
ConfigSections Class Reference

#include <conf_sections.h>

Collaboration diagram for ConfigSections:
Collaboration graph
[legend]

List of all members.

Public Member Functions

 ConfigSections (const char *filename)
 ConfigSections (std::istream &f)
 ~ConfigSections (void)
 operator bool (void)
bool AddSection (const char *name)
bool ReadNext (std::string &line)
bool ReadNext (std::string &name, std::string &value)
const char * Section (void)
bool SectionNew (void)
int SectionNum (void)
const char * SectionMatch (void)
const char * SubSection (void)
const char * SubSectionMatch (const char *name)

Private Attributes

std::istream * fin
bool open
std::list< std::string > section_names
std::string current_section
int current_section_n
std::list< std::string >::iterator current_section_p
int line_number
bool current_section_changed

Detailed Description

Definition at line 9 of file conf_sections.h.


Constructor & Destructor Documentation

ConfigSections::ConfigSections ( const char *  filename)

Definition at line 30 of file conf_sections.cpp.

                                                  :fin(NULL),open(false) {
  line_number=0;
  current_section_n=-1;
  current_section_p=section_names.end();
  if(!filename) return;
  fin=new std::ifstream(filename);
  if(*fin) open=true;
  current_section_changed=false;
}
ConfigSections::ConfigSections ( std::istream &  f)

Definition at line 22 of file conf_sections.cpp.

Definition at line 15 of file conf_sections.cpp.

                                    {
  if(fin && open) {
    ((std::ifstream*)(fin))->close();
    delete fin;
  };
}

Member Function Documentation

bool ConfigSections::AddSection ( const char *  name)

Definition at line 40 of file conf_sections.cpp.

                                                {
  if(name) section_names.push_back(std::string(name));
  return true;
}

Here is the caller graph for this function:

ConfigSections::operator bool ( void  ) [inline]

Definition at line 23 of file conf_sections.h.

{ return ((fin!=NULL) && (*fin)); };
bool ConfigSections::ReadNext ( std::string &  line)

Definition at line 45 of file conf_sections.cpp.

                                             {
  if(!fin) return false;
  if(!*fin) return false;
  current_section_changed=false;
  for(;;) {
    line=config_read_line(*fin);
    if(line=="") { // eof
      current_section="";
      current_section_n=-1;
      current_section_p=section_names.end();
      current_section_changed=true;
      return true;
    };
    std::string::size_type n=line.find_first_not_of(" \t");
    if(n == std::string::npos) continue; // should never happen
    if(line[n] == '[') {  // section
      n++; std::string::size_type nn = line.find(']',n);
      if(nn == std::string::npos) { line=""; return false; }; // missing ']'
      current_section=line.substr(n,nn-n);
      current_section_n=-1;
      current_section_p=section_names.end();
      current_section_changed=true;
      continue;
    };
    if(section_names.size()) { // only limited sections allowed
      bool match = false;
      int s_n = -1;
      for(std::list<std::string>::iterator sec = section_names.begin();
                                       sec!=section_names.end();++sec) {
        std::string::size_type len = sec->length();
        s_n++;
        if(strncasecmp(sec->c_str(),current_section.c_str(),len) != 0) continue;
        if(len != current_section.length()) {
          if(current_section[len] != '/') continue;
        };
        current_section_n=s_n;
        current_section_p=sec;
        match=true; break;
      };
      if(!match) continue;
    };
    line.erase(0,n);
    break;
  };
  return true;
}

Here is the call graph for this function:

Here is the caller graph for this function:

bool ConfigSections::ReadNext ( std::string &  name,
std::string &  value 
)

Definition at line 92 of file conf_sections.cpp.

                                                              {
  if(!ReadNext(name)) return false;
  std::string::size_type n = name.find('=');
  if(n == std::string::npos) { value=""; return true; };
  value=name.c_str()+n+1;
  name.erase(n);
  std::string::size_type l = value.length();
  for(n = 0;n<l;n++) if((value[n] != ' ') && (value[n] != '\t')) break;
  if(n>=l) { value=""; return true; };
  if(n) value.erase(0,n);
  if(value[0] != '"') return true;
  std::string::size_type nn = value.rfind('"');
  if(nn == 0) return true; // strange
  std::string::size_type n_ = value.find('"',1);
  if((nn > n_) && (n_ != 1)) return true;
  value.erase(nn);
  value.erase(0,1);
  return true;
}

Here is the call graph for this function:

const char* ConfigSections::Section ( void  ) [inline]

Definition at line 27 of file conf_sections.h.

{ return current_section.c_str(); };
const char* ConfigSections::SectionMatch ( void  ) [inline]

Definition at line 30 of file conf_sections.h.

                                 {
    if(current_section_n<0) return "";
    return current_section_p->c_str();
  };
bool ConfigSections::SectionNew ( void  ) [inline]

Definition at line 28 of file conf_sections.h.

Here is the caller graph for this function:

int ConfigSections::SectionNum ( void  ) [inline]

Definition at line 29 of file conf_sections.h.

{ return current_section_n; };

Here is the caller graph for this function:

const char* ConfigSections::SubSection ( void  ) [inline]

Definition at line 34 of file conf_sections.h.

                               {
    if(current_section_n<0) return "";
    if(current_section.length() > current_section_p->length())
      return (current_section.c_str()+current_section_p->length()+1);
    return "";
  };   

Here is the caller graph for this function:

const char * ConfigSections::SubSectionMatch ( const char *  name)

Definition at line 112 of file conf_sections.cpp.

                                                            {
  const char* subsection = current_section.c_str();
  if(current_section_n>=0) subsection+=current_section_p->length()+1;
  int l = strlen(name);
  if(strncmp(name,subsection,l) != 0) return NULL;
  if(subsection[l] == 0) return (subsection+l);
  if(subsection[l] == '/') return (subsection+l+1);
  return NULL;
}

Member Data Documentation

std::string ConfigSections::current_section [private]

Definition at line 14 of file conf_sections.h.

Definition at line 18 of file conf_sections.h.

Definition at line 15 of file conf_sections.h.

std::list<std::string>::iterator ConfigSections::current_section_p [private]

Definition at line 16 of file conf_sections.h.

std::istream* ConfigSections::fin [private]

Definition at line 11 of file conf_sections.h.

Definition at line 17 of file conf_sections.h.

bool ConfigSections::open [private]

Definition at line 12 of file conf_sections.h.

std::list<std::string> ConfigSections::section_names [private]

Definition at line 13 of file conf_sections.h.


The documentation for this class was generated from the following files: