00001 /************************************************************************ 00002 ************************************************************************ 00003 FAUST compiler 00004 Copyright (C) 2003-2004 GRAME, Centre National de Creation Musicale 00005 --------------------------------------------------------------------- 00006 This program is free software; you can redistribute it and/or modify 00007 it under the terms of the GNU General Public License as published by 00008 the Free Software Foundation; either version 2 of the License, or 00009 (at your option) any later version. 00010 00011 This program is distributed in the hope that it will be useful, 00012 but WITHOUT ANY WARRANTY; without even the implied warranty of 00013 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00014 GNU General Public License for more details. 00015 00016 You should have received a copy of the GNU General Public License 00017 along with this program; if not, write to the Free Software 00018 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. 00019 ************************************************************************ 00020 ************************************************************************/ 00029 // construction des representations graphiques 00030 00031 00032 #include "occurrences.hh" 00033 #include "compatibility.hh" 00034 00038 Occurrences::Occurrences(Tree root) 00039 { 00040 fKey = specificKey(root); 00041 countOccurrences(root); 00042 setCount(root,0); // root as no occurences in itself 00043 } 00044 00048 int Occurrences::getCount(Tree t) 00049 { 00050 Tree c; 00051 return (getProperty(t, fKey, c)) ? c->node().getInt() : 0; 00052 } 00053 00057 void Occurrences::setCount(Tree t, int c) 00058 { 00059 setProperty(t, fKey, tree(c)); 00060 } 00061 00062 00063 00067 Tree Occurrences::specificKey(Tree root) 00068 { 00069 char keyname[256]; 00070 snprintf(keyname, 256, "OCCURRENCES COUNT IN %p : ", (CTree*)root); 00071 00072 return tree(unique(keyname)); 00073 } 00074 00078 void Occurrences::countOccurrences(Tree t) 00079 { 00080 setCount(t, getCount(t)+1); // increment t occurrences count 00081 for (int i=0; i<t->arity(); i++) { 00082 countOccurrences(t->branch(i)); 00083 } 00084 } 00085