GenContext.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 
00026 #include <stdlib.h>
00027 #include <stdio.h>
00028 #include <assert.h>
00029 #include <string.h>
00030 #include "GenContext.h"
00031 
00032 #define GENCONTEXT_INC 2
00033 
00034 namespace eyedb {
00035 
00036   GenContext::GenContext(FILE *_fd, const char *_package,
00037                          const char *_rootclass)
00038   {
00039     buff_alloc = 32;
00040     buff = (char *)malloc(buff_alloc);
00041     buff_len = 0;
00042     buff[buff_len] = 0;
00043     fd = _fd;
00044     package = (_package ? strdup(_package) : 0);
00045     rootclass = (_rootclass ? strdup(_rootclass) : 0);
00046   }
00047 
00048   GenContext::~GenContext()
00049   {
00050     free(buff);
00051     free(package);
00052     free(rootclass);
00053   }
00054 
00055   void GenContext::push()
00056   {
00057     if (buff_len + GENCONTEXT_INC >= buff_alloc)
00058       {
00059         buff_alloc = buff_len + GENCONTEXT_INC + 32;
00060         buff = (char *)realloc(buff, buff_alloc);
00061       }
00062 
00063     for (int i = 0; i < GENCONTEXT_INC; i++)
00064       buff[buff_len++] = ' ';
00065 
00066     buff[buff_len] = 0;
00067   }
00068 
00069   void GenContext::pop()
00070   {
00071     buff_len -= GENCONTEXT_INC;
00072 
00073     assert(buff_len >= 0);
00074     buff[buff_len] = 0;
00075   }
00076 
00077   void GenContext::print()
00078   {
00079     fprintf(fd, "%s", buff);
00080   }
00081 
00082   FILE *GenContext::getFile()
00083   {
00084     return fd;
00085   }
00086 
00087   const char *GenContext::get() const
00088   {
00089     return buff;
00090   }
00091 
00092 }
00093   

Generated on Mon Dec 22 18:15:55 2008 for eyedb by  doxygen 1.5.3