<commit_before>// $Id$
//
//  Copyright (C) 2001-2006 Greg Landrum and Rational Discovery LLC
//
//   @@ All Rights Reserved  @@
//
#include <GraphMol/GraphMol.h>
#include <GraphMol/MolOps.h>
#include <GraphMol/Atom.h>
#include <GraphMol/AtomIterators.h>
#include <GraphMol/BondIterators.h>

#include <vector>
#include <algorithm>

#include <boost/graph/connected_components.hpp>
#include <boost/graph/kruskal_min_spanning_tree.hpp>
#include <boost/graph/johnson_all_pairs_shortest.hpp>
#include <boost/property_map.hpp>
#include <boost/config.hpp>
#include <boost/graph/adjacency_list.hpp>
#include <boost/graph/graphviz.hpp>

const int ci_LOCAL_INF=static_cast<int>(1e8);

namespace RDKit{
  namespace MolOps {
    void cleanUp(RWMol &mol) {
      ROMol::AtomIterator ai;
      int aid;
      bool aromHolder;
      for (ai = mol.beginAtoms(); ai != mol.endAtoms(); ai++) {
        switch( (*ai)->getAtomicNum() ){
        case 7:
          // convert neutral 5 coordinate Ns with double bonds to Os to the
          // zwitterionic form.  e.g.:
          //  CN(=O)=O -> C[N+](=O)[O-]
          // and:
          //  C1=CC=CN(=O)=C1 -> C1=CC=C[N+](O)=C1

          // we only want to do neutrals so that things like this don't get
          // munged:
          //  O=[n+]1occcc1
          // this was sf.net issue 1811276
          if((*ai)->getFormalCharge()){
            continue;
          }

          // we need to play this little aromaticity game because the
          // explicit valence code modifies its results for aromatic
          // atoms.
          aromHolder = (*ai)->getIsAromatic();
          (*ai)->setIsAromatic(0);
          // NOTE that we are calling calcExplicitValence() here, we do
          // this because we cannot be sure that it has already been
          // called on the atom (cleanUp() gets called pretty early in
          // the sanitization process):
          if((*ai)->calcExplicitValence(false)==5 ) {
            aid = (*ai)->getIdx();
            RWMol::ADJ_ITER nid1,end1;
            boost::tie(nid1, end1) = mol.getAtomNeighbors(*ai);
            while (nid1 != end1) {
              if ((mol.getAtomWithIdx(*nid1)->getAtomicNum() == 8) &&
                  (mol.getBondBetweenAtoms(aid, *nid1)->getBondType() == Bond::DOUBLE)) {
                // here's the double bonded oxygen
                Bond *b = mol.getBondBetweenAtoms(aid, *nid1);
                b->setBondType(Bond::SINGLE);
                (*ai)->setFormalCharge(1);
                mol.getAtomWithIdx(*nid1)->setFormalCharge(-1);
                break;
              }
              nid1++;
            } // end of loop over the first neigh
          } // if this atom is 5 coordinate nitrogen
          // force a recalculation of the explicit valence here
          (*ai)->setIsAromatic(aromHolder);
          (*ai)->getExplicitValence(true);
          break;
        case 17:
          // recognize perchlorate and convert it from:
          //    Cl(=O)(=O)(=O)[O-]
          // to:
          //    [Cl+3]([O-])([O-])([O-])[O-]
          if((*ai)->calcExplicitValence(false)==7 && (*ai)->getFormalCharge()==0){
            aid = (*ai)->getIdx();
            bool neighborsAllO=true;
            RWMol::ADJ_ITER nid1,end1;
            boost::tie(nid1, end1) = mol.getAtomNeighbors(*ai);
            while (nid1 != end1) {
              if(mol.getAtomWithIdx(*nid1)->getAtomicNum() != 8){
                neighborsAllO = false;
                break;
              }
              nid1++;
            }
            if(neighborsAllO){
              (*ai)->setFormalCharge(3);
              boost::tie(nid1, end1) = mol.getAtomNeighbors(*ai);
              while (nid1 != end1) {
                Bond *b = mol.getBondBetweenAtoms(aid, *nid1);
                if(b->getBondType()==Bond::DOUBLE){
                  b->setBondType(Bond::SINGLE);
                  Atom *otherAtom=mol.getAtomWithIdx(*nid1);
                  otherAtom->setFormalCharge(-1);
                  otherAtom->calcExplicitValence(false);
                }
                nid1++;
              }
              (*ai)->calcExplicitValence(false);
            }
          }
          break;
        }
      }
    }

    void adjustHs(RWMol &mol) {
      //
      //  Go through and adjust the number of implicit and explicit Hs
      //  on each atom in the molecule.
      //
      //  Atoms that do not *need* explicit Hs
      //
      //  Assumptions: this is called after the molecule has been
      //  sanitized, aromaticity has been perceived, and the implicit
      //  valence of everything has been calculated.
      //
      ROMol::AtomIterator ai;
      for (ai = mol.beginAtoms(); ai != mol.endAtoms(); ai++) {
        int origImplicitV = (*ai)->getImplicitValence();
        (*ai)->calcExplicitValence();
        int origExplicitV = (*ai)->getNumExplicitHs();
        //(*ai)->setNumExplicitHs(0);

        int newImplicitV = (*ai)->calcImplicitValence();
        //
        //  Case 1: The disappearing Hydrogen
        //    Smiles:  O=C1NC=CC2=C1C=CC=C2
        //
        //    after perception is done, the N atom has two aromatic
        //    bonds to it and a single implict H.  When the Smiles is
        //    written, we get: n1ccc2ccccc2c1=O.  Here the nitrogen has
        //    no implicit Hs (because there are two aromatic bonds to
        //    it, giving it a valence of 3).  Also: this SMILES is bogus
        //    (un-kekulizable).  The correct SMILES would be:
        //    [nH]1ccc2ccccc2c1=O.  So we need to loop through the atoms
        //    and find those that have lost implicit H; we'll add those
        //    back as explict Hs.
        //
        //    <phew> that takes way longer to comment than it does to
        //    write:
        if(newImplicitV < origImplicitV){
          (*ai)->setNumExplicitHs(origExplicitV+(origImplicitV-newImplicitV));
          (*ai)->calcExplicitValence();
        }
      }
    }

    void sanitizeMol(RWMol &mol) {

      // clear out any cached properties
      mol.clearComputedProps();

      // clean up things like nitro groups
      cleanUp(mol);

      // update computed properties on atoms and bonds:
      mol.updatePropertyCache();

      // first do the keuklizations
      Kekulize(mol);

      // then do aromaticity perception
      setAromaticity(mol);

      // set conjugation
      setConjugation(mol);

      // set hybridization
      setHybridization(mol);

      // remove bogus chirality specs:
      cleanupChirality(mol);

      // adjust Hydrogen counts:
      adjustHs(mol);

    }

    unsigned int getMolFrags(const ROMol &mol, INT_VECT &mapping) {
      mapping.resize(mol.getNumAtoms());
      const MolGraph *G_p = mol.getTopology();
      return boost::connected_components(*G_p,&mapping[0]);
    };

    unsigned int getMolFrags(const ROMol &mol, VECT_INT_VECT &frags) {
      frags.clear();
      INT_VECT mapping;
      getMolFrags(mol, mapping);

      INT_INT_VECT_MAP comMap;
      for (unsigned int i = 0; i < mol.getNumAtoms(); i++) {
        int mi = mapping[i];
        if(comMap.find(mi)==comMap.end()){
          INT_VECT comp;
          comMap[mi] = comp;
        }
        comMap[mi].push_back(i);
      }

      for (INT_INT_VECT_MAP_CI mci = comMap.begin();
               mci != comMap.end();
               mci++) {
           frags.push_back((*mci).second);
      }
      return frags.size();
    }

    void findSpanningTree(const ROMol &mol,INT_VECT &mst){
      //
      //  The BGL provides Prim's and Kruskal's algorithms for finding
      //  the MST of a graph.  Prim's is O(n2) (n=# of atoms) while
      //  Kruskal's is O(e log e) (e=# of bonds).  For molecules, where
      //  e << n2, Kruskal's should be a win.
      //
      const MolGraph *mgraph = mol.getTopology();
      MolGraph *molGraph = const_cast<MolGraph *> (mgraph);
      ROMol::GRAPH_MOL_BOND_PMAP::const_type pMap = mol.getBondPMap();

      std::vector<MolGraph::edge_descriptor> treeEdges;
      treeEdges.reserve(boost::num_vertices(*molGraph));

      boost::property_map < MolGraph, edge_wght_t >::type w = boost::get(edge_wght_t(), *molGraph);
      boost::property_map < MolGraph, edge_bond_t>::type bps = boost::get(edge_bond_t(), *molGraph);
      boost::graph_traits < MolGraph >::edge_iterator e, e_end;
      Bond* bnd;
      for (boost::tie(e, e_end) = boost::edges(*molGraph); e != e_end; ++e) {
        bnd = bps[*e];

        if(!bnd->getIsAromatic()){
          w[*e] = (bnd->getBondTypeAsDouble());
        } else {
          w[*e] = 3.0/2.0;
        }
      }

      // FIX: this is a hack due to problems with MSVC++
#if 1
      typedef boost::graph_traits<MolGraph>::vertices_size_type size_type;
      typedef boost::graph_traits<MolGraph>::vertex_descriptor vertex_t;
      typedef boost::property_map<MolGraph,boost::vertex_index_t>::type index_map_t;
      boost::graph_traits<MolGraph>::vertices_size_type
        n = boost::num_vertices(*molGraph);
      std::vector<size_type> rank_map(n);
      std::vector<vertex_t> pred_map(n);

      boost::detail::kruskal_mst_impl
        (*molGraph, std::back_inserter(treeEdges),
         boost::make_iterator_property_map(rank_map.begin(),
                                           boost::get(boost::vertex_index, *molGraph),
                                           rank_map[0]),
         boost::make_iterator_property_map(pred_map.begin(),
                                           boost::get(boost::vertex_index, *molGraph),
                                           pred_map[0]),
         w);

#else
      boost::kruskal_minimum_spanning_tree(*molGraph,std::back_inserter(treeEdges),
                                           w, *molGraph);
      //boost::weight_map(static_cast<boost::property_map<MolGraph,edge_wght_t>::const_type>(boost::get(edge_wght_t(),*molGraph))));
#endif
      mst.resize(0);
      for(std::vector<MolGraph::edge_descriptor>::iterator edgeIt=treeEdges.begin();
          edgeIt!=treeEdges.end();edgeIt++){
        mst.push_back(pMap[*edgeIt]->getIdx());
      }
    }

    int getFormalCharge(const ROMol &mol){
      int accum = 0;
      for(ROMol::ConstAtomIterator atomIt=mol.beginAtoms();
          atomIt!=mol.endAtoms();
          atomIt++){
        accum += (*atomIt)->getFormalCharge();
      }
      return accum;
    };
  }; // end of namespace MolOps
}; // end of namespace RDKit
<commit_msg>fix an error in an explanatory comment<commit_after>// $Id$
//
//  Copyright (C) 2001-2006 Greg Landrum and Rational Discovery LLC
//
//   @@ All Rights Reserved  @@
//
#include <GraphMol/GraphMol.h>
#include <GraphMol/MolOps.h>
#include <GraphMol/Atom.h>
#include <GraphMol/AtomIterators.h>
#include <GraphMol/BondIterators.h>

#include <vector>
#include <algorithm>

#include <boost/graph/connected_components.hpp>
#include <boost/graph/kruskal_min_spanning_tree.hpp>
#include <boost/graph/johnson_all_pairs_shortest.hpp>
#include <boost/property_map.hpp>
#include <boost/config.hpp>
#include <boost/graph/adjacency_list.hpp>
#include <boost/graph/graphviz.hpp>

const int ci_LOCAL_INF=static_cast<int>(1e8);

