repositorymanager.cpp

Go to the documentation of this file.
00001 //----------------------------------------------
00002 //          File: repositorymanager.cpp         
00003 //----------------------------------------------
00004 
00005 using namespace std;
00006 
00007 #include<cstdlib>
00008 #include<cstring>
00009 #include<string>
00010 #include<vector>
00011 
00012 #ifndef PARAMETERSINCLUDED
00013 #include "parameters.cpp"
00014 #endif
00015 
00016 #ifndef FRAMEINCLUDED
00017 #include "frame.cpp"
00018 #endif
00019 
00020 #ifndef PARAMETERSINCLUDED
00021 #include "parameters.cpp"
00022 #endif
00023 
00024 #define REPOSITORYMANAGERINCLUDED
00025 
00026 class repositorymanager{
00027 private:
00028         string emailid;                         // uniquely identifies the repository and is also the name of the repository directory.
00029         string path;                            //system path of the directory under which all the repositories are stored. 
00030  
00031 
00032 public:
00033   
00034    repositorymanager() 
00035    {                                //default constructor
00036      path=(string)REP_PATH;
00037      emailid="";
00038    }
00039 
00040    repositorymanager(string email_id, int create=NOCREATE)
00041    {
00042      string temp_path;
00043      FILE* fptr;
00044      path=(string)REP_PATH;                // repositories/
00045      emailid=email_id;
00046      temp_path=path+emailid;
00047      temp_path=temp_path+(string)CODEBOOK;    //  repositories/emailidstring/rep_file.bin 
00048      fptr=fopen(temp_path.c_str(),"r");
00049      int size=0;
00050      if(fptr!=NULL)
00051        size=fseek(fptr,0L,SEEK_END);  
00052      if(fptr)
00053      {
00054        fclose(fptr);  
00055      }
00056      else
00057      {     
00058        if(create==CREATE)
00059        {
00060        temp_path=(string)"mkdir "+path+emailid;
00061        system(temp_path.c_str());
00062        temp_path=path+emailid;
00063        temp_path=temp_path+(string)CODEBOOK;
00064        }
00065        else
00066        {
00067          cerr<<"The desired repository could not be found"<<endl;
00068          exit(1);
00069        }
00070      }
00071    }
00072  
00073   string makeNewFileName(int i)
00074   {
00075     string filename; 
00076     string temp;
00077     char tmp[60];
00078     sprintf(tmp,"%d",i);
00079     filename=path +emailid+"/"+tmp+".wav";
00080     return filename;
00081   }
00082 
00083   vector<double> getClusterCenter(unsigned int i)
00084   {
00085     FILE* fptr;
00086     vector<double> a;
00087     string temp_path=path+emailid;
00088     temp_path=temp_path+(string)CODEBOOK;  
00089     fptr=fopen(temp_path.c_str(),"r+");
00090     if(fptr!=NULL)
00091     {
00092       fseek(fptr,i*sizeof(double)*MAX_DIM,SEEK_SET); 
00093       double b; 
00094       for(int j=0;j<MAX_DIM;j++)
00095       {
00096         fread((double*)&b,sizeof(double),1,fptr);
00097         a.push_back(b);
00098       }
00099       fclose(fptr);
00100     }
00101     else
00102       cout<<"You don't possess the desired repository at the appropriate location";
00103     return a;
00104   }
00105 
00106   int addMFCC(vector<double> mfcc)
00107   {
00108     FILE* fptr;
00109     double temp_param;
00110     string temp_path;
00111     temp_path=path+emailid+(string)CODEBOOK;
00112     fptr=fopen(temp_path.c_str(),"a+");
00113     int bytes;
00114     for(int j=0;j<MAX_DIM;j++)
00115     {
00116       temp_param=mfcc[j];
00117       bytes=fwrite((double*)&temp_param,sizeof(double),1,fptr);
00118     }
00119     fclose(fptr);
00120     return SUCCESS;
00121   }
00122 
00123 
00124   string getFrameName(unsigned int code)
00125   {
00126     string filename;
00127     char tmp[60];
00128     sprintf(tmp,"%d",code);
00129     filename=path +emailid+"/"+tmp+".wav";
00130     return filename;  
00131   }
00132 
00133   ~repositorymanager() {
00134   }
00135 
00136 };
00137 
00138 /*
00139 int main()
00140 {
00141   string abc;
00142   repositorymanager rep_mgr("ttat@yahoo.com");
00143   rep_mgr.makeNewFileName(10,abc);
00144   cout<<abc;
00145   vector<double> a;
00146   for(double i=0.01;i<MAX_DIM;i++)
00147     a.push_back(i);
00148 
00149  rep_mgr.addMFCC(10,a);
00150  cout<<"\n"<<sizeof(int)<<"\n ";
00151  return 0;
00152 }
00153 
00154 */
00155 

Best viewed on Get Firefox!. Generated on Mon Mar 28 22:09:09 2005 for VoX by  doxygen 1.4.2 . This project hosted by SourceForge.net Logo .