/* Network-Integrated Multimedia Middleware (NMM)
 * http://www.motama.com/nmm.html
 *  
 * Copyright (C) 2006-2007
 * Motama GmbH, Saarbruecken, Germany
 * http://www.motama.com
 *  
 * This file is part of NMM. 
 * 
 * NMM is free software; you can redistribute it and/or modify it    
 * under the terms of the GNU General Public License as published by 
 * the Free Software Foundation; only version 2 of the License.      
 * 
 * NMM is distributed in the hope that it will be useful, but WITHOUT 
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY 
 * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public 
 * License for more details.  
 * 
 * You should have received a copy of the GNU General Public License 
 * along with NMM; if not, write to the Free Software Foundation,    
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
 *
 */
#ifndef TVCHANNELLIST_HPP
#define TVCHANNELLIST_HPP TVCHANNELLIST_HPP

#include "nmm/nmm_prefix.hpp"

#include "nmm/Result.hpp"

#include "nmm/plugins/video/tv/interfaces/TVChannel.hpp"
#include "nmm/plugins/video/tv/interfaces/ChannelNotFoundException.hpp"

namespace NMM{

  /**
   * Class for storing TVChannels provided by a TV-Card
   */  
  class TVChannelList : public SerializedValue {
  private:
    NMM::TValue<list<TVChannel> > channels;
    NMM::TValue<nmm_int32> channelNumber; //internal only to number the channels increasing when addChannel() is called

  public:
    TVChannelList();
    TVChannelList(string filename);
    TVChannelList(const TVChannelList& t);

    ~TVChannelList();

    void addChannel(TVChannel cd);
    TVChannel& getChannelByNumber(unsigned int number);
    TVChannel& getChannelByName(string name);
    list<TVChannel> getChannels();

    list<string> getTVCardURLs();

    Result load(string filename);
    Result write(string filename);

    void clear(){channels.getRValue().clear();}
    size_t size() {return channels.getRValue().size();}
    bool empty() {return channels.getRValue().empty();}

  private:
    void registerAttributes();

    void transform(string &s){
      size_t sIt = string::npos;
      size_t sOld = 0;
      do{
        sIt = s.find_first_of(" ", sOld);
        if(sIt != string::npos) s.erase(sIt,1);
        sOld = sIt+1;
      }while(sIt != string::npos);

      string sout = s;
      for (unsigned int i = 0; i <= s.length(); i++){
        sout[i] = toupper(s[i]);
      }
      s=sout;
    }

  };
}
#include "nmm/nmm_suffix.hpp"

#endif