namespace RDKit{
  namespace MolOps {
    void cleanUp(RWMol &mol) {
      ROMol::AtomIterator ai;
      int aid;
      bool aromHolder;
      for (ai = mol.beginAtoms(); ai != mol.endAtoms(); ai++) {
        switch( (*ai)->getAtomicNum() ){
        case 7:
          // convert neutral 5 coordinate Ns with double bonds to Os to the
          // zwitterionic form.  e.g.:
          //  CN(=O)=O -> C[N+](=O)[O-]
          // and:
          //  C1=CC=CN(=O)=C1 -> C1=CC=C[N+]([O-])=C1

          // we only want to do neutrals so that things like this don't get
          // munged:
          //  O=[n+]1occcc1
          // this was sf.net issue 1811276
          if((*ai)->getFormalCharge()){
            continue;
          }

          // we need to play this little aromaticity game because the
          // explicit valence code modifies its results for aromatic
          // atoms.
          aromHolder = (*ai)->getIsAromatic();
          (*ai)->setIsAromatic(0);
          // NOTE that we are calling calcExplicitValence() here, we do
          // this because we cannot be sure that it has already been
          // called on the atom (cleanUp() gets called pretty early in
          // the sanitization process):
          if((*ai)->calcExplicitValence(false)==5 ) {
            aid = (*ai)->getIdx();
            RWMol::ADJ_ITER nid1,end1;
            boost::tie(nid1, end1) = mol.getAtomNeighbors(*ai);
            while (nid1 != end1) {
              if ((mol.getAtomWithIdx(*nid1)->getAtomicNum() == 8) &&
                  (mol.getBondBetweenAtoms(aid, *nid1)->getBondType() == Bond::DOUBLE)) {
                // here's the double bonded oxygen
                Bond *b = mol.getBondBetweenAtoms(aid, *nid1);
                b->setBondType(Bond::SINGLE);
                (*ai)->setFormalCharge(1);
                mol.getAtomWithIdx(*nid1)->setFormalCharge(-1);
                break;
              }
              nid1++;
            } // end of loop over the first neigh
          } // if this atom is 5 coordinate nitrogen
          // force a recalculation of the explicit valence here
          (*ai)->setIsAromatic(aromHolder);
          (*ai)->getExplicitValence(true);
          break;
        case 17:
          // recognize perchlorate and convert it from:
          //    Cl(=O)(=O)(=O)[O-]
          // to:
          //    [Cl+3]([O-])([O-])([O-])[O-]
          if((*ai)->calcExplicitValence(false)==7 && (*ai)->getFormalCharge()==0){
            aid = (*ai)->getIdx();
            bool neighborsAllO=true;
            RWMol::ADJ_ITER nid1,end1;
            boost::tie(nid1, end1) = mol.getAtomNeighbors(*ai);
            while (nid1 != end1) {
              if(mol.getAtomWithIdx(*nid1)->getAtomicNum() != 8){
                neighborsAllO = false;
                break;
              }
              nid1++;
            }
            if(neighborsAllO){
              (*ai)->setFormalCharge(3);
              boost::tie(nid1, end1) = mol.getAtomNeighbors(*ai);
              while (nid1 != end1) {
                Bond *b = mol.getBondBetweenAtoms(aid, *nid1);
                if(b->getBondType()==Bond::DOUBLE){
                  b->setBondType(Bond::SINGLE);
                  Atom *otherAtom=mol.getAtomWithIdx(*nid1);
                  otherAtom->setFormalCharge(-1);
                  otherAtom->calcExplicitValence(false);
                }
                nid1++;
              }
              (*ai)->calcExplicitValence(false);
            }
          }
          break;
        }
      }
    }

    void adjustHs(RWMol &mol) {
      //
      //  Go through and adjust the number of implicit and explicit Hs
      //  on each atom in the molecule.
      //
      //  Atoms that do not *need* explicit Hs
      //
      //  Assumptions: this is called after the molecule has been
      //  sanitized, aromaticity has been perceived, and the implicit
      //  valence of everything has been calculated.
      //
      ROMol::AtomIterator ai;
      for (ai = mol.beginAtoms(); ai != mol.endAtoms(); ai++) {
        int origImplicitV = (*ai)->getImplicitValence();
        (*ai)->calcExplicitValence();
        int origExplicitV = (*ai)->getNumExplicitHs();
        //(*ai)->setNumExplicitHs(0);

        int newImplicitV = (*ai)->calcImplicitValence();
        //
        //  Case 1: The disappearing Hydrogen
        //    Smiles:  O=C1NC=CC2=C1C=CC=C2
        //
        //    after perception is done, the N atom has two aromatic
        //    bonds to it and a single implict H.  When the Smiles is
        //    written, we get: n1ccc2ccccc2c1=O.  Here the nitrogen has
        //    no implicit Hs (because there are two aromatic bonds to
        //    it, giving it a valence of 3).  Also: this SMILES is bogus
        //    (un-kekulizable).  The correct SMILES would be:
        //    [nH]1ccc2ccccc2c1=O.  So we need to loop through the atoms
        //    and find those that have lost implicit H; we'll add those
        //    back as explict Hs.
        //
        //    <phew> that takes way longer to comment than it does to
        //    write:
        if(newImplicitV < origImplicitV){
          (*ai)->setNumExplicitHs(origExplicitV+(origImplicitV-newImplicitV));
          (*ai)->calcExplicitValence();
        }
      }
    }

    void sanitizeMol(RWMol &mol) {

      // clear out any cached properties
      mol.clearComputedProps();

      // clean up things like nitro groups
      cleanUp(mol);

      // update computed properties on atoms and bonds:
      mol.updatePropertyCache();

      // first do the keuklizations
      Kekulize(mol);

      // then do aromaticity perception
      setAromaticity(mol);

      // set conjugation
      setConjugation(mol);

      // set hybridization
      setHybridization(mol);

      // remove bogus chirality specs:
      cleanupChirality(mol);

      // adjust Hydrogen counts:
      adjustHs(mol);

    }

    unsigned int getMolFrags(const ROMol &mol, INT_VECT &mapping) {
      mapping.resize(mol.getNumAtoms());
      const MolGraph *G_p = mol.getTopology();
      return boost::connected_components(*G_p,&mapping[0]);
    };

    unsigned int getMolFrags(const ROMol &mol, VECT_INT_VECT &frags) {
      frags.clear();
      INT_VECT mapping;
      getMolFrags(mol, mapping);

      INT_INT_VECT_MAP comMap;
      for (unsigned int i = 0; i < mol.getNumAtoms(); i++) {
        int mi = mapping[i];
        if(comMap.find(mi)==comMap.end()){
          INT_VECT comp;
          comMap[mi] = comp;
        }
        comMap[mi].push_back(i);
      }

      for (INT_INT_VECT_MAP_CI mci = comMap.begin();
               mci != comMap.end();
               mci++) {
           frags.push_back((*mci).second);
      }
      return frags.size();
    }

    void findSpanningTree(const ROMol &mol,INT_VECT &mst){
      //
      //  The BGL provides Prim's and Kruskal's algorithms for finding
      //  the MST of a graph.  Prim's is O(n2) (n=# of atoms) while
      //  Kruskal's is O(e log e) (e=# of bonds).  For molecules, where
      //  e << n2, Kruskal's should be a win.
      //
      const MolGraph *mgraph = mol.getTopology();
      MolGraph *molGraph = const_cast<MolGraph *> (mgraph);
      ROMol::GRAPH_MOL_BOND_PMAP::const_type pMap = mol.getBondPMap();

      std::vector<MolGraph::edge_descriptor> treeEdges;
      treeEdges.reserve(boost::num_vertices(*molGraph));

      boost::property_map < MolGraph, edge_wght_t >::type w = boost::get(edge_wght_t(), *molGraph);
      boost::property_map < MolGraph, edge_bond_t>::type bps = boost::get(edge_bond_t(), *molGraph);
      boost::graph_traits < MolGraph >::edge_iterator e, e_end;
      Bond* bnd;
      for (boost::tie(e, e_end) = boost::edges(*molGraph); e != e_end; ++e) {
        bnd = bps[*e];

        if(!bnd->getIsAromatic()){
          w[*e] = (bnd->getBondTypeAsDouble());
        } else {
          w[*e] = 3.0/2.0;
        }
      }

      // FIX: this is a hack due to problems with MSVC++
#if 1
      typedef boost::graph_traits<MolGraph>::vertices_size_type size_type;
      typedef boost::graph_traits<MolGraph>::vertex_descriptor vertex_t;
      typedef boost::property_map<MolGraph,boost::vertex_index_t>::type index_map_t;
      boost::graph_traits<MolGraph>::vertices_size_type
        n = boost::num_vertices(*molGraph);
      std::vector<size_type> rank_map(n);
      std::vector<vertex_t> pred_map(n);

      boost::detail::kruskal_mst_impl
        (*molGraph, std::back_inserter(treeEdges),
         boost::make_iterator_property_map(rank_map.begin(),
                                           boost::get(boost::vertex_index, *molGraph),
                                           rank_map[0]),
         boost::make_iterator_property_map(pred_map.begin(),
                                           boost::get(boost::vertex_index, *molGraph),
                                           pred_map[0]),
         w);

#else
      boost::kruskal_minimum_spanning_tree(*molGraph,std::back_inserter(treeEdges),
                                           w, *molGraph);
      //boost::weight_map(static_cast<boost::property_map<MolGraph,edge_wght_t>::const_type>(boost::get(edge_wght_t(),*molGraph))));
#endif
      mst.resize(0);
      for(std::vector<MolGraph::edge_descriptor>::iterator edgeIt=treeEdges.begin();
          edgeIt!=treeEdges.end();edgeIt++){
        mst.push_back(pMap[*edgeIt]->getIdx());
      }
    }

    int getFormalCharge(const ROMol &mol){
      int accum = 0;
      for(ROMol::ConstAtomIterator atomIt=mol.beginAtoms();
          atomIt!=mol.endAtoms();
          atomIt++){
        accum += (*atomIt)->getFormalCharge();
      }
      return accum;
    };
  }; // end of namespace MolOps
}; // end of namespace RDKit
<|endoftext|>


<commit_before>/*
    aboutdata.cpp

    This file is part of Kleopatra, the KDE keymanager
    Copyright (c) 2001,2002,2004 Klarälvdalens Datakonsult AB

    Kleopatra is free software; you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation; either version 2 of the License, or
    (at your option) any later version.

    Kleopatra is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
    General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with this program; if not, write to the Free Software
    Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA

    In addition, as a special exception, the copyright holders give
    permission to link the code of this program with any edition of
    the Qt library by Trolltech AS, Norway (or with modified versions
    of Qt that use the same license as Qt), and distribute linked
    combinations including the two.  You must obey the GNU General
    Public License in all respects for all of the code used other than
    Qt.  If you modify this file, you may extend this exception to
    your version of the file, but you are not obligated to do so.  If
    you do not wish to do so, delete this exception statement from
    your version.
*/

#include <config-kleopatra.h>

#include "aboutdata.h"

#include <klocale.h>
#include <kiconloader.h>

#include <QPixmap>
#include <QVariant>

#include <cassert>

static const char kleopatra_version[] = KLEOPATRA_VERSION_STRING;
static const char description[] = I18N_NOOP("Certificate Manager and Unified Crypto GUI");

struct about_data {
  const char * name;
  const char * desc;
  const char * email;
  const char * web;
};

static const about_data authors[] = {
  { "Marc Mutz", I18N_NOOP("Current Maintainer"), "mutz@kde.org", 0 },
  { "Steffen Hansen", I18N_NOOP("Former Maintainer"), "hansen@kde.org", 0 },
  { "Matthias Kalle Dalheimer", I18N_NOOP("Original Author"), "kalle@kde.org", 0 },
};

