Main Page | Namespace List | Class Hierarchy | Class List | Directories | File List | Namespace Members | Class Members | File Members

EvalBasics.C

Go to the documentation of this file.
00001 // Copyright (C) 2001, Compaq Computer Corporation
00002 // 
00003 // This file is part of Vesta.
00004 // 
00005 // Vesta 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 // Vesta 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 Vesta; if not, write to the Free Software
00017 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00018 
00019 /* File: EvalBasics.C                                              */
00020 
00021 #include "EvalBasics.H"
00022 
00023 const Text emptyText;
00024 
00025 Text IntToText(int n) {
00026   char buff[32];
00027   sprintf(buff, "%d", n);
00028   Text res(buff);
00029   return res;
00030 }
00031 
00032 Text IntArc(int n) {
00033   char buff[32];
00034   sprintf(buff, "##%d", n);
00035   Text res(buff);
00036   return res;
00037 }
00038 
00039 int ArcInt(const Text& t) {
00040   if (t.chars()[0] == '#' &&
00041       t.chars()[1] == '#') {
00042     char *start = t.chars()+2, *end;
00043     // Clear errno first, as strtoul only sets it when there's an
00044     // overflow error.
00045     errno = 0;
00046     unsigned long int l_n = strtoul(start, &end, 10);
00047     // If the value was too large...
00048     if((errno == ERANGE) ||
00049        // ...or there was no number...
00050        (start == end) ||
00051        // ...or there were left-over bytes...
00052        (*end != 0))
00053       // ...treat this as a non-integer arc
00054       return -1;
00055     int n = l_n;
00056     // If converting to a signed integer resulted in a different
00057     // value, treat this as a non-integer arc
00058     if(((unsigned long int) n) != l_n)
00059       return -1;
00060     return n;
00061   }
00062   return -1;
00063 }
00064 
00065 static Basics::mutex counterMu;
00066 
00067 // Used to increment the various global counters.
00068 int IncCounter(int* counter) {
00069   counterMu.lock();
00070   int c = ++*counter;
00071   counterMu.unlock();
00072   return c;
00073 }

Generated on Mon May 8 00:48:37 2006 for Vesta by  doxygen 1.4.2