• Main Page
  • Namespaces
  • Classes
  • Files
  • File List
  • File Members

C:/CVUT/diplomka/Automata_editor/include/utility/utils.h

Go to the documentation of this file.
00001 #ifndef _UTILS_H_24363650851_
00002 #define _UTILS_H_24363650851_
00003 
00004 #include <QString>
00005 #include <QStringList>
00006 #include <QRegExp>
00007 
00008 // declarations -------------------------------->
00009 
00010 //! makes string in form "abc" from stringlist ["a","b","c"]
00011 QString trStringListToString(const QStringList &strings);
00012 
00013 //! appends suffix if needed, otherwise return false
00014 bool appendFilenameSuffix(QString &fileName, const QString &suffix);
00015 
00016 //! converts list of SharedPointers to subtype to list of SharedPointers to supertype 
00017 //! (TO has to be child of FROM)
00018 template <typename FROM, typename TO>
00019 QList<QSharedPointer<TO> > trSharedPointerListStaticCast(const QList<QSharedPointer<FROM> > &list);
00020 
00021 //! make list's items unique
00022 template <typename T>
00023 QList<T> getUnifiedListKeepOrder(const QList<T> &list);
00024 
00025 // definitions --------------------------------->
00026 
00027 inline QString trStringListToString(const QStringList &strings)
00028 {
00029     return strings.join("");
00030 }
00031 
00032 inline bool appendFilenameSuffix(QString &fileName, const QString &suffix)
00033 {
00034     if (fileName.lastIndexOf(".") != -1)
00035     {
00036         return false;
00037     }
00038     
00039     fileName.append(".").append(suffix);
00040     return true;
00041 }
00042 
00043 template <typename FROM, typename TO>
00044 QList<QSharedPointer<TO> > trSharedPointerListStaticCast(const QList<QSharedPointer<FROM> > &list)
00045 {
00046     typedef QList<QSharedPointer<FROM> >    TInputList;
00047     typedef QList<QSharedPointer<TO> >      TOutputList;
00048     
00049     TOutputList result;
00050     for (typename TInputList::ConstIterator listIt = list.begin();
00051          listIt != list.end();
00052          ++listIt)
00053     {
00054         result << (*listIt);
00055     }
00056     
00057     return result;
00058 }
00059 
00060 template <typename T>
00061 QList<T> getUnifiedListKeepOrder(const QList<T> &list)
00062 {
00063     QList<T>    unifiedList;
00064     QSet<T>     itemsSet;
00065     
00066     for(typename QList<T>::ConstIterator listIt = list.begin();
00067         listIt != list.end();
00068         ++listIt)
00069     {
00070         if (itemsSet.contains(*listIt)) continue;
00071         unifiedList << *listIt;
00072         itemsSet << *listIt;
00073     }
00074     
00075     return unifiedList;
00076 }
00077 
00078 #endif //_STRINGLISTTOSTRING_H_24363650851_

Generated on Tue Jan 4 2011 03:03:22 for Autoamata editor by  doxygen 1.7.0