static const about_data credits[] = {
  { I18N_NOOP("David Faure"),
    I18N_NOOP("Backend configuration framework, KIO integration"),
    "faure@kde.org", 0 },
  { I18N_NOOP("Michel Boyer de la Giroday"),
    I18N_NOOP("Key-state dependant colors and fonts in the key list"),
    "michel@klaralvdalens-datakonsult.se", 0 },
  { I18N_NOOP("Thomas Moenicke"),
    I18N_NOOP("Artwork"),
    "tm@php-qt.org", 0 },
  { I18N_NOOP("Frank Osterfeld"),
    I18N_NOOP("Resident gpgme/win wrangler, UI Server commands and dialogs"),
    "osterfeld@kde.org", 0 },
  { I18N_NOOP("Karl-Heinz Zimmer"),
    I18N_NOOP("DN display ordering support, infrastructure"),
    "khz@kde.org", 0 },
};

AboutData::AboutData()
  : KAboutData( "kleopatra", 0, ki18n("Kleopatra"),
		kleopatra_version, ki18n(description), License_GPL,
		ki18n("(c) 2002 Steffen\xC2\xA0Hansen, Matthias\xC2\xA0Kalle\xC2\xA0" "Dalheimer, Klar\xC3\xA4lvdalens\xC2\xA0" "Datakonsult\xC2\xA0" "AB\n"
		      "(c) 2004, 2007, 2008, 2009 Marc\xC2\xA0Mutz, Klar\xC3\xA4lvdalens\xC2\xA0" "Datakonsult\xC2\xA0" "AB") )
{
  using ::authors;
  using ::credits;
  for ( unsigned int i = 0 ; i < sizeof authors / sizeof *authors ; ++i )
    addAuthor( ki18n(authors[i].name), ki18n(authors[i].desc),
	       authors[i].email, authors[i].web );
  for ( unsigned int i = 0 ; i < sizeof credits / sizeof *credits ; ++i )
    addCredit( ki18n(credits[i].name), ki18n(credits[i].desc),
	       credits[i].email, credits[i].web );
}

static const char gpg4win_description[] = I18N_NOOP( "Gpg4win is an installer package for Windows for EMail and "
                                                     "file encryption using the core component GnuPG for Windows. "
                                                     "Both relevant cryptography standards are supported, OpenPGP "
                                                     "and S/MIME. Gpg4win and the software included with Gpg4win "
                                                     "are Free Software.");
static const char gpg4win_version[] = "1.9.15-beta"; // ### make this better come from somewhere...

static QPixmap UserIcon_nocached2( const char * name ) {
    // KIconLoader insists on caching all pixmaps. Since the splash
    // screen is a particularly large 'icon' and used only once,
    // caching is unneccesary and just hurts startup preformance.
    KIconLoader * const il = KIconLoader::global();
    assert( il );
    const QString iconPath = il->iconPath( QLatin1String( name ), KIconLoader::User );
    return iconPath.isEmpty() ? il->unknown() : QPixmap( iconPath ) ;
}

AboutGpg4WinData::AboutGpg4WinData()
    : KAboutData( "gpg4win", 0, ki18n("Gpg4win"),
                  gpg4win_version, ki18n(gpg4win_description),
                  License_GPL, KLocalizedString(), KLocalizedString(), "http://www.gpg4win.de" )
{
    addAuthor( ki18n("Intevation GmbH (Project Management)"), KLocalizedString(), 0, "http://www.intevation.de" );
    addAuthor( ki18n("g\xC2\xB9\xC2\xBA" "code GmbH (Crypto Functionality, GpgOL, GpgEX, GPA)"), KLocalizedString(), 0, "http://www.g10code.de" );
    addAuthor( ki18n("KDAB (Kleopatra)"), KLocalizedString(), 0, "http://www.kdab.com" );
    setCustomAuthorText( ki18n("Gpg4win is being developed by the following companies:"),
                         ki18n("Gpg4win is being developed by the following companies:") );
    setProgramLogo( UserIcon_nocached2( "gpg4win" ) );
}
<commit_msg>update gpg4win version to 1.9.16<commit_after>/*
    aboutdata.cpp

    This file is part of Kleopatra, the KDE keymanager
    Copyright (c) 2001,2002,2004 Klarälvdalens Datakonsult AB

    Kleopatra is free software; you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation; either version 2 of the License, or
    (at your option) any later version.

    Kleopatra is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
    General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with this program; if not, write to the Free Software
    Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA

    In addition, as a special exception, the copyright holders give
    permission to link the code of this program with any edition of
    the Qt library by Trolltech AS, Norway (or with modified versions
    of Qt that use the same license as Qt), and distribute linked
    combinations including the two.  You must obey the GNU General
    Public License in all respects for all of the code used other than
    Qt.  If you modify this file, you may extend this exception to
    your version of the file, but you are not obligated to do so.  If
    you do not wish to do so, delete this exception statement from
    your version.
*/

#include <config-kleopatra.h>

#include "aboutdata.h"

#include <klocale.h>
#include <kiconloader.h>

#include <QPixmap>
#include <QVariant>

#include <cassert>

static const char kleopatra_version[] = KLEOPATRA_VERSION_STRING;
static const char description[] = I18N_NOOP("Certificate Manager and Unified Crypto GUI");

struct about_data {
  const char * name;
  const char * desc;
  const char * email;
  const char * web;
};

static const about_data authors[] = {
  { "Marc Mutz", I18N_NOOP("Current Maintainer"), "mutz@kde.org", 0 },
  { "Steffen Hansen", I18N_NOOP("Former Maintainer"), "hansen@kde.org", 0 },
  { "Matthias Kalle Dalheimer", I18N_NOOP("Original Author"), "kalle@kde.org", 0 },
};

static const about_data credits[] = {
  { I18N_NOOP("David Faure"),
    I18N_NOOP("Backend configuration framework, KIO integration"),
    "faure@kde.org", 0 },
  { I18N_NOOP("Michel Boyer de la Giroday"),
    I18N_NOOP("Key-state dependant colors and fonts in the key list"),
    "michel@klaralvdalens-datakonsult.se", 0 },
  { I18N_NOOP("Thomas Moenicke"),
    I18N_NOOP("Artwork"),
    "tm@php-qt.org", 0 },
  { I18N_NOOP("Frank Osterfeld"),
    I18N_NOOP("Resident gpgme/win wrangler, UI Server commands and dialogs"),
    "osterfeld@kde.org", 0 },
  { I18N_NOOP("Karl-Heinz Zimmer"),
    I18N_NOOP("DN display ordering support, infrastructure"),
    "khz@kde.org", 0 },
};

AboutData::AboutData()
  : KAboutData( "kleopatra", 0, ki18n("Kleopatra"),
		kleopatra_version, ki18n(description), License_GPL,
		ki18n("(c) 2002 Steffen\xC2\xA0Hansen, Matthias\xC2\xA0Kalle\xC2\xA0" "Dalheimer, Klar\xC3\xA4lvdalens\xC2\xA0" "Datakonsult\xC2\xA0" "AB\n"
		      "(c) 2004, 2007, 2008, 2009 Marc\xC2\xA0Mutz, Klar\xC3\xA4lvdalens\xC2\xA0" "Datakonsult\xC2\xA0" "AB") )
{
  using ::authors;
  using ::credits;
  for ( unsigned int i = 0 ; i < sizeof authors / sizeof *authors ; ++i )
    addAuthor( ki18n(authors[i].name), ki18n(authors[i].desc),
	       authors[i].email, authors[i].web );
  for ( unsigned int i = 0 ; i < sizeof credits / sizeof *credits ; ++i )
    addCredit( ki18n(credits[i].name), ki18n(credits[i].desc),
	       credits[i].email, credits[i].web );
}

static const char gpg4win_description[] = I18N_NOOP( "Gpg4win is an installer package for Windows for EMail and "
                                                     "file encryption using the core component GnuPG for Windows. "
                                                     "Both relevant cryptography standards are supported, OpenPGP "
                                                     "and S/MIME. Gpg4win and the software included with Gpg4win "
                                                     "are Free Software.");
static const char gpg4win_version[] = "1.9.16-beta"; // ### make this better come from somewhere...

static QPixmap UserIcon_nocached2( const char * name ) {
    // KIconLoader insists on caching all pixmaps. Since the splash
    // screen is a particularly large 'icon' and used only once,
    // caching is unneccesary and just hurts startup preformance.
    KIconLoader * const il = KIconLoader::global();
    assert( il );
    const QString iconPath = il->iconPath( QLatin1String( name ), KIconLoader::User );
    return iconPath.isEmpty() ? il->unknown() : QPixmap( iconPath ) ;
}

AboutGpg4WinData::AboutGpg4WinData()
    : KAboutData( "gpg4win", 0, ki18n("Gpg4win"),
                  gpg4win_version, ki18n(gpg4win_description),
                  License_GPL, KLocalizedString(), KLocalizedString(), "http://www.gpg4win.de" )
{
    addAuthor( ki18n("Intevation GmbH (Project Management)"), KLocalizedString(), 0, "http://www.intevation.de" );
    addAuthor( ki18n("g\xC2\xB9\xC2\xBA" "code GmbH (Crypto Functionality, GpgOL, GpgEX, GPA)"), KLocalizedString(), 0, "http://www.g10code.de" );
    addAuthor( ki18n("KDAB (Kleopatra)"), KLocalizedString(), 0, "http://www.kdab.com" );
    setCustomAuthorText( ki18n("Gpg4win is being developed by the following companies:"),
                         ki18n("Gpg4win is being developed by the following companies:") );
    setProgramLogo( UserIcon_nocached2( "gpg4win" ) );
}
<|endoftext|>


<commit_before>/*************************************************************************
 *
 *  OpenOffice.org - a multi-platform office productivity suite
 *
 *  $RCSfile: TDatabaseMetaDataBase.hxx,v $
 *
 *  $Revision: 1.5 $
 *
 *  last change: $Author: rt $ $Date: 2008-01-30 07:59:47 $
 *
 *  The Contents of this file are made available subject to
 *  the terms of GNU Lesser General Public License Version 2.1.
 *
 *
 *    GNU Lesser General Public License Version 2.1
 *    =============================================
 *    Copyright 2005 by Sun Microsystems, Inc.
 *    901 San Antonio Road, Palo Alto, CA 94303, USA
 *
 *    This library is free software; you can redistribute it and/or
 *    modify it under the terms of the GNU Lesser General Public
 *    License version 2.1, as published by the Free Software Foundation.
 *
 *    This library is distributed in the hope that it will be useful,
 *    but WITHOUT ANY WARRANTY; without even the implied warranty of
 *    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 *    Lesser General Public License for more details.
 *
 *    You should have received a copy of the GNU Lesser General Public
 *    License along with this library; if not, write to the Free Software
 *    Foundation, Inc., 59 Temple Place, Suite 330, Boston,
 *    MA  02111-1307  USA
 *
 ************************************************************************/

#ifndef _CONNECTIVITY_ODATABASEMETADATABASE_HXX_
#define _CONNECTIVITY_ODATABASEMETADATABASE_HXX_

#ifndef _COM_SUN_STAR_SDBC_XDATABASEMETADATA2_HPP_
#include <com/sun/star/sdbc/XDatabaseMetaData2.hpp>
#endif
#ifndef _CPPUHELPER_IMPLBASE2_HXX_
#include <cppuhelper/implbase2.hxx>
#endif
#ifndef _COMPHELPER_BROADCASTHELPER_HXX_
#include <comphelper/broadcasthelper.hxx>
#endif
#ifndef _COM_SUN_STAR_LANG_XEVENTLISTENER_HPP_
#include <com/sun/star/lang/XEventListener.hpp>
#endif
#include "FDatabaseMetaDataResultSet.hxx"
#include <functional>

