HomogeneousDevCol.cpp

Go to the documentation of this file.
00001 // Copyright CERN 2012 - Developed in collaboration with GSI
00002 
00003 #include <fesa-core/Sorting/HomogeneousDevCol.h>
00004 
00005 #include <algorithm> // for set intersection and union.
00006 #include <iterator>
00007 
00008 
00009 namespace fesa
00010 {
00011 
00012 HomogeneousDevCol::HomogeneousDevCol()
00013 {
00014 }
00015 
00016 std::vector<AbstractDevice*> HomogeneousDevCol::getAsVector()
00017 {
00018 
00019     //TODO: This implementation requires from the caller to delete the collection
00020     // Why the vector is not returned by copy ?
00021     //  std::vector<Device* >* result =  new std::vector<Device* >();
00022     std::vector<AbstractDevice*> result;
00023     std::set<AbstractDevice *>::const_iterator it;
00024 
00025     for (it = devCol_.begin(); it != devCol_.end(); it++)
00026     {
00027         result.push_back(*it);
00028     }
00029 
00030     return result;
00031 }
00032 
00033 int32_t HomogeneousDevCol::getSize()
00034 {
00035     return static_cast<int32_t>(devCol_.size());
00036 }
00037 
00038 HomogeneousDevCol operator^(HomogeneousDevCol col1, HomogeneousDevCol col2)
00039 {
00040 
00041     std::string criteria1 = col1.getSharedCriteria();
00042     std::string criteria2 = col2.getSharedCriteria();
00043 
00044     std::set<AbstractDevice*> resultSet;
00045 
00046     std::set<AbstractDevice*>* set1 = col1.getDevCol();
00047     std::set<AbstractDevice*>* set2 = col2.getDevCol();
00048 
00049     std::insert_iterator<std::set<AbstractDevice*> > res_ins(resultSet, resultSet.begin());
00050 
00051     std::set_intersection(set1->begin(), set1->end(), set2->begin(), set2->end(), res_ins);
00052 
00053     HomogeneousDevCol res;
00054     res.setDevCol(resultSet);
00055     res.setSharedCriteria("(" + criteria1 + "and" + criteria2 + ")");
00056 
00057     return res;
00058 
00059 }
00060 
00061 HomogeneousDevCol operator+(HomogeneousDevCol col1, HomogeneousDevCol col2)
00062 {
00063 
00064     std::string criteria1 = col1.getSharedCriteria();
00065     std::string criteria2 = col2.getSharedCriteria();
00066 
00067     std::set<AbstractDevice*> resultSet;
00068 
00069     std::set<AbstractDevice*>* set1 = col1.getDevCol();
00070     std::set<AbstractDevice*>* set2 = col2.getDevCol();
00071 
00072     std::insert_iterator<std::set<AbstractDevice*> > res_ins(resultSet, resultSet.begin());
00073 
00074     std::set_union(set1->begin(), set1->end(), set2->begin(), set2->end(), res_ins);
00075 
00076     HomogeneousDevCol res;
00077     res.setDevCol(resultSet);
00078     res.setSharedCriteria("(" + criteria1 + "or" + criteria2 + ")");
00079 
00080     return res;
00081 
00082 }
00083 
00084 } // fesa

Generated on 18 Jan 2013 for Fesa by  doxygen 1.6.1