# a_codsection.cc

Go to the documentation of this file.

    00001 ///
    00002 /// \file       a_codsection.cc
    00003 ///             COD structure for the ALX file parser
    00004 ///
    00005
    00006 /*
    00007     Copyright (C) 2010, Nicolas VIVIEN
    00008     Copyright (C) 2005-2011, Net Direct Inc. (http://www.netdirect.ca/)
    00009
    00010     This program is free software; you can redistribute it and/or modify
    00011     it under the terms of the GNU General Public License as published by
    00012     the Free Software Foundation; either version 2 of the License, or
    00013     (at your option) any later version.
    00014
    00015     This program is distributed in the hope that it will be useful,
    00016     but WITHOUT ANY WARRANTY; without even the implied warranty of
    00017     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
    00018
    00019     See the GNU General Public License in the COPYING file at the
    00020     root directory of this project for more details.
    00021 */
    00022
    00023 #include <iostream>
    00024 #include <fstream>
    00025 #include <sstream>
    00026
    00027 #include "a_codsection.h"
    00028
    00029
    00030 namespace Barry {
    00031
    00032 namespace {
    00033
    00034 std::string trim(const std::string &str) {
    00035         int i;
    00036         int start, end;
    00037
    00038         std::string s;
    00039
    00040         const int len = str.size();
    00041
    00042         // ltrim
    00043         for (i=0; (((str[i]==' ') || (str[i]=='\t') || (str[i]=='\r') || (str[i]=='\n')) && (i<len)); i++);
    00044     start = i;
    00045
    00046     // rtrim
    00047         for (i=len-1; (((str[i]==' ') || (str[i]=='\t') || (str[i]=='\r') || (str[i]=='\n')) && (i>=0)); i--);
    00048         end = i+1;
    00049
    00050     s = str.substr(start, end-start);
    00051
    00052     return s;
    00053 }
    00054
    00055 }
    00056
    00057
    00058 namespace ALX {
    00059
    00060
    00061 CODSection::CODSection(void)
    00062 {
    00063         isRequired = false;
    00064 }
    00065
    00066
    00067 CODSection::CODSection(const xmlpp::SaxParser::AttributeList& attrs)
    00068 {
    00069         isRequired = false;
    00070
    00071         for (xmlpp::SaxParser::AttributeList::const_iterator iter = attrs.begin(); iter != attrs.end(); ++iter) {
    00072                 std::string attribut(iter->name);
    00073                 std::string value(iter->value);
    00074
    00075                 if (attribut == "id")
    00076                         SetID(value);
    00077         }
    00078 }
    00079
    00080
    00081 CODSection::~CODSection(void)
    00082 {
    00083         isRequired = false;
    00084 }
    00085
    00086
    00087 void CODSection::SetID(const std::string& id)
    00088 {
    00089         this->id = id;
    00090 }
    00091
    00092
    00093 void CODSection::SetName(const std::string& name)
    00094 {
    00095         this->name = trim(name);
    00096 }
    00097
    00098
    00099 void CODSection::SetDescription(const std::string& description)
    00100 {
    00101         this->description = trim(description);
    00102 }
    00103
    00104
    00105 void CODSection::SetVersion(const std::string& version)
    00106 {
    00107         this->version = trim(version);
    00108 }
    00109
    00110
    00111 void CODSection::SetVendor(const std::string& vendor)
    00112 {
    00113         this->vendor = trim(vendor);
    00114 }
    00115
    00116
    00117 void CODSection::SetCopyright(const std::string& copyright)
    00118 {
    00119         this->copyright = trim(copyright);
    00120 }
    00121
    00122
    00123 void CODSection::SetDirectory(const std::string& directory)
    00124 {
    00125         this->directory = trim(directory);
    00126 }
    00127
    00128
    00129 void CODSection::SetRequired(const std::string& required)
    00130 {
    00131         std::string s = trim(required);
    00132
    00133         if (s == "true")
    00134                 isRequired = true;
    00135         else
    00136                 isRequired = false;
    00137 }
    00138
    00139
    00140 void CODSection::AddFiles(const std::string& files)
    00141 {
    00142         std::string file;
    00143         std::istringstream iss(files);
    00144
    00145         while( std::getline(iss, file) ) {
    00146                 file = trim(file);
    00147
    00148                 if (file.length() > 0)
    00149                         AddFile(file);
    00150         }
    00151 }
    00152
    00153
    00154 void CODSection::AddFile(const std::string& file)
    00155 {
    00156         codfiles.push_back(file);
    00157 }
    00158
    00159
    00160 } // namespace ALX
    00161
    00162 } // namespace Barry
    00163