namespace connectivity
{
        typedef ::com::sun::star::uno::Sequence< ::com::sun::star::uno::Any >  TConditions;
        class ODatabaseMetaDataBase :   public  comphelper::OBaseMutex,
                                        public ::cppu::WeakImplHelper2< ::com::sun::star::sdbc::XDatabaseMetaData2,
                                                                        ::com::sun::star::lang::XEventListener>
        {
        private:
            ::com::sun::star::uno::Sequence< ::com::sun::star::beans::PropertyValue >   m_aConnectionInfo;
            ::connectivity::ODatabaseMetaDataResultSet::ORows                           m_aTypeInfoRows;

            // cached database information
            ::std::pair<bool,sal_Bool>          m_isCatalogAtStart;
            ::std::pair<bool,::rtl::OUString>   m_sCatalogSeparator;
            ::std::pair<bool,::rtl::OUString>   m_sIdentifierQuoteString;
            ::std::pair<bool,sal_Bool>          m_supportsCatalogsInTableDefinitions;
            ::std::pair<bool,sal_Bool>          m_supportsSchemasInTableDefinitions;
            ::std::pair<bool,sal_Bool>          m_supportsCatalogsInDataManipulation;
            ::std::pair<bool,sal_Bool>          m_supportsSchemasInDataManipulation;
            ::std::pair<bool,sal_Bool>          m_supportsMixedCaseQuotedIdentifiers;
            ::std::pair<bool,sal_Bool>          m_supportsAlterTableWithAddColumn;
            ::std::pair<bool,sal_Bool>          m_supportsAlterTableWithDropColumn;
            ::std::pair<bool,sal_Int32>         m_MaxStatements;
            ::std::pair<bool,sal_Int32>         m_MaxTablesInSelect;
            ::std::pair<bool,sal_Bool>          m_storesMixedCaseQuotedIdentifiers;

            template <typename T> T callImplMethod(::std::pair<bool,T>& _rCache,const ::std::mem_fun_t<T,ODatabaseMetaDataBase>& _pImplMethod)
            {
                ::osl::MutexGuard aGuard( m_aMutex );
                if ( !_rCache.first )
                {
                    _rCache.second = _pImplMethod(this);
                    _rCache.first = true;
                }
                return _rCache.second;
            }
        protected:
            ::com::sun::star::uno::Reference< ::com::sun::star::sdbc::XConnection >     m_xConnection;
            ::com::sun::star::uno::Reference< ::com::sun::star::lang::XEventListener>   m_xListenerHelper; // forward the calls from the connection to me

            virtual ~ODatabaseMetaDataBase();

        protected:
            virtual ::com::sun::star::uno::Reference< ::com::sun::star::sdbc::XResultSet > impl_getTypeInfo_throw() = 0;
            // cached database information
            virtual ::rtl::OUString impl_getIdentifierQuoteString_throw(  )             = 0;
            virtual sal_Bool        impl_isCatalogAtStart_throw(  )                     = 0;
            virtual ::rtl::OUString impl_getCatalogSeparator_throw(  )                  = 0;
            virtual sal_Bool        impl_supportsCatalogsInTableDefinitions_throw(  )   = 0;
            virtual sal_Bool        impl_supportsSchemasInTableDefinitions_throw(  )    = 0;
            virtual sal_Bool        impl_supportsCatalogsInDataManipulation_throw(  )   = 0;
            virtual sal_Bool        impl_supportsSchemasInDataManipulation_throw(  )    = 0;
            virtual sal_Bool        impl_supportsMixedCaseQuotedIdentifiers_throw(  )   = 0;
            virtual sal_Bool        impl_supportsAlterTableWithAddColumn_throw(  )      = 0;
            virtual sal_Bool        impl_supportsAlterTableWithDropColumn_throw(  )     = 0;
            virtual sal_Int32       impl_getMaxStatements_throw(  )                     = 0;
            virtual sal_Int32       impl_getMaxTablesInSelect_throw(  )                 = 0;
            virtual sal_Bool        impl_storesMixedCaseQuotedIdentifiers_throw(  )     = 0;

        public:

            ODatabaseMetaDataBase(const ::com::sun::star::uno::Reference< ::com::sun::star::sdbc::XConnection >& _rxConnection,const ::com::sun::star::uno::Sequence< ::com::sun::star::beans::PropertyValue >& _rInfo);

            // XDatabaseMetaData2
            virtual ::com::sun::star::uno::Sequence< ::com::sun::star::beans::PropertyValue > SAL_CALL getConnectionInfo(  ) throw (::com::sun::star::uno::RuntimeException);

            // XEventListener
            virtual void SAL_CALL disposing( const ::com::sun::star::lang::EventObject& Source ) throw(::com::sun::star::uno::RuntimeException);

            virtual ::com::sun::star::uno::Reference< ::com::sun::star::sdbc::XResultSet > SAL_CALL getTypeInfo(  ) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException);
            virtual ::com::sun::star::uno::Reference< ::com::sun::star::sdbc::XResultSet > SAL_CALL getProcedures( const ::com::sun::star::uno::Any& catalog, const ::rtl::OUString& schemaPattern, const ::rtl::OUString& procedureNamePattern ) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException);
            virtual ::com::sun::star::uno::Reference< ::com::sun::star::sdbc::XResultSet > SAL_CALL getProcedureColumns( const ::com::sun::star::uno::Any& catalog, const ::rtl::OUString& schemaPattern, const ::rtl::OUString& procedureNamePattern, const ::rtl::OUString& columnNamePattern ) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException);
            virtual ::com::sun::star::uno::Reference< ::com::sun::star::sdbc::XResultSet > SAL_CALL getSchemas(  ) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException);
            virtual ::com::sun::star::uno::Reference< ::com::sun::star::sdbc::XResultSet > SAL_CALL getCatalogs(  ) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException);
            virtual ::com::sun::star::uno::Reference< ::com::sun::star::sdbc::XResultSet > SAL_CALL getColumnPrivileges( const ::com::sun::star::uno::Any& catalog, const ::rtl::OUString& schema, const ::rtl::OUString& table, const ::rtl::OUString& columnNamePattern ) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException);
            virtual ::com::sun::star::uno::Reference< ::com::sun::star::sdbc::XResultSet > SAL_CALL getTablePrivileges( const ::com::sun::star::uno::Any& catalog, const ::rtl::OUString& schemaPattern, const ::rtl::OUString& tableNamePattern ) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException);
            virtual ::com::sun::star::uno::Reference< ::com::sun::star::sdbc::XResultSet > SAL_CALL getBestRowIdentifier( const ::com::sun::star::uno::Any& catalog, const ::rtl::OUString& schema, const ::rtl::OUString& table, sal_Int32 scope, sal_Bool nullable ) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException);
            virtual ::com::sun::star::uno::Reference< ::com::sun::star::sdbc::XResultSet > SAL_CALL getVersionColumns( const ::com::sun::star::uno::Any& catalog, const ::rtl::OUString& schema, const ::rtl::OUString& table ) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException);
            virtual ::com::sun::star::uno::Reference< ::com::sun::star::sdbc::XResultSet > SAL_CALL getPrimaryKeys( const ::com::sun::star::uno::Any& catalog, const ::rtl::OUString& schema, const ::rtl::OUString& table ) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException);
            virtual ::com::sun::star::uno::Reference< ::com::sun::star::sdbc::XResultSet > SAL_CALL getImportedKeys( const ::com::sun::star::uno::Any& catalog, const ::rtl::OUString& schema, const ::rtl::OUString& table ) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException);
            virtual ::com::sun::star::uno::Reference< ::com::sun::star::sdbc::XResultSet > SAL_CALL getExportedKeys( const ::com::sun::star::uno::Any& catalog, const ::rtl::OUString& schema, const ::rtl::OUString& table ) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException);
            virtual ::com::sun::star::uno::Reference< ::com::sun::star::sdbc::XResultSet > SAL_CALL getCrossReference( const ::com::sun::star::uno::Any& primaryCatalog, const ::rtl::OUString& primarySchema, const ::rtl::OUString& primaryTable, const ::com::sun::star::uno::Any& foreignCatalog, const ::rtl::OUString& foreignSchema, const ::rtl::OUString& foreignTable ) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException);
            virtual ::com::sun::star::uno::Reference< ::com::sun::star::sdbc::XResultSet > SAL_CALL getIndexInfo( const ::com::sun::star::uno::Any& catalog, const ::rtl::OUString& schema, const ::rtl::OUString& table, sal_Bool unique, sal_Bool approximate ) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException);

            virtual ::com::sun::star::uno::Reference< ::com::sun::star::sdbc::XConnection > SAL_CALL getConnection(  ) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException);
            // cached database information
            virtual ::rtl::OUString SAL_CALL getIdentifierQuoteString(  ) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException);
            virtual sal_Bool SAL_CALL isCatalogAtStart(  ) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException);
            virtual ::rtl::OUString SAL_CALL getCatalogSeparator(  ) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException);
            virtual sal_Bool SAL_CALL supportsCatalogsInTableDefinitions(  ) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException);
            virtual sal_Bool SAL_CALL supportsSchemasInTableDefinitions(  ) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException);
            virtual sal_Bool SAL_CALL supportsCatalogsInDataManipulation(  ) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException);
            virtual sal_Bool SAL_CALL supportsSchemasInDataManipulation(  ) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException);
            virtual sal_Bool SAL_CALL supportsMixedCaseQuotedIdentifiers(  ) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException);
            virtual sal_Bool SAL_CALL supportsAlterTableWithAddColumn(  ) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException);
            virtual sal_Bool SAL_CALL supportsAlterTableWithDropColumn(  ) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException);
            virtual sal_Int32 SAL_CALL getMaxStatements(  ) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException);
            virtual sal_Int32 SAL_CALL getMaxTablesInSelect(  ) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException);
            virtual sal_Bool SAL_CALL storesMixedCaseQuotedIdentifiers(  ) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException);
        };
}
#endif // _CONNECTIVITY_ODATABASEMETADATABASE_HXX_
<commit_msg>INTEGRATION: CWS changefileheader (1.5.22); FILE MERGED 2008/04/01 15:09:06 thb 1.5.22.3: #i85898# Stripping all external header guards 2008/04/01 10:53:16 thb 1.5.22.2: #i85898# Stripping all external header guards 2008/03/28 15:24:05 rt 1.5.22.1: #i87441# Change license header to LPGL v3.<commit_after>/*************************************************************************
 *
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
 *
 * Copyright 2008 by Sun Microsystems, Inc.
 *
 * OpenOffice.org - a multi-platform office productivity suite
 *
 * $RCSfile: TDatabaseMetaDataBase.hxx,v $
 * $Revision: 1.6 $
 *
 * This file is part of OpenOffice.org.
 *
 * OpenOffice.org is free software: you can redistribute it and/or modify
 * it under the terms of the GNU Lesser General Public License version 3
 * only, as published by the Free Software Foundation.
 *
 * OpenOffice.org is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU Lesser General Public License version 3 for more details
 * (a copy is included in the LICENSE file that accompanied this code).
 *
 * You should have received a copy of the GNU Lesser General Public License
 * version 3 along with OpenOffice.org.  If not, see
 * <http://www.openoffice.org/license.html>
 * for a copy of the LGPLv3 License.
 *
 ************************************************************************/

#ifndef _CONNECTIVITY_ODATABASEMETADATABASE_HXX_
#define _CONNECTIVITY_ODATABASEMETADATABASE_HXX_

#include <com/sun/star/sdbc/XDatabaseMetaData2.hpp>
#include <cppuhelper/implbase2.hxx>
#include <comphelper/broadcasthelper.hxx>
#include <com/sun/star/lang/XEventListener.hpp>
#include "FDatabaseMetaDataResultSet.hxx"
#include <functional>

