Main Page   Namespace List   Class Hierarchy   Alphabetical List   Compound List   File List   Compound Members   File Members  

datamap.cc

Go to the documentation of this file.
00001 // Data map implementation -*- C++ -*-
00002 
00003 // Copyright (C) 2001-2003 Hermann Schichl
00004 //
00005 // This file is part of the COCONUT API.  This library
00006 // is free software; you can redistribute it and/or modify it under the
00007 // terms of the Library GNU General Public License as published by the
00008 // Free Software Foundation; either version 2, or (at your option)
00009 // any later version.
00010 
00011 // This library 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 // Library GNU General Public License for more details.
00015 
00016 // As a special exception, you may use this file as part of a free software
00017 // library without restriction.  Specifically, if other files instantiate
00018 // templates or use macros or inline functions from this file, or you compile
00019 // this file and link it with other files to produce an executable, this
00020 // file does not by itself cause the resulting executable to be covered by
00021 // the Library GNU General Public License.  This exception does not however
00022 // invalidate any other reasons why the executable file might be covered by
00023 // the Library GNU General Public License.
00024 
00027 #include <datamap.h>
00028 
00029 bool datamap::sinsert(const std::string& __s, const additional_info_u& __h,
00030                       bool remove)
00031 {
00032   _Base::iterator __b(find(__s));
00033 
00034   if(__b != end())
00035   {
00036     if(!remove) return false;
00037     erase(__b);
00038   }
00039   insert(std::make_pair(__s, __h));
00040   return true;
00041 }
00042 
00043 std::string datamap::encode(const std::string& __s, int i) const
00044 {
00045   char buf[30];
00046   sprintf(buf, "%+020d", i);
00047   return __s + __DATAMAP_SEPARATOR + buf;
00048 }
00049 
00050 bool datamap::update_index(const std::string& __s, int i, bool __insert)
00051 {
00052   _Base::iterator __b = find(__s + __DATAMAP_SEPARATOR + __DATAMAP_IDXSPEC);
00053   std::vector<int> _iv;
00054   bool update(false);
00055   
00056   if(__b != end())
00057     _iv = __b->second.n();
00058   std::vector<int>::iterator _lb = std::lower_bound(_iv.begin(), _iv.end(), i);
00059   if(__insert)
00060   {
00061     if(_lb == _iv.end() || *_lb != i)
00062     {
00063       update = true;
00064       _iv.insert(_lb, i);
00065     }
00066   }
00067   else
00068   {
00069     if(_lb != _iv.end() && *_lb == i)
00070     {
00071       update = true;
00072       _iv.erase(_lb);
00073     }
00074   }
00075   if(update)
00076   {
00077     if(__b != end()) erase(__b);
00078     insert(std::make_pair(__s + __DATAMAP_SEPARATOR + __DATAMAP_IDXSPEC, _iv));
00079   }
00080   return update;
00081 }
00082 
00083 bool datamap::check_index(const std::string& __s, int i) const
00084 {
00085   _Base::const_iterator __b = find(__s + __DATAMAP_SEPARATOR + __DATAMAP_IDXSPEC);
00086   bool ret(false);
00087   
00088   if(__b == end())
00089     return ret;
00090   return std::binary_search(__b->second.n().begin(), __b->second.n().end(), i);
00091 }

Generated on Tue Nov 4 01:57:57 2003 for COCONUT API by doxygen1.2.18