view UniqueString.hpp @ 16:06166d6c083b

Add configuration processing. Cache DB values Add a custom RBTree to save space. Track multiple DB connections properly. More testing. Add ValueExistsException.
author Tom Fredrik Blenning Klaussen <bfg@blenning.no>
date Tue, 28 Aug 2012 18:58:02 +0200
parents
children d0502678429c
line wrap: on
line source

#ifndef UNIQUESTRING_HPP
#define UNIQUESTRING_HPP

#if 0
#include <QtCore/QMap>
#include <QtCore/QString>

class UniqueString : public QString
{
private:
  static QMap<QString, QString> map;
  
public:
  UniqueString(const QString& str)
  {
    if (!map.contains(str)) {
      map.insert(str, str);
    }
    QString::operator=(map.value(str)); 
  }
};
#else
#include "RBTree.hpp"
#include <QtCore/QString>
#include <QtCore/QDebug>

class UniqueString : public QString
{
private:
  static RBTree<QString> map;
  
public:
  UniqueString(const QString& str)
  {
    boost::optional<QString> present = map.find(str);
    if (!present) {
      map.insert(str);
      present = str;
      //qDebug() << map.optimal_depth() << " : " << map.avg_depth() << " : " << map.depth();
    }
    QString::operator=(*present);

  }
};
#endif

#endif //UNIQUESTRING_HPP