namespace connectivity
{
        typedef ::com::sun::star::uno::Sequence< ::com::sun::star::uno::Any >  TConditions;
        class ODatabaseMetaDataBase :   public  comphelper::OBaseMutex,
                                        public ::cppu::WeakImplHelper2< ::com::sun::star::sdbc::XDatabaseMetaData2,
                                                                        ::com::sun::star::lang::XEventListener>
        {
        private:
            ::com::sun::star::uno::Sequence< ::com::sun::star::beans::PropertyValue >   m_aConnectionInfo;
            ::connectivity::ODatabaseMetaDataResultSet::ORows                           m_aTypeInfoRows;

            // cached database information
            ::std::pair<bool,sal_Bool>          m_isCatalogAtStart;
            ::std::pair<bool,::rtl::OUString>   m_sCatalogSeparator;
            ::std::pair<bool,::rtl::OUString>   m_sIdentifierQuoteString;
            ::std::pair<bool,sal_Bool>          m_supportsCatalogsInTableDefinitions;
            ::std::pair<bool,sal_Bool>          m_supportsSchemasInTableDefinitions;
            ::std::pair<bool,sal_Bool>          m_supportsCatalogsInDataManipulation;
            ::std::pair<bool,sal_Bool>          m_supportsSchemasInDataManipulation;
            ::std::pair<bool,sal_Bool>          m_supportsMixedCaseQuotedIdentifiers;
            ::std::pair<bool,sal_Bool>          m_supportsAlterTableWithAddColumn;
            ::std::pair<bool,sal_Bool>          m_supportsAlterTableWithDropColumn;
            ::std::pair<bool,sal_Int32>         m_MaxStatements;
            ::std::pair<bool,sal_Int32>         m_MaxTablesInSelect;
            ::std::pair<bool,sal_Bool>          m_storesMixedCaseQuotedIdentifiers;

            template <typename T> T callImplMethod(::std::pair<bool,T>& _rCache,const ::std::mem_fun_t<T,ODatabaseMetaDataBase>& _pImplMethod)
            {
                ::osl::MutexGuard aGuard( m_aMutex );
                if ( !_rCache.first )
                {
                    _rCache.second = _pImplMethod(this);
                    _rCache.first = true;
                }
                return _rCache.second;
            }
        protected:
            ::com::sun::star::uno::Reference< ::com::sun::star::sdbc::XConnection >     m_xConnection;
            ::com::sun::star::uno::Reference< ::com::sun::star::lang::XEventListener>   m_xListenerHelper; // forward the calls from the connection to me

            virtual ~ODatabaseMetaDataBase();

        protected:
            virtual ::com::sun::star::uno::Reference< ::com::sun::star::sdbc::XResultSet > impl_getTypeInfo_throw() = 0;
            // cached database information
            virtual ::rtl::OUString impl_getIdentifierQuoteString_throw(  )             = 0;
            virtual sal_Bool        impl_isCatalogAtStart_throw(  )                     = 0;
            virtual ::rtl::OUString impl_getCatalogSeparator_throw(  )                  = 0;
            virtual sal_Bool        impl_supportsCatalogsInTableDefinitions_throw(  )   = 0;
            virtual sal_Bool        impl_supportsSchemasInTableDefinitions_throw(  )    = 0;
            virtual sal_Bool        impl_supportsCatalogsInDataManipulation_throw(  )   = 0;
            virtual sal_Bool        impl_supportsSchemasInDataManipulation_throw(  )    = 0;
            virtual sal_Bool        impl_supportsMixedCaseQuotedIdentifiers_throw(  )   = 0;
            virtual sal_Bool        impl_supportsAlterTableWithAddColumn_throw(  )      = 0;
            virtual sal_Bool        impl_supportsAlterTableWithDropColumn_throw(  )     = 0;
            virtual sal_Int32       impl_getMaxStatements_throw(  )                     = 0;
            virtual sal_Int32       impl_getMaxTablesInSelect_throw(  )                 = 0;
            virtual sal_Bool        impl_storesMixedCaseQuotedIdentifiers_throw(  )     = 0;

        public:

            ODatabaseMetaDataBase(const ::com::sun::star::uno::Reference< ::com::sun::star::sdbc::XConnection >& _rxConnection,const ::com::sun::star::uno::Sequence< ::com::sun::star::beans::PropertyValue >& _rInfo);

            // XDatabaseMetaData2
            virtual ::com::sun::star::uno::Sequence< ::com::sun::star::beans::PropertyValue > SAL_CALL getConnectionInfo(  ) throw (::com::sun::star::uno::RuntimeException);

            // XEventListener
            virtual void SAL_CALL disposing( const ::com::sun::star::lang::EventObject& Source ) throw(::com::sun::star::uno::RuntimeException);

            virtual ::com::sun::star::uno::Reference< ::com::sun::star::sdbc::XResultSet > SAL_CALL getTypeInfo(  ) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException);
            virtual ::com::sun::star::uno::Reference< ::com::sun::star::sdbc::XResultSet > SAL_CALL getProcedures( const ::com::sun::star::uno::Any& catalog, const ::rtl::OUString& schemaPattern, const ::rtl::OUString& procedureNamePattern ) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException);
            virtual ::com::sun::star::uno::Reference< ::com::sun::star::sdbc::XResultSet > SAL_CALL getProcedureColumns( const ::com::sun::star::uno::Any& catalog, const ::rtl::OUString& schemaPattern, const ::rtl::OUString& procedureNamePattern, const ::rtl::OUString& columnNamePattern ) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException);
            virtual ::com::sun::star::uno::Reference< ::com::sun::star::sdbc::XResultSet > SAL_CALL getSchemas(  ) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException);
            virtual ::com::sun::star::uno::Reference< ::com::sun::star::sdbc::XResultSet > SAL_CALL getCatalogs(  ) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException);
            virtual ::com::sun::star::uno::Reference< ::com::sun::star::sdbc::XResultSet > SAL_CALL getColumnPrivileges( const ::com::sun::star::uno::Any& catalog, const ::rtl::OUString& schema, const ::rtl::OUString& table, const ::rtl::OUString& columnNamePattern ) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException);
            virtual ::com::sun::star::uno::Reference< ::com::sun::star::sdbc::XResultSet > SAL_CALL getTablePrivileges( const ::com::sun::star::uno::Any& catalog, const ::rtl::OUString& schemaPattern, const ::rtl::OUString& tableNamePattern ) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException);
            virtual ::com::sun::star::uno::Reference< ::com::sun::star::sdbc::XResultSet > SAL_CALL getBestRowIdentifier( const ::com::sun::star::uno::Any& catalog, const ::rtl::OUString& schema, const ::rtl::OUString& table, sal_Int32 scope, sal_Bool nullable ) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException);
            virtual ::com::sun::star::uno::Reference< ::com::sun::star::sdbc::XResultSet > SAL_CALL getVersionColumns( const ::com::sun::star::uno::Any& catalog, const ::rtl::OUString& schema, const ::rtl::OUString& table ) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException);
            virtual ::com::sun::star::uno::Reference< ::com::sun::star::sdbc::XResultSet > SAL_CALL getPrimaryKeys( const ::com::sun::star::uno::Any& catalog, const ::rtl::OUString& schema, const ::rtl::OUString& table ) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException);
            virtual ::com::sun::star::uno::Reference< ::com::sun::star::sdbc::XResultSet > SAL_CALL getImportedKeys( const ::com::sun::star::uno::Any& catalog, const ::rtl::OUString& schema, const ::rtl::OUString& table ) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException);
            virtual ::com::sun::star::uno::Reference< ::com::sun::star::sdbc::XResultSet > SAL_CALL getExportedKeys( const ::com::sun::star::uno::Any& catalog, const ::rtl::OUString& schema, const ::rtl::OUString& table ) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException);
            virtual ::com::sun::star::uno::Reference< ::com::sun::star::sdbc::XResultSet > SAL_CALL getCrossReference( const ::com::sun::star::uno::Any& primaryCatalog, const ::rtl::OUString& primarySchema, const ::rtl::OUString& primaryTable, const ::com::sun::star::uno::Any& foreignCatalog, const ::rtl::OUString& foreignSchema, const ::rtl::OUString& foreignTable ) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException);
            virtual ::com::sun::star::uno::Reference< ::com::sun::star::sdbc::XResultSet > SAL_CALL getIndexInfo( const ::com::sun::star::uno::Any& catalog, const ::rtl::OUString& schema, const ::rtl::OUString& table, sal_Bool unique, sal_Bool approximate ) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException);

            virtual ::com::sun::star::uno::Reference< ::com::sun::star::sdbc::XConnection > SAL_CALL getConnection(  ) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException);
            // cached database information
            virtual ::rtl::OUString SAL_CALL getIdentifierQuoteString(  ) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException);
            virtual sal_Bool SAL_CALL isCatalogAtStart(  ) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException);
            virtual ::rtl::OUString SAL_CALL getCatalogSeparator(  ) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException);
            virtual sal_Bool SAL_CALL supportsCatalogsInTableDefinitions(  ) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException);
            virtual sal_Bool SAL_CALL supportsSchemasInTableDefinitions(  ) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException);
            virtual sal_Bool SAL_CALL supportsCatalogsInDataManipulation(  ) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException);
            virtual sal_Bool SAL_CALL supportsSchemasInDataManipulation(  ) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException);
            virtual sal_Bool SAL_CALL supportsMixedCaseQuotedIdentifiers(  ) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException);
            virtual sal_Bool SAL_CALL supportsAlterTableWithAddColumn(  ) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException);
            virtual sal_Bool SAL_CALL supportsAlterTableWithDropColumn(  ) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException);
            virtual sal_Int32 SAL_CALL getMaxStatements(  ) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException);
            virtual sal_Int32 SAL_CALL getMaxTablesInSelect(  ) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException);
            virtual sal_Bool SAL_CALL storesMixedCaseQuotedIdentifiers(  ) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException);
        };
}
#endif // _CONNECTIVITY_ODATABASEMETADATABASE_HXX_
<|endoftext|>


<commit_before>#include "types.h"
#include "user.h"
#include "fcntl.h"
#include "wq.hh"

class thing {
protected:
  int done;
public:
  static void * operator new(unsigned long n){
    return malloc(n);
  }
  static void operator delete(void *p){
    free(p);
  }
  thing() { done = 0; }
  virtual ~thing();
  virtual void print() = 0;
  virtual void run() = 0;
  int checkdone() { return done; }
};

class cmd : public thing {
private:
  int argc;
  char *argv[20];
public:
  cmd() { argc = 0; }

  void print();
  void run();
  static cmd *parse();
};

class sequence : public thing {
private:
  int n;
  class cmd *a[20];
public:
  sequence() { n = 0; }

  void print();
  void run();
  static sequence *parse();
};

thing::~thing()
{
}

int
isspace(char c)
{
  return c == ' ' || c == '\t' || c == '\n' || c == '\r';
}

cmd *
cmd::parse()
{
  char buf[512];
  gets(buf, sizeof(buf));
  if(buf[0] == 0)
    return 0;

  cmd *c = new cmd();
  for(int i = 0; buf[i]; ){
    int j;
    for(j = i; buf[j] && !isspace(buf[j]); j++)
      ;

    char *p = (char *) malloc(j - i + 1);
    assert(p);
    memmove(p, buf + i, j - i);
    p[j - i] = '\0';
    assert(c->argc < 20);
    c->argv[c->argc++] = p;

    while(isspace(buf[j]))
      j++;
    i = j;
  }
  return c;
}

void
cmd::run()
{
  int pid = fork(0);
  if(pid < 0){
    printf("fork failed\n");
    exit();
  }
  if(pid == 0){
    argv[argc] = 0;
    exec(argv[0], (const char **) argv);
    printf("exec failed\n");
    exit();
  } else {
    wait();
    done = 1;
  }
}

