Esempio n. 1
0
bool
OptionContainer::deserializeOptions( Glib::ustring basePath,
                                     Util::IODeserialize& deser,
                                     OptionContainer& container)
{
    int i = 0;
    bool bFinished = false;
    bool result=true;
    do {
        std::ostringstream strstrm;
        strstrm << basePath << "/" << "Option" << i;

        if ( deser.isExisting( strstrm.str() ) ) {
            Option pOption = Option::deserialize( strstrm.str() + "/",
                                                  deser );
            if ( pOption.getType() != Option::EInvalid ) {
                result &= container.addOption(pOption);
                i++;
            } else {
                bFinished = true;
            }
        } else {
            bFinished = true;
        }
    } while ( !bFinished );

    return result;
}
Esempio n. 2
0
bool OptionContainer::addOption(Option o) {
    if (o.getType()==OptionContainer::Option::EInvalid) {
        return false;
    }
    if (hasOption(o)){
        return false;
    }

    m_Options.push_back(o);

    return true;
}
Esempio n. 3
0
void ConfTool::do_opts (bool annotated, bool changed) {
  (void)annotated;(void)changed;
  std::vector<const char*>* opts = ConfigManager::getOptions();
  size_t i;
  buffer_t value, valid;
  const char* name, *init, *type;

  if (!opts)
    return;

  buffer_init(&value);
  buffer_init(&valid);

  for (i = 0; i < opts->size(); i++) {
    buffer_shrink(&value,0);
    buffer_shrink(&valid,0);
    Option* opt = ConfigManager::get(opts->at(i));
    name = opt->getName();
    type = opt->getType();
    init = opt->getInit();
    opt->query(&value);
    if (!opt->validity(&valid))
      buffer_shrink(&valid,0);
    int eq = buffer_equal1 (&value,init,-1);
    Option::prettyValue(&value);
    if (changed && eq)
      continue;
    cout << name << " = \"" << (NONULL(value.str)) << "\"";
    if (annotated) {
      cout << " #";
      if (!eq)
        cout << " (default: \"" << (NONULL(init)) << "\")";
      cout << " (type: " << (NONULL(type)) << ")";
      if (valid.len)
        cout << " (validity: " << valid.str << ")";
    }
    cout << endl;
  }

  delete opts;
  buffer_free (&value);
  buffer_free (&valid);
}
Esempio n. 4
0
void InputDialog::initializeControl(Option const& opt, QLineEdit* edit) 
{
   connectControl(opt, edit);
   edit->setToolTip(prependRemName(opt.getName(), opt.getDescription()));

   Action* action = new Action(
      boost::bind(&QLineEdit::setText, edit, opt.getOptionString()) );
   m_resetActions.push_back(action);

   Update* update = new Update(
      boost::bind( 
         static_cast<void(*)(QLineEdit*, QString const&)>(SetControl), edit, _1));
   QString name = opt.getName();
   m_setUpdates[name] = update;

   if (opt.getType() == Option::Type_Array) {
      QRegExp rx("^\\[(\\d+,?)+\\]$");
      QValidator* validator(new QRegExpValidator(rx, this));
      edit->setValidator(validator);
      //edit->setMask("");
   }
}
Esempio n. 5
0
//! Inserts an Option into the database, overwriting the record if the
//! option name already exists.  The user is prompted if an overwrite will
//! occur and if \var promptOnOverwrite is set to true.
bool OptionDatabase::insert(Option const& opt, bool const promptOnOverwrite)
{
    Option tmp;
    QString name(opt.getName());

    if ( get(name, tmp) ) {
        if (promptOnOverwrite) {
            QString msg("Option name ");
            msg += name;
            msg += " already exists in database, overwrite?";
            int ret = QMsgBox::question(0, "Option Exists",msg,
                                        QMessageBox::Ok | QMessageBox::Cancel);
            if (ret == QMessageBox::Cancel) {
                return false;
            }
        }
        remove(name,false);
    }

    QString buf("insert into options( 'Name', 'Type', 'Default', 'Options', "
                "'Description', 'Implementation' ) values ( '");
    buf += opt.getName() + "', ";
    buf += QString::number(opt.getType()) + ", ";
    buf += QString::number(opt.getDefaultIndex()) + ", '";
    buf += opt.getOptionString() + "', ";   // No quote!

    QSqlField desc("Description", QVariant::String);
    desc.setValue(opt.getDescription());
    buf += QSqlDatabase::database("QChem").driver()->formatValue(desc);
    buf += ", ";
    buf += QString::number(opt.getImplementation()) + ");";

    qDebug() << "Database insert: " << buf;

    return execute(buf);
}
Esempio n. 6
0
bool RemSection::fixOptionForQChem(QString& name, QString& value) {
   //qDebug() << "Fixing option for QChem" << name << "=" << value;
   bool shouldPrint(true);
   bool isInt;
   Option opt;
   OptionDatabase& db = OptionDatabase::instance();
   bool inDatabase(db.get(name, opt));

   // Skip internal QUI options
   if (name.startsWith("qui_",Qt::CaseInsensitive)) shouldPrint = false;

   // Perform some ad hoc conversions.  These are all triggered in the database
   // by having an entry of the form a|b where a is replaced by b in the input
   // file.  These are set in the InputDialog::initializeControl member function
   QString key = name + "::" + value;
   if (m_adHoc.count(key)) value = m_adHoc[key];

   //fix logicals
   if (inDatabase && opt.getType() == Option::Type_Logical) {
      if (name == "GUI") {
         value = value.toInt() == 0 ? QString::number(0) : QString::number(2);
      }else if (value.toInt() == Qt::Checked) {
         value = QString::number(1);
      }
   }



   //fix reals
   if (name == "CC_DIIS_MAXIMUM_OVERLAP" || 
       name == "CC_DOV_THRESH" ||
       name == "CC_DTHRESHOLD" ||
       name == "CC_HESSIAN_THRESH" ||
       name == "CC_THETA_STEPSIZE") {

       bool ok(true);
       double val = value.toDouble(&ok);

       int exp = floor(log10(val));
       int man = 100 * val * pow(10,-exp);
       //qDebug() << "2) " << man << "x10e" << exp+2;

       value = QString::number(man) + QString("%1").arg(exp+2,2,10,QChar('0'));

   }else if (inDatabase && opt.getType() == Option::Type_Real) {
      value = QString::number(value.toDouble() / opt.doubleStep());
   }


   if (name == "SCF_GUESS_MIX") {
      value = QString::number(value.toInt()/10);
   }

   if (name == "QUI_FROZEN_CORE" && value.toInt() != 0) {
      name = "N_FROZEN_CORE";
      value = "FC";
      shouldPrint = true;
   }

   if (name == "XC_GRID") {
      int ang(value.toInt(&isInt));

      if (isInt) {
         value = QString("%1").arg(ang);
         value = m_options["QUI_RADIAL_GRID"] + value.rightJustified(6,'0');
      }

   }

  
   if (name == "QUI_XOPT1" && value.toInt() > 0) {
      name = "XOPT_STATE_1";
      shouldPrint = true;

      // This is crappy
      key = "QUI_XOPT_SPIN1::";      
      key += m_options["QUI_XOPT_SPIN1"];
      if (m_adHoc.count(key)) m_options["QUI_XOPT_SPIN1"] = m_adHoc[key];

      value = "[" + m_options["QUI_XOPT_SPIN1"]  + ", "
                  + m_options["QUI_XOPT_IRREP1"] + ", "
                  + m_options["QUI_XOPT_STATE1"] + "]";

   }

   if (name == "QUI_XOPT2" && value.toInt() > 0)  {
      name = "XOPT_STATE_2";
      shouldPrint = true;

      key = "QUI_XOPT_SPIN2::";      
      key += m_options["QUI_XOPT_SPIN2"];
      if (m_adHoc.count(key)) m_options["QUI_XOPT_SPIN2"] = m_adHoc[key];

      value = "[" + m_options["QUI_XOPT_SPIN2"]  + ", "
                  + m_options["QUI_XOPT_IRREP2"] + ", "
                  + m_options["QUI_XOPT_STATE2"] + "]";
   }
 

   //qDebug() << "Fixing option for QChem" << name << "=" << value << "print = " << shouldPrint;
   return shouldPrint;
}
Esempio n. 7
0
bool RemSection::fixOptionForQui(QString& name, QString& value) {
   //qDebug() << "Fixing option for QUI" << name << "=" << value;
   Option opt;
   OptionDatabase& db = OptionDatabase::instance();
   bool inDatabase(db.get(name, opt));

   // Perform some ad hoc conversions.  These are all triggered in the database
   // by having an entry of the form a//b where a is replaced by b in the input
   // file.  These are set in the InputDialog::initializeControl member function
   QString key = name + "::" + value;
   if (m_adHoc.count(key)) value = m_adHoc[key];

   //fix logicals
   if (inDatabase && opt.getType() == Option::Type_Logical) {
      if (value.toLower() == "true") {
         value = "1";
      }else if (value.toLower() == "false") {
         value = "0";
      }else if (value.toInt() != 0) {
         value = "1";
      }
   }

   // Fix CCman real variables
 /*  if (name == "CC_DIIS_MAXIMUM_OVERLAP" || 
       name == "CC_DOV_THRESH" ||
       name == "CC_DTHRESHOLD" ||
       name == "CC_HESSIAN_THRESH" ||
       name == "CC_THETA_STEPSIZE") {

       //qDebug() << "1) " << value;
       QString tmp(value);
       tmp.chop(2);
       bool ok(true);
       int exp = value.right(2).toInt(&ok);
       double man = tmp.toDouble(&ok);
       //qDebug() << "2) " << man << "x10-e" << exp;
       man *= pow(10.0,-exp);
       value = QString::number(man);
       
   }else if (inDatabase && opt.getType() == Option::Type_Real) {
      //fix other reals
      value = QString::number(value.toDouble() * opt.doubleStep());
   }*/

   if (name == "SCF_GUESS_MIX") {
      value = QString::number(value.toInt()*10);
   }

   if (name == "XC_GRID") {
      bool isInt(false);
      int g = value.toInt(&isInt); 
      if (isInt) {
         int a = g % 1000000;
         int r = g / 1000000;
         value =QString::number(a); 
         m_options["QUI_RADIAL_GRID"] = QString::number(r);
      }
   }

   //qDebug() << "Fixing option for QUI" << name << "=" << value;
   return true;
}
void OptionsList::usage()
{
  size_t len;
  char buffer[1024], *cp;

  cp = buffer;
  len = sprintf(buffer, "Usage: %s ", program_);
  cp += len;

  bool hasSimpleFlags = false;
	
  for (list<Option>::iterator iter = begin(); iter != end(); iter++)
  {
    Option *opt = &(*iter);
    if (opt->getName() != NULL &&
        !opt->hasArgument() &&
        (len = strlen(opt->getName())) == 1)
    {
      hasSimpleFlags = true;
      break;
    }
  }

  if (hasSimpleFlags)
  {
    *cp++ = '[';
    *cp++ = '-';
		
    for (list<Option>::iterator iter = begin(); iter != end(); iter++)
    {
      Option *opt = &(*iter);
      if (opt->getName() != NULL &&
          !opt->hasArgument() &&
          (len = strlen(opt->getName())) == 1)
      {
	strcpy(cp, opt->getName());
	cp += len;
      }
    }
		
    *cp++ = ']';
  }

  char staging[128], *cp2;
  for (list<Option>::iterator iter = begin(); iter != end(); iter++)
  {
    Option *opt = &(*iter);

    if (opt->getName() != NULL && !opt->hasArgument() && (len = strlen(opt->getName())) == 1)
      continue;
		
    *cp++ = ' ';

    cp2 = staging;
    if (!opt->isRequired())
    {
      *cp2++ = '[';
    }

    if (opt->getType() == Option::eList)
    {
      *cp2++ = '{';
    }
				
    if (opt->getName() != NULL && !opt->hasArgument() && strlen(opt->getName()) > 1)
    {
      len = sprintf(cp2, "-%s", opt->getName());
      cp2 += len;
    }
    else if (opt->getName() != NULL && opt->hasArgument())
    {
      len = sprintf(cp2, "-%s <%s>", opt->getName(), opt->getArgDesc());
      cp2 += len;
    }
    else if (opt->getName() == NULL)
    {
      len = sprintf(cp2, "<%s>", opt->getArgDesc());
      cp2 += len;
    }
		
    if (opt->getType() == Option::eList)
    {
      *cp2++ = '}';
      *cp2++ = '.';
      *cp2++ = '.';
      *cp2++ = '.';
    }
				
    if (!opt->isRequired())
    {
      *cp2++ = ']';
    }

    *cp2 = '\0';
		
    if (((cp2 - staging) + (cp - buffer)) > 79)
    {
      *cp++ = '\n';
      *cp = '\0';
			
      fputs(buffer, stderr);
      strcpy(buffer, "        ");
      cp = buffer + 8;
    }
		
    strcpy(cp, staging);
    cp += cp2 - staging;
  }

  *cp++ = '\n';
  *cp = '\0';
  fputs(buffer, stderr);
	

  for (list<Option>::iterator iter = begin(); iter != end(); iter++)
  {
    Option *opt = &(*iter);
    if (opt->getName() != NULL)
    {
      if (opt->hasArgument())
	sprintf(buffer, "-%-2.2s <%s>", opt->getName(), opt->getArgDesc());
      else
	sprintf(buffer, "-%-6.6s", opt->getName());
    }
    else if (opt->getOrder() >= 0)
    {
      sprintf(buffer, "<%s>", opt->getArgDesc());
    }
    else
    {
      sprintf(buffer, "<%s>...", opt->getArgDesc());
    }
		
    fprintf(stderr, "    %-20.20s : ", buffer);
    const char *cp = opt->getUsage();
    while (*cp != '\0')
    {
      if (*cp == '\n')
      {
	fputc(*cp, stderr);
	int count = 4 + 20 + 1;
	while (count--)
	  fputc(' ', stderr);
				
	fputc('>', stderr);
	fputc(' ', stderr);
      }
      else
      {
	fputc(*cp, stderr);
      }
			
      cp++;
    }
    fputc('\n', stderr);
  }

  exit(256);
}