~ubuntu-branches/ubuntu/wily/chemeq/wily

« back to all changes in this revision

Viewing changes to src/chemeq.cc

  • Committer: Bazaar Package Importer
  • Author(s): Georges Khaznadar
  • Date: 2006-04-02 16:45:22 UTC
  • Revision ID: james.westby@ubuntu.com-20060402164522-gjv7hcv1hdrzhnc0
Tags: 1.9
recompiled with a new version of flex (see 
http://www.debian.org/security/2006/dsa-1020)

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
#include "chemeq.h"
2
2
#include <math.h>
 
3
#include <sstream>
3
4
 
4
5
atome lesatomes[] ={
5
6
{-1, "e"},
191
192
  return al;
192
193
}
193
194
 
194
 
void AtomeListe::printnorm(std::ostream & o){
 
195
bool operator == (const AtomeListe & a1, const AtomeListe & a2){
 
196
  std::stringstream s1, s2;
 
197
  a1.printnorm(s1);
 
198
  a2.printnorm(s2);
 
199
  return s1 == s2;
 
200
}
 
201
 
 
202
void AtomeListe::printnorm(std::ostream & o) const{
195
203
  if (sqbr) o << "[";
196
204
  if(Zed!=0){ /* cas o� ce n'est pas un groupe */
197
205
    o << symb;
229
237
 
230
238
char* moltypeStr[] = { "aq", "g", "s" };
231
239
 
 
240
bool operator == (const Molec & m1, const Molec & m2){
 
241
  return *(m1.al) == *(m2.al) && m1.ch == m2.ch;
 
242
}
 
243
 
232
244
const std::string Molec::signature()const{
233
245
  std::ostringstream o;
234
246
  o << liste();
416
428
  return o;
417
429
}
418
430
 
 
431
Membre operator & (Membre & m1, Membre & m2){
 
432
  Membre result;
 
433
  fraction min(1);
 
434
  for(Membre::iterator i = m1.begin(); i < m1.end(); i++){
 
435
    for(Membre::iterator j = m2.begin(); j < m2.end(); j++){
 
436
      if (**i == **j){
 
437
        Molec *m = new Molec(**i);
 
438
        if ((*i)->nb > (*j)->nb){
 
439
          min=(*j)->nb;
 
440
        }else{
 
441
          min=(*i)->nb;
 
442
        }
 
443
        m->nb=min;
 
444
        result.push_back(m);
 
445
      }
 
446
    }
 
447
  }
 
448
}
 
449
 
 
450
Membre operator - (Membre & m1, Membre & m2){
 
451
  Membre result;
 
452
  fraction diff(1);
 
453
  for(Membre::iterator i = m1.begin(); i < m1.end(); i++){
 
454
    Molec *m = new Molec(**i);
 
455
    for(Membre::iterator j = m2.begin(); j < m2.end(); j++){
 
456
      if (**i == **j){
 
457
        diff=(*i)->nb - (*j)->nb;
 
458
        m->nb=diff;
 
459
      }
 
460
    }
 
461
    result.push_back(m);
 
462
  }
 
463
}
 
464
 
419
465
void Chemeq::printnorm(std::ostream & o){
420
466
  gauche->printnorm(o);
421
467
  o << " -> ";
450
496
  mult.inverse();
451
497
  gauche->coeff(mult);
452
498
  droit->coeff(mult);
 
499
  Membre communs(*gauche & *droit);
 
500
  if (communs.size()>0){
 
501
    Membre * g, *d;
 
502
    g= new Membre(*gauche - communs);
 
503
    d= new Membre(*droit  - communs);
 
504
    delete gauche;
 
505
    delete droit;
 
506
    gauche=g;
 
507
    droit =d;
 
508
  }
453
509
  if (!redox()){
454
510
    val = val*mult.i/mult.d;
455
511
  }
556
612
  return result;
557
613
}
558
614
 
 
615
fraction operator - (fraction f, fraction g){
 
616
  fraction result = fraction(f.i*g.d-g.i*f.d, f.d*g.d);
 
617
  result.simplifie();
 
618
  return result;
 
619
}
 
620
 
559
621
void fraction::simplifie(){
560
622
  int maxprem = 23;
561
623
  int premiers[]={2,3,5,7,11,13,17,19,23,29};
572
634
  return f.i > f.d*i;
573
635
}
574
636
 
 
637
bool operator > (fraction f1, fraction f2){
 
638
  return f1.i*f2.d > f1.d*f2.i;
 
639
}
 
640
 
575
641
bool operator != (fraction f, int i){
576
642
  return f.i != f.d*i;
577
643
}