void
cmd::print()
{
  for(int i = 0; i < argc; i++)
    printf("%s ", argv[i]);
  printf("\n");
}

sequence *
sequence::parse()
{
  sequence *s = new sequence();

  while(cmd *c = cmd::parse()){
    assert(s->n < 20);
    s->a[s->n++] = c;
  }

  return s;
}

void
blah(void *x)
{
  thing *t = (thing *) x;
  t->run();
}

void
sequence::run()
{
  for(int i = 0; i < n; i++){
    cwork *w = new cwork();
    w->rip = (void*) blah;
    w->arg0 = a[i];
    wq_push(w);
  }
  while(1){
    int do_more = 0;
    for(int i = 0; i < n; i++){
      if(a[i]->checkdone() == 0){
        do_more += 1;
      }
    }
    if(do_more == 0)
      break;
    wq_trywork();
  }
  done = 1;
}

void
sequence::print()
{
  for(int i = 0; i < n; i++)
    a[i]->print();
}

int
main(void)
{
  initwq();
  sequence *s = sequence::parse();
  if(s){
    s->run();
  }
}
<commit_msg>dependency-aware shell<commit_after>//
// A simple shell that uses a dependency-aware layer on
// top of wq to schedule commands.
//
// If you give this script to wqsh:
//   cp README x
//   cp x y
//   cp README z
// It will ask wq to run the two "cp README ..." commands in parallel,
// but will block the "cp x y" until the first cp has completed.
//

#include "types.h"
#include "user.h"
#include "fcntl.h"
#include "wq.hh"

//
// Adapt wq to understand simple dependencies
//
class dwork;
class dwq {
private:
  static const int max = 100;

  // keep track of sequence of push()ed dworks.
  // so we know which are done, and thus what
  // dependencies are or are not satisfied.
  int n;
  dwork *da[max];

  // is it OK to run da[i]?
  int can_run(int i);

public:
  static void * operator new(unsigned long n){
    return malloc(n);
  }
  dwq() { n = 0; }
  int done();
  void push(dwork *);
  void run();
};

class dwork {
private:
  friend class dwq;
  cwork *w;
  int started;
  int done;
  static const int max = 10;
  int nneeds, nsatisfies;
  int _needs[max];
  int _satisfies[max];
  static void gogo(void *a0, void *a1, void *a2);
public:

  static void * operator new(unsigned long n){
    return malloc(n);
  }
  dwork(void *fn, void *arg);
  void needs(int); // must wait for this dependency, for input
  void satisfies(int); // output satisfies this dependency
};

void
dwq::push(dwork *dw)
{
  assert(n+1 < max);
  da[n++] = dw;
}

int
dwq::done()
{
  int ndone = 0;
  for(int i = 0; i < n; i++)
    if(da[i]->done)
      ndone++;
  return ndone >= n;
}

int
dwq::can_run(int di)
{
  dwork *w = da[di];
  int ready[dwork::max];

  // by default, all symbolic resources are ready.
  for(int i = 0; i < w->nneeds; i++)
    ready[i] = 1;

  // for each input w needs, figure out if the most
  // recent provider is done.
  for(int i = 0; i < di; i++){
    for(int j = 0; j < w->nneeds; j++){
      for(int k = 0; k < da[i]->nsatisfies; k++){
        if(w->_needs[j] == da[i]->_satisfies[k]){
          ready[j] = da[i]->done;
        }
      }
    }
  }

  // are all inputs ready?
  for(int i = 0; i < w->nneeds; i++){
    if(ready[i] == 0){
      printf("can_run(%d) 0\n", di);
      return 0;
    }
  }

  printf("can_run(%d) 1\n", di);
  return 1;
}

// find dworks w/ satisfied inputs, run them, see
// if they un-block further dworks, &c.
void
dwq::run()
{
  while(done() == 0){
    for(int i = 0; i < n; i++){
      if(da[i]->done == 0 && da[i]->started == 0 &&
         can_run(i)){
        da[i]->started = 1;
        wq_push(da[i]->w);
      }
    }
    wq_trywork();
  }
}

void
dwork::gogo(void *a0, void *a1, void *a2)
{
  dwork *w = (dwork *) a0;
  auto fn = (void (*)(void *)) a1;
  fn(a2);
  w->done = 1;
}

dwork::dwork(void *fn, void *arg)
{
  w = new cwork();
  w->rip = (void *) dwork::gogo;
  w->arg0 = this;
  w->arg1 = fn;
  w->arg2 = arg;
  started = 0;
  done = 0;
  nneeds = 0;
  nsatisfies = 0;
}

// this dwork must wait for some previously pushed
// dwork to generate output with symbolic name x.
void
dwork::needs(int x)
{
  assert(nneeds < max);
  _needs[nneeds++] = x;
}

// this dwork generates output with symbolic name x,
// so any dwork needing (waiting for) x can start.
void
dwork::satisfies(int x)
{
  assert(nsatisfies < max);
  _satisfies[nsatisfies++] = x;
}

//
// parse shell scripts
//
class thing {
protected:
  int done;
public:
  static void * operator new(unsigned long n){
    return malloc(n);
  }
  static void operator delete(void *p){
    free(p);
  }
  thing() { done = 0; }
  virtual ~thing();
  virtual void print() = 0;
  virtual void run(dwq *) = 0;
  int checkdone() { return done; }
};

class cmd : public thing {
private:
  int argc;
  char *argv[20];
public:
  cmd() { argc = 0; }

  void print();
  void run(dwq *);
  void reallyrun();
  static cmd *parse();
};

class sequence : public thing {
private:
  int n;
  class cmd *a[20];
public:
  sequence() { n = 0; }

  void print();
  void run(dwq *);
  static sequence *parse();
};

thing::~thing()
{
}

int
isspace(char c)
{
  return c == ' ' || c == '\t' || c == '\n' || c == '\r';
}

cmd *
cmd::parse()
{
  char buf[512];
  gets(buf, sizeof(buf));
  if(buf[0] == 0)
    return 0;

  cmd *c = new cmd();
  for(int i = 0; buf[i]; ){
    int j;
    for(j = i; buf[j] && !isspace(buf[j]); j++)
      ;

    char *p = (char *) malloc(j - i + 1);
    assert(p);
    memmove(p, buf + i, j - i);
    p[j - i] = '\0';
    assert(c->argc < 20);
    c->argv[c->argc++] = p;

    while(isspace(buf[j]))
      j++;
    i = j;
  }
  return c;
}

void
blah(void *x)
{
  cmd *c = (cmd *) x;
  c->reallyrun();
}

void
cmd::reallyrun()
{
  int pid = fork(0);
  if(pid < 0){
    printf("fork failed\n");
    exit();
  }
  if(pid == 0){
    argv[argc] = 0;
    exec(argv[0], (const char **) argv);
    printf("exec failed\n");
    exit();
  } else {
    wait();
    done = 1;
  }
}

void
cmd::run(dwq *d)
{
  dwork *w = new dwork((void *) blah, this);
  if(argc == 3 && strcmp(argv[0], "cp") == 0){
    // this isn't correct; it's pessimistic in that
    // distinct files can be mapped to the same "need" key,
    // and that if you use different names for the same
    // file, we won't realize they are the same.
    w->needs(argv[1][0]);
    w->satisfies(argv[2][0]);
  } else {
    printf("warning: don't understand %s dependencies\n", argv[0]);
  }
  d->push(w);
}

void
cmd::print()
{
  for(int i = 0; i < argc; i++)
    printf("%s ", argv[i]);
  printf("\n");
}

sequence *
sequence::parse()
{
  sequence *s = new sequence();

  while(cmd *c = cmd::parse()){
    assert(s->n < 20);
    s->a[s->n++] = c;
  }

  return s;
}

void
sequence::run(dwq *d)
{
  for(int i = 0; i < n; i++){
    a[i]->run(d);
  }
  done = 1;
}

void
sequence::print()
{
  for(int i = 0; i < n; i++)
    a[i]->print();
}

int
main(void)
{
  initwq();
  dwq *d= new dwq();
  sequence *s = sequence::parse();
  if(s){
    s->run(d);
    d->run();
  }
}
<|endoftext|>


<commit_before><commit_msg>Some little modif<commit_after><|endoftext|>


<commit_before>//==--- Utility/Portability.hpp ---------------------------- -*- C++ -*- ---==//
//
//                                Voxel : Utility
//
//                        Copyright (c) 2017 Rob Clucas
//
//  This file is distributed under the MIT License. See LICENSE for details.
//
//==------------------------------------------------------------------------==//
//
/// \file  Portability.hpp
/// \brief This file defines macros to allow correct compilation for host and
///        device code.
//
//==------------------------------------------------------------------------==//

#ifndef VOXEL_UTILITY_PORTABILITY_HPP
#define VOXEL_UTILTIY_PORTABILITY_HPP

#if defined(__CUDA_ARCH__)

// Cuda device code compilation:
#define CUDA_DEVICE_COMPILE

#if defined(__clang__) && !defined(__CUDA__)

/// Definition for when clang is compiling CUDA code in host mode.
# define CLANG_CUDA_HOST_COMPILE

#elif defined(__clang__) && defined(__CUDA__)

/// Definition for when clang is compiling CUDA code in device mode.
# define CLANG_CUDA_DEVICE_COMPILE

#endif // clang and cuda
#endif // cuda_arch

#include <cuda.h>
#include <cuda_runtime.h>

/// Definition for host, device, and host device functions.
#if defined(__CUDACC__) || defined(__clang__)  // GPU Environment, or clang:
# define VoxxHost       __host__
# define VoxxDevice     __device__
# define VoxxDeviceHost __device__ __host__
#else                                          // Non-GPU Environment:
# define VoxxHost
# define VoxxDevice
# define VoxxDeviceHost
#endif

#endif // VOXEL_UTILITY_PORTABILITY_HPP<commit_msg>Fixed macro error in Portability header<commit_after>//==--- Utility/Portability.hpp ---------------------------- -*- C++ -*- ---==//
//
//                                Voxel : Utility
//
//                        Copyright (c) 2017 Rob Clucas
//
//  This file is distributed under the MIT License. See LICENSE for details.
//
//==------------------------------------------------------------------------==//
//
/// \file  Portability.hpp
/// \brief This file defines macros to allow correct compilation for host and
///        device code.
//
//==------------------------------------------------------------------------==//

#ifndef VOXEL_UTILITY_PORTABILITY_HPP
#define VOXEL_UTILITY_PORTABILITY_HPP

#if defined(__CUDA_ARCH__)

// Cuda device code compilation:
#define CUDA_DEVICE_COMPILE

#if defined(__clang__) && !defined(__CUDA__)

/// Definition for when clang is compiling CUDA code in host mode.
# define CLANG_CUDA_HOST_COMPILE

#elif defined(__clang__) && defined(__CUDA__)

/// Definition for when clang is compiling CUDA code in device mode.
# define CLANG_CUDA_DEVICE_COMPILE

#endif // clang and cuda
#endif // cuda_arch

#include <cuda.h>
#include <cuda_runtime.h>

/// Definition for host, device, and host device functions.
#if defined(__CUDACC__) || defined(__clang__)  // GPU Environment, or clang:
# define VoxxHost       __host__
# define VoxxDevice     __device__
# define VoxxDeviceHost __device__ __host__
#else                                          // Non-GPU Environment:
# define VoxxHost
# define VoxxDevice
# define VoxxDeviceHost
#endif

#endif // VOXEL_UTILITY_PORTABILITY_HPP<|endoftext|>


<commit_before>//
// LibSourcey
// Copyright (C) 2005, Sourcey <http://sourcey.com>
//
// LibSourcey is free software; you can redistribute it and/or
// modify it under the terms of the GNU Lesser General Public
// License as published by the Free Software Foundation; either
// version 2.1 of the License, or (at your option) any later version.
//
// LibSourcey is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <http://www.gnu.org/licenses/>.
//

#include "scy/filesystem.h"
#include "scy/logger.h"
#include "scy/util.h"
#include "scy/uv/uvpp.h"
#include <sstream>
#include <fstream>
#include <memory>
#include <algorithm>
#if defined(WIN32) && defined(SCY_UNICODE)
#include <locale>
#include <codecvt>
#endif

namespace scy {
namespace fs {

static const char* separatorWin = "\\";
static const char* separatorUnix = "/";
#ifdef WIN32
    const char delimiter = '\\';
    const char* separator = separatorWin;
    static const char* sepPattern = "/\\";
#else
    const char delimiter = '/';
    const char* separator = separatorUnix;
    static const char* sepPattern = "/";
#endif

std::string filename(const std::string& path)
{
    std::size_t dirp = path.find_last_of(fs::sepPattern);
    if (dirp == std::string::npos) return path;
    return path.substr(dirp + 1);
}

std::string dirname(const std::string& path)
{
    std::size_t dirp = path.find_last_of(fs::sepPattern);
    if (dirp == std::string::npos) return "";
    if (path.find(".", dirp) == std::string::npos) return path;
    return path.substr(0, dirp);
}

std::string basename(const std::string& path)
{
    std::size_t dotp = path.find_last_of(".");
    if (dotp == std::string::npos)
        return path;

    std::size_t dirp = path.find_last_of(fs::sepPattern);
    if (dirp != std::string::npos && dotp < dirp)
        return path;

    return path.substr(0, dotp);
}

std::string extname(const std::string& path, bool includeDot)
{
    std::size_t dotp = path.find_last_of(".");
    if (dotp == std::string::npos)
        return "";

    // Ensure the dot was not part of the pathname
    std::size_t dirp = path.find_last_of(fs::sepPattern);
    if (dirp != std::string::npos && dotp < dirp)
        return "";

    return path.substr((dotp + includeDot) ? 0 : 1);
}

bool exists(const std::string& path)
{
    // Normalize is needed to ensure no
    // trailing slash for directories or
    // stat fails to recognize validity.
    // TODO: Do we need transcode here?
#ifdef WIN32
    struct _stat s;
    return _stat(fs::normalize(path).c_str(), &s) != -1;
#else
    struct stat s;
    return stat(fs::normalize(path).c_str(), &s) != -1;
#endif
}

bool isdir(const std::string& path)
{
    // TODO: Do we need transcode here?
#ifdef WIN32
    struct _stat s;
    _stat(fs::normalize(path).c_str(), &s);
#else
    struct stat s;
    stat(fs::normalize(path).c_str(), &s);
#endif
    // S_IFDIR: directory file.
    // S_IFCHR: character-oriented device file
    // S_IFBLK: block-oriented device file
    // S_IFREG: regular file
    // S_IFLNK: symbolic link
    // S_IFSOCK: socket
    // S_IFIFO: FIFO or pipe
    return (s.st_mode & S_IFDIR) != 0;
}

std::int64_t filesize(const std::string& path)
{
#ifdef WIN32
    struct _stat s;
    if (_stat(path.c_str(), &s) == 0)
#else
    struct stat s;
    if (stat(path.c_str(), &s) == 0)
#endif
        return s.st_size;
    return -1;
}

namespace internal {

    struct FSReq
    {
        FSReq() {}
        ~FSReq() { uv_fs_req_cleanup(&req); }
        FSReq(const FSReq& req);
        FSReq& operator=(const FSReq& req);
        uv_fs_t req;
    };

#define FSapi(func, ...)                                        \
    FSReq wrap;                                                    \
    int err = uv_fs_ ## func(uv_default_loop(),                    \
        &wrap.req, __VA_ARGS__, nullptr);                        \
    if (err < 0)                                                 \
        uv::throwError(std::string("Filesystem error: ") +        \
            #func + std::string(" failed"), err);                \

} // namespace internal

void readdir(const std::string& path, std::vector<std::string>& res)
{
    internal::FSapi(scandir, path.c_str(), 0)

    char *namebuf = static_cast<char*>(wrap.req.ptr);
    int nnames = wrap.req.result;
    for (int i = 0; i < nnames; i++)
    {
        std::string name(namebuf);
        res.push_back(name);
#ifdef _DEBUG
        namebuf += name.length();
        assert(*namebuf == '\0');
        namebuf += 1;
#else
        namebuf += name.length() + 1;
#endif
    }
}

void mkdir(const std::string& path, int mode)
{
    internal::FSapi(mkdir, path.c_str(), mode)
}

void mkdirr(const std::string& path, int mode)
{
    std::string current;
    std::string level;
    std::istringstream istr(fs::normalize(path));

    while (std::getline(istr, level, fs::delimiter))
    {
        if (level.empty()) continue;
        current += level;

#ifdef WIN32
        if (level.at(level.length() - 1) == ':') {
            current += fs::separator;
            continue; // skip drive letter
        }
#endif
        // create current level
        if (!fs::exists(current))
            fs::mkdir(current.c_str(), mode); // create or throw

        current += fs::separator;
    }
}

void rmdir(const std::string& path)
{
    internal::FSapi(rmdir, path.c_str())
}

void unlink(const std::string& path)
{
    internal::FSapi(unlink, path.c_str())
}

void rename(const std::string& path, const std::string& target)
{
    internal::FSapi(rename, path.c_str(), target.c_str())
}

void trimslash(std::string& path)
{
    std::size_t dirp = path.find_last_of(sepPattern);
    if (dirp == path.length() - 1)
        path.resize(dirp);
}

std::string normalize(const std::string& path)
{
    std::string s(util::replace(path,
#ifdef WIN32
        separatorUnix, separatorWin
#else
        separatorWin, separatorUnix
#endif
    ));

    // Trim the trailing slash for stat compatability
    trimslash(s);
    return s;
}

std::string transcode(const std::string& path)
{
#if defined(_MSC_VER) && defined(SCY_UNICODE)
    std::wstring_convert<std::codecvt<char16_t,char,std::mbstate_t>,char16_t> convert;
    std::u16string u16s = convert.from_bytes(path);
    std::wstring uniPath(u16s.begin(), u16s.end()); // copy data across, w_char is 16 bit on windows so this should be OK
    DWORD len = WideCharToMultiByte(CP_ACP, WC_NO_BEST_FIT_CHARS, uniPath.c_str(), static_cast<int>(uniPath.length()), nullptr, 0, nullptr, nullptr);
    if (len > 0) {
        std::unique_ptr<char[]> buffer(new char[len]);
        DWORD rc = WideCharToMultiByte(CP_ACP, WC_NO_BEST_FIT_CHARS, uniPath.c_str(), static_cast<int>(uniPath.length()), buffer.get(), static_cast<int>(len), nullptr, nullptr);
        if (rc) {
            return std::string(buffer.get(), len);
        }
    }
#endif
    return path;
}

void addsep(std::string& path)
{
    if (!path.empty() && path.at(path.length() - 1) != fs::separator[0])
        path.append(fs::separator, 1);
}

void addnode(std::string& path, const std::string& node)
{
    fs::addsep(path);
    path += node;
}

bool savefile(const std::string& path, const char* data, std::size_t size, bool whiny)
{
    std::ofstream ofs(path, std::ios_base::binary | std::ios_base::out);
    if (ofs.is_open())
        ofs.write(data, size);
    else {
        if (whiny)
            throw std::runtime_error("Cannot save file: " + path);
        return false;
    }
    return true;
}

} } // namespace scy::fs
<commit_msg>Improve compiler definitions<commit_after>//
// LibSourcey
// Copyright (C) 2005, Sourcey <http://sourcey.com>
//
// LibSourcey is free software; you can redistribute it and/or
// modify it under the terms of the GNU Lesser General Public
// License as published by the Free Software Foundation; either
// version 2.1 of the License, or (at your option) any later version.
//
// LibSourcey is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <http://www.gnu.org/licenses/>.
//

#include "scy/filesystem.h"
#include "scy/logger.h"
#include "scy/util.h"
#include "scy/uv/uvpp.h"
#include <sstream>
#include <fstream>
#include <memory>
#include <algorithm>
#if defined(_MSC_VER) && defined(SCY_UNICODE)
#include <locale>
#include <codecvt>
#endif

namespace scy {
namespace fs {

static const char* separatorWin = "\\";
static const char* separatorUnix = "/";
#ifdef WIN32
    const char delimiter = '\\';
    const char* separator = separatorWin;
    static const char* sepPattern = "/\\";
#else
    const char delimiter = '/';
    const char* separator = separatorUnix;
    static const char* sepPattern = "/";
#endif

std::string filename(const std::string& path)
{
    std::size_t dirp = path.find_last_of(fs::sepPattern);
    if (dirp == std::string::npos) return path;
    return path.substr(dirp + 1);
}

std::string dirname(const std::string& path)
{
    std::size_t dirp = path.find_last_of(fs::sepPattern);
    if (dirp == std::string::npos) return "";
    if (path.find(".", dirp) == std::string::npos) return path;
    return path.substr(0, dirp);
}

std::string basename(const std::string& path)
{
    std::size_t dotp = path.find_last_of(".");
    if (dotp == std::string::npos)
        return path;

    std::size_t dirp = path.find_last_of(fs::sepPattern);
    if (dirp != std::string::npos && dotp < dirp)
        return path;

    return path.substr(0, dotp);
}

std::string extname(const std::string& path, bool includeDot)
{
    std::size_t dotp = path.find_last_of(".");
    if (dotp == std::string::npos)
        return "";

    // Ensure the dot was not part of the pathname
    std::size_t dirp = path.find_last_of(fs::sepPattern);
    if (dirp != std::string::npos && dotp < dirp)
        return "";

    return path.substr((dotp + includeDot) ? 0 : 1);
}

bool exists(const std::string& path)
{
    // Normalize is needed to ensure no
    // trailing slash for directories or
    // stat fails to recognize validity.
    // TODO: Do we need transcode here?
#ifdef WIN32
    struct _stat s;
    return _stat(fs::normalize(path).c_str(), &s) != -1;
#else
    struct stat s;
    return stat(fs::normalize(path).c_str(), &s) != -1;
#endif
}

bool isdir(const std::string& path)
{
    // TODO: Do we need transcode here?
#ifdef WIN32
    struct _stat s;
    _stat(fs::normalize(path).c_str(), &s);
#else
    struct stat s;
    stat(fs::normalize(path).c_str(), &s);
#endif
    // S_IFDIR: directory file.
    // S_IFCHR: character-oriented device file
    // S_IFBLK: block-oriented device file
    // S_IFREG: regular file
    // S_IFLNK: symbolic link
    // S_IFSOCK: socket
    // S_IFIFO: FIFO or pipe
    return (s.st_mode & S_IFDIR) != 0;
}

std::int64_t filesize(const std::string& path)
{
#ifdef WIN32
    struct _stat s;
    if (_stat(path.c_str(), &s) == 0)
#else
    struct stat s;
    if (stat(path.c_str(), &s) == 0)
#endif
        return s.st_size;
    return -1;
}

namespace internal {

    struct FSReq
    {
        FSReq() {}
        ~FSReq() { uv_fs_req_cleanup(&req); }
        FSReq(const FSReq& req);
        FSReq& operator=(const FSReq& req);
        uv_fs_t req;
    };

#define FSapi(func, ...)                                        \
    FSReq wrap;                                                    \
    int err = uv_fs_ ## func(uv_default_loop(),                    \
        &wrap.req, __VA_ARGS__, nullptr);                        \
    if (err < 0)                                                 \
        uv::throwError(std::string("Filesystem error: ") +        \
            #func + std::string(" failed"), err);                \

} // namespace internal

void readdir(const std::string& path, std::vector<std::string>& res)
{
    internal::FSapi(scandir, path.c_str(), 0)

    char *namebuf = static_cast<char*>(wrap.req.ptr);
    int nnames = wrap.req.result;
    for (int i = 0; i < nnames; i++)
    {
        std::string name(namebuf);
        res.push_back(name);
#ifdef _DEBUG
        namebuf += name.length();
        assert(*namebuf == '\0');
        namebuf += 1;
#else
        namebuf += name.length() + 1;
#endif
    }
}

void mkdir(const std::string& path, int mode)
{
    internal::FSapi(mkdir, path.c_str(), mode)
}

void mkdirr(const std::string& path, int mode)
{
    std::string current;
    std::string level;
    std::istringstream istr(fs::normalize(path));

    while (std::getline(istr, level, fs::delimiter))
    {
        if (level.empty()) continue;
        current += level;

#ifdef WIN32
        if (level.at(level.length() - 1) == ':') {
            current += fs::separator;
            continue; // skip drive letter
        }
#endif
        // create current level
        if (!fs::exists(current))
            fs::mkdir(current.c_str(), mode); // create or throw

        current += fs::separator;
    }
}

void rmdir(const std::string& path)
{
    internal::FSapi(rmdir, path.c_str())
}

void unlink(const std::string& path)
{
    internal::FSapi(unlink, path.c_str())
}

void rename(const std::string& path, const std::string& target)
{
    internal::FSapi(rename, path.c_str(), target.c_str())
}

void trimslash(std::string& path)
{
    std::size_t dirp = path.find_last_of(sepPattern);
    if (dirp == path.length() - 1)
        path.resize(dirp);
}

std::string normalize(const std::string& path)
{
    std::string s(util::replace(path,
#ifdef WIN32
        separatorUnix, separatorWin
#else
        separatorWin, separatorUnix
#endif
    ));

    // Trim the trailing slash for stat compatability
    trimslash(s);
    return s;
}

std::string transcode(const std::string& path)
{
#if defined(_MSC_VER) && defined(SCY_UNICODE)
    std::wstring_convert<std::codecvt<char16_t,char,std::mbstate_t>,char16_t> convert;
    std::u16string u16s = convert.from_bytes(path);
    std::wstring uniPath(u16s.begin(), u16s.end()); // copy data across, w_char is 16 bit on windows so this should be OK
    DWORD len = WideCharToMultiByte(CP_ACP, WC_NO_BEST_FIT_CHARS, uniPath.c_str(), static_cast<int>(uniPath.length()), nullptr, 0, nullptr, nullptr);
    if (len > 0) {
        std::unique_ptr<char[]> buffer(new char[len]);
        DWORD rc = WideCharToMultiByte(CP_ACP, WC_NO_BEST_FIT_CHARS, uniPath.c_str(), static_cast<int>(uniPath.length()), buffer.get(), static_cast<int>(len), nullptr, nullptr);
        if (rc) {
            return std::string(buffer.get(), len);
        }
    }
#endif
    return path;
}

void addsep(std::string& path)
{
    if (!path.empty() && path.at(path.length() - 1) != fs::separator[0])
        path.append(fs::separator, 1);
}

void addnode(std::string& path, const std::string& node)
{
    fs::addsep(path);
    path += node;
}

bool savefile(const std::string& path, const char* data, std::size_t size, bool whiny)
{
    std::ofstream ofs(path, std::ios_base::binary | std::ios_base::out);
    if (ofs.is_open())
        ofs.write(data, size);
    else {
        if (whiny)
            throw std::runtime_error("Cannot save file: " + path);
        return false;
    }
    return true;
}

} } // namespace scy::fs
<|endoftext|>


<commit_before>//-----------------------------------------------------------------------------
#include "server.h"
#include "clientconexion.h"
#include "../socket/socket.h"
#ifndef _WIN32
#include "../socket/posix/posixsocket.h"
#endif // ! _WIN32
#include "../model/game.h"
#include "../remote_client/remote_client.h"

#include <iostream>

void idle_int(int param) {}

using namespace std;
//-----------------------------------------------------------------------------
Server::Server(Game& game) :
	port(8001),
	ip("127.0.0.1"),
	max_clients(4),
	status(false),
	socket(nullptr),
	game(game)
{
}

Server::Server(Configuration* config, Game& game) : game(game) {
	this->port = std::stoi(config->port);
	this->ip = config->ip;
	this->max_clients = config->max_clients;
	this->status = false;
	this->socket = 0;

}
//-----------------------------------------------------------------------------
Server::~Server() {
	stop();
}
//----------------------------------------------------------------------------
bool Server::isActive()
{
	return this->status && !game.willExit();
}
//-----------------------------------------------------------------------------
void Server::start() {
	th = thread(&Server::run, this);
}

void Server::run()
{
	cerr << "Server::run()" << endl;
	while(this->isActive())
	{
		shared_ptr<Socket> socketCLI;

		// Aceptamos nuevo cliente accept es bloqueante
		//cuando se recibe un nuevo cliente, se genera una conexion para atenderlo y se lo carga en el vector
		//de conexiones

		// Fede, en este punto es donde si queres la conexion puede ser un "Cliente... y tener logica"
		//Osea cambiamos esa clase a lo que modela el cliente en el servidor y usa sockets para comunicacion
		socketCLI = this->socket->Accept();

		//Si hubo problemas en el socket salir y loggear
		if(!this->socket->IsActive() || !socketCLI) break;

		// Generamos una nueva conexión para ese cliente
		auto player = game.getAvailablePlayer();
		if (player) {
			game.addClient(make_shared<RemoteClient>(game, *player, socketCLI));
		}
	}

}
//-----------------------------------------------------------------------------
bool Server::init()
{
	this->socket = Socket::create();

	if(this->socket->Listen(this->port,this->max_clients))
	{
		// si se establece el listen el server queda levantado
		this->status = true;
	}

	if (!status) {
		cerr << "Could not open a new socket at " << ip << ":" << port << endl;
		return false;
	}

	this->start();

	return true;
}
//-----------------------------------------------------------------------------
void Server::stop()
{
	//Cambio el estado del server
	if (status) {
		this->status = false;
		auto dummy = Socket::create();
		dummy->Connect("localhost", port); // TODO: check address
		// Detenemos hilo hay q detener la funcion run
		th.join();
		// Cerramos el socket
		this->socket->deinit();
	}
	// TODO: Mensaje de log
}
//-----------------------------------------------------------------------------

<commit_msg>More Code Golf, saco comentarios viejos<commit_after>//-----------------------------------------------------------------------------
#include "server.h"
#include "clientconexion.h"
#include "../socket/socket.h"
#ifndef _WIN32
#include "../socket/posix/posixsocket.h"
#endif // ! _WIN32
#include "../model/game.h"
#include "../remote_client/remote_client.h"

#include <iostream>

void idle_int(int param) {}

using namespace std;
//-----------------------------------------------------------------------------
Server::Server(Game& game) :
	port(8001),
	ip("127.0.0.1"),
	max_clients(4),
	status(false),
	socket(nullptr),
	game(game)
{
}

Server::Server(Configuration* config, Game& game) : game(game) {
	this->port = std::stoi(config->port);
	this->ip = config->ip;
	this->max_clients = config->max_clients;
	this->status = false;
	this->socket = 0;

}
//-----------------------------------------------------------------------------
Server::~Server() {
	stop();
}
//----------------------------------------------------------------------------
bool Server::isActive() {
	return this->status && !game.willExit();
}
//-----------------------------------------------------------------------------
void Server::start() {
	th = thread(&Server::run, this);
}

void Server::run() {
	while(this->isActive()) {
		shared_ptr<Socket> socketCLI;

		// Aceptamos nuevo cliente accept es bloqueante
		//cuando se recibe un nuevo cliente, se genera una conexion para atenderlo y se lo carga en el vector
		//de conexiones

		socketCLI = this->socket->Accept();

		if(socketCLI) {
			// Generamos una nueva conexión para ese cliente
			auto player = game.getAvailablePlayer();
			if (player) {
				game.addClient(make_shared<RemoteClient>(game, *player, socketCLI));
			}
		} else {
			//Si hubo problemas en el socket salir y loggear
			stop();
		}
	}
}
//-----------------------------------------------------------------------------
bool Server::init() {
	this->socket = Socket::create();

	if(this->socket->Listen(this->port,this->max_clients)) {
		// si se establece el listen el server queda levantado
		this->status = true;
	}

	if (!status) {
		cerr << "Could not open a new socket at " << ip << ":" << port << endl;
		return false;
	}

	this->start();

	return true;
}
//-----------------------------------------------------------------------------
void Server::stop() {
	//Cambio el estado del server
	if (status) {
		this->status = false;
		auto dummy = Socket::create();
		dummy->Connect("localhost", port); // TODO: check address
		// Detenemos hilo hay q detener la funcion run
		th.join();
		// Cerramos el socket
		this->socket->deinit();
	}
	// TODO: Mensaje de log
}
//-----------------------------------------------------------------------------

<|endoftext|>


<commit_before>//
// Created by juzeg on 03.12.16.
//

#include "Account.h"
#include <fstream>

void Account::newAccount() {

    std::string filename;
    std::string name;
    std::string password;

    std::cout << "How should i call you?   " << std::endl;
    std::cin >> name;
    filename = name + ".txt";

    std::cout << "file name is   :" << filename << std::endl;

    std::ofstream accountfile;

    accountfile.open(filename.c_str());

    if (accountfile.good()) {
        std::cout << "file created!" << std::endl;

        accountfile << name;
        accountfile << "\n";
        std::cout << "Please insert your passoword" << std::endl;
        std::cin >> password;
        accountfile << password;
    } else std::cout << "file creation fail" << std::endl;

}

std::string Account::login() {
    std::string name;
    std::string readName;
    std::string readPassword;
    std::string password;
    std::string filename;

    std::cout << "Please type in your name " << std::endl;
    std::cin >> name;
    std::cout << "\n Plaease type in your passoword \n ";
    std::cin >> password;

    std::fstream accountfile;

    filename = name + ".txt";
    accountfile.open(filename.c_str(), std::ios::in);

    if (accountfile.good()) {
        getline(accountfile, readName);
        getline(accountfile, readPassword);
        if ((readName == name) && (readPassword == password)) {
            std::cout << "logged succesfu lly!" << std::endl;
            return name;
        }
    } else { std::cout << "no such user on this computer " << std::endl; }
    return "";

}<commit_msg>logging finctionality<commit_after>//
// Created by juzeg on 03.12.16.
//

#include "Account.h"
#include <fstream>

void Account::newAccount() {

    std::string filename;
    std::string name;
    std::string password;

    std::cout << "How should i call you?   " << std::endl;
    std::cin >> name;
    filename = name + ".txt";

    std::cout << "file name is   :" << filename << std::endl;

    std::ofstream accountfile;

    accountfile.open(filename.c_str());

    if (accountfile.good()) {
        std::cout << "file created!" << std::endl;

        accountfile << name;
        accountfile << "\n";
        std::cout << "Please insert your passoword" << std::endl;
        std::cin >> password;
        accountfile << password;
    } else std::cout << "file creation fail" << std::endl;

}

std::string Account::login() {
    std::string name;
    std::string readName;
    std::string readPassword;
    std::string password;
    std::string filename;

    std::cout << "Please type in your name " << std::endl;
    std::cin >> name;
    std::cout << "\n Plaease type in your passoword \n ";
    std::cin >> password;

    std::fstream accountfile;

    filename = name + ".txt";
    accountfile.open(filename.c_str(), std::ios::in);

    if (accountfile.good()) {
        getline(accountfile, readName);
        getline(accountfile, readPassword);
        if ((readName == name) && (readPassword == password)) {
            std::cout << "logged succesfully!" << std::endl;
            return name;
        }
    } else { std::cout << "no such user on this computer " << std::endl; }
    return "";

}<|endoftext|>