RecMode.cc

00001 /* 
00002    EyeDB Object Database Management System
00003    Copyright (C) 1994-2008 SYSRA
00004    
00005    EyeDB is free software; you can redistribute it and/or
00006    modify it under the terms of the GNU Lesser General Public
00007    License as published by the Free Software Foundation; either
00008    version 2.1 of the License, or (at your option) any later version.
00009    
00010    EyeDB is distributed in the hope that it will be useful,
00011    but WITHOUT ANY WARRANTY; without even the implied warranty of
00012    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00013    Lesser General Public License for more details.
00014    
00015    You should have received a copy of the GNU Lesser General Public
00016    License along with this library; if not, write to the Free Software
00017    Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA 
00018 */
00019 
00020 /*
00021    Author: Eric Viara <viara@sysra.com>
00022 */
00023 
00024 
00025 #include "eyedb_p.h"
00026 
00027 namespace eyedb {
00028 
00029   const RecMode *FullRecurs;
00030   const RecMode *NoRecurs;
00031 
00032   const RecMode *RecMode::FullRecurs;
00033   const RecMode *RecMode::NoRecurs;
00034 
00035   void RecMode::init(void)
00036   {
00037     static const RecMode FullRecurs_rec(RecMode_FullRecurs);;
00038     static const RecMode NoRecurs_rec(RecMode_NoRecurs);;
00039 
00040     eyedb::FullRecurs = &FullRecurs_rec;
00041     eyedb::NoRecurs = &NoRecurs_rec;
00042 
00043     FullRecurs = eyedb::FullRecurs;
00044     NoRecurs = eyedb::NoRecurs;
00045   }
00046 
00047   void RecMode::_release(void)
00048   {
00049   }
00050 
00051   RecMode::RecMode(RecModeType typ)
00052   {
00053     type = typ;
00054     u.pred = 0;
00055     u.fnm.fnm_cnt = 0;
00056   }
00057 
00058   RecMode::RecMode(Bool (*p)(const Object *,
00059                              const Attribute *, int))
00060   {
00061     type = RecMode_Predicat;
00062     u.pred = p;
00063   }
00064 
00065 #define SET_FNAMES(FIRST, AP) \
00066   va_list AP; \
00067   va_start(AP, FIRST); \
00068   char *s; \
00069   u.fnm.fnm_cnt = 1; \
00070  \
00071   while (s = va_arg(AP, char *)) \
00072     { \
00073       u.fnm.fnm_cnt++; \
00074     } \
00075   u.fnm.fnm = (char **)malloc(u.fnm.fnm_cnt * sizeof(char *)); \
00076   va_start(AP, FIRST); \
00077   int k = 0; \
00078   u.fnm.fnm[k++] = strdup(first); \
00079   while (s = va_arg(AP, char *)) \
00080     { \
00081       u.fnm.fnm[k++] = strdup(s); \
00082     } \
00083   va_end(AP);
00084 
00085   RecMode::RecMode(const char *first, ...)
00086   {
00087     type = RecMode_FieldNames;
00088     u.fnm._not = False;
00089 
00090     SET_FNAMES(first, ap);
00091   }
00092 
00093   RecMode::RecMode(Bool _not, const char *first, ...)
00094   {
00095     type = RecMode_FieldNames;
00096     u.fnm._not = _not;
00097 
00098     SET_FNAMES(first, ap);
00099   }
00100 
00101   Bool RecMode::isAgregRecurs(const Attribute *agreg, int n, const Object *o) const
00102   {
00103     if (type == RecMode_NoRecurs)
00104       return False;
00105 
00106     if (type == RecMode_FullRecurs)
00107       return True;
00108 
00109     if (type == RecMode_Predicat)
00110       return u.pred(o, agreg, n);
00111 
00112     if (type == RecMode_FieldNames)
00113       {
00114         const char *name = agreg->getName();
00115         for (int i = 0; i < u.fnm.fnm_cnt; i++)
00116           if (!strcmp(name, u.fnm.fnm[i]))
00117             return True;
00118      
00119         return False;
00120       }
00121 
00122     return False;
00123   }
00124 
00125 }

Generated on Mon Dec 22 18:16:07 2008 for eyedb by  doxygen 1.5.3