MythTV  0.26-pre
inputgroupmap.cpp
Go to the documentation of this file.
00001 // -*- Mode: c++ -*-
00002 /*
00003  *   Copyright (c) Daniel Kristjansson 2007
00004  *
00005  *   This program is free software; you can redistribute it and/or modify
00006  *   it under the terms of the GNU General Public License as published by
00007  *   the Free Software Foundation; either version 2 of the License, or
00008  *   (at your option) any later version.
00009  *
00010  *   This program is distributed in the hope that it will be useful,
00011  *   but WITHOUT ANY WARRANTY; without even the implied warranty of
00012  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00013  *   GNU General Public License for more details.
00014  *
00015  *   You should have received a copy of the GNU General Public License
00016  *   along with this program; if not, write to the Free Software
00017  *   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00018  */
00019 
00020 #include <algorithm>
00021 
00022 #include "inputgroupmap.h"
00023 #include "mythdb.h"
00024 
00025 bool InputGroupMap::Build(void)
00026 {
00027     bool ok = true;
00028     inputgroupmap.clear();
00029     MSqlQuery query(MSqlQuery::InitCon());
00030 
00031     query.prepare("SELECT cardinputid, inputgroupid from inputgroup");
00032     if (!query.exec())
00033     {
00034         MythDB::DBError("InputGroupMap::Build 1", query);
00035         ok = false;
00036     }
00037     else
00038     {
00039         while (query.next())
00040         {
00041             uint inputid = query.value(0).toUInt();
00042             uint groupid = query.value(1).toUInt();
00043             inputgroupmap[inputid].push_back(groupid);
00044         }
00045     }
00046 
00047     query.prepare("SELECT cardinputid, cardid from cardinput");
00048     if (!query.exec())
00049     {
00050         MythDB::DBError("InputGroupMap::Build 2", query);
00051         ok = false;
00052     }
00053     else
00054     {
00055         while (query.next())
00056         {
00057             uint inputid = query.value(0).toUInt();
00058             uint groupid = query.value(1).toUInt() + 1000;
00059             if (inputgroupmap[inputid].empty())
00060                 inputgroupmap[inputid].push_back(groupid);
00061         }
00062     }
00063 
00064     return ok;
00065 }
00066 
00067 uint InputGroupMap::GetSharedInputGroup(uint inputid1, uint inputid2) const
00068 {
00069     const InputGroupList &input1 = inputgroupmap[inputid1];
00070     const InputGroupList &input2 = inputgroupmap[inputid2];
00071     if (input1.empty() || input2.empty())
00072         return 0;
00073 
00074     InputGroupList::const_iterator it;
00075     for (it = input1.begin(); it != input1.end(); ++it)
00076     {
00077         if (find(input2.begin(), input2.end(), *it) != input2.end())
00078             return *it;
00079     }
00080 
00081     return 0;
00082 }
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends