Commit ef7b5bb2 authored by hjk's avatar hjk Committed by David Schulz

GenericHighlighte: Code cosmetics

The GenericHelper structure is not needed.

Change-Id: I21f394fb81c237958559a61fe4fdef26fe93dee0
Reviewed-by: default avatarDavid Schulz <david.schulz@digia.com>
parent 6f4f47c8
......@@ -39,27 +39,10 @@
using namespace TextEditor;
using namespace Internal;
HighlightDefinition::HighlightDefinition() :
m_keywordCaseSensitivity(Qt::CaseSensitive),
m_singleLineCommentAfterWhiteSpaces(false),
m_indentationBasedFolding(false)
{
QString s(QLatin1String(".():!+,-<=>%&/;?[]^{|}~\\*, \t"));
foreach (const QChar &c, s)
m_delimiters.insert(c);
}
HighlightDefinition::~HighlightDefinition()
{}
bool HighlightDefinition::isValid() const
{
return !m_initialContext.isEmpty();
}
namespace {
template <class Element, class Container>
QSharedPointer<Element> HighlightDefinition::
GenericHelper::create(const QString &name, Container &container)
QSharedPointer<Element> createHelper(const QString &name, Container &container)
{
if (name.isEmpty())
throw HighlighterException();
......@@ -71,8 +54,8 @@ GenericHelper::create(const QString &name, Container &container)
}
template <class Element, class Container>
QSharedPointer<Element> HighlightDefinition::
GenericHelper::find(const QString &name, const Container &container) const
QSharedPointer<Element>
findHelper(const QString &name, const Container &container)
{
typename Container::const_iterator it = container.find(name);
if (it == container.end())
......@@ -81,36 +64,70 @@ GenericHelper::find(const QString &name, const Container &container) const
return it.value();
}
} // anon namespace
HighlightDefinition::HighlightDefinition() :
m_keywordCaseSensitivity(Qt::CaseSensitive),
m_singleLineCommentAfterWhiteSpaces(false),
m_indentationBasedFolding(false)
{
QString s(QLatin1String(".():!+,-<=>%&/;?[]^{|}~\\*, \t"));
foreach (const QChar &c, s)
m_delimiters.insert(c);
}
HighlightDefinition::~HighlightDefinition()
{}
bool HighlightDefinition::isValid() const
{
return !m_initialContext.isEmpty();
}
QSharedPointer<KeywordList> HighlightDefinition::createKeywordList(const QString &list)
{ return m_helper.create<KeywordList>(list, m_lists); }
{
return createHelper<KeywordList>(list, m_lists);
}
QSharedPointer<KeywordList> HighlightDefinition::keywordList(const QString &list)
{ return m_helper.find<KeywordList>(list, m_lists); }
{
return findHelper<KeywordList>(list, m_lists);
}
QSharedPointer<Context> HighlightDefinition::createContext(const QString &context, bool initial)
{
if (initial)
m_initialContext = context;
QSharedPointer<Context> newContext = m_helper.create<Context>(context, m_contexts);
QSharedPointer<Context> newContext = createHelper<Context>(context, m_contexts);
newContext->setName(context);
return newContext;
}
QSharedPointer<Context> HighlightDefinition::initialContext() const
{ return m_helper.find<Context>(m_initialContext, m_contexts); }
{
return findHelper<Context>(m_initialContext, m_contexts);
}
QSharedPointer<Context> HighlightDefinition::context(const QString &context) const
{ return m_helper.find<Context>(context, m_contexts); }
{
return findHelper<Context>(context, m_contexts);
}
const QHash<QString, QSharedPointer<Context> > &HighlightDefinition::contexts() const
{ return m_contexts; }
{
return m_contexts;
}
QSharedPointer<ItemData> HighlightDefinition::createItemData(const QString &itemData)
{ return m_helper.create<ItemData>(itemData, m_itemsData); }
{
return createHelper<ItemData>(itemData, m_itemsData);
}
QSharedPointer<ItemData> HighlightDefinition::itemData(const QString &itemData) const
{ return m_helper.find<ItemData>(itemData, m_itemsData); }
{
return findHelper<ItemData>(itemData, m_itemsData);
}
void HighlightDefinition::setSingleLineComment(const QString &start)
{ m_singleLineComment = start; }
......
......@@ -89,16 +89,6 @@ public:
private:
Q_DISABLE_COPY(HighlightDefinition)
struct GenericHelper
{
template <class Element, class Container>
QSharedPointer<Element> create(const QString &name, Container &container);
template <class Element, class Container>
QSharedPointer<Element> find(const QString &name, const Container &container) const;
};
GenericHelper m_helper;
QHash<QString, QSharedPointer<KeywordList> > m_lists;
QHash<QString, QSharedPointer<Context> > m_contexts;
QHash<QString, QSharedPointer<ItemData> > m_itemsData;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment