00001 // -*- c++ -*- 00002 //------------------------------------------------------------------------------ 00003 // SerialNumber.cpp 00004 //------------------------------------------------------------------------------ 00005 // $Id: SerialNumber.cpp,v 1.3 2003/02/07 05:15:10 vlg Exp $ 00006 //------------------------------------------------------------------------------ 00007 // Copyright (c) 2002 by Vladislav Grinchenko 00008 // 00009 // This program is free software; you can redistribute it and/or 00010 // modify it under the terms of the GNU General Public License 00011 // as published by the Free Software Foundation; either version 00012 // 2 of the License, or (at your option) any later version. 00013 //------------------------------------------------------------------------------ 00014 // Created: 07/30/2002 00015 //------------------------------------------------------------------------------ 00016 00017 #include <sstream> 00018 #include <iomanip> 00019 00020 #include "SerialNumber.h" 00021 00022 00023 SerialNumber::SerialNumber (u_int base_, const string& prefix_, 00024 const string postfix_, size_t size_) 00025 : 00026 m_prefix (prefix_), m_postfix (postfix_), m_size (size_+base_), 00027 m_current (base_), m_width (1) 00028 { 00029 int j = 10; 00030 while (m_size >= j) { 00031 m_width++; 00032 j *= 10; 00033 } 00034 } 00035 00036 SerialNumber 00037 00038 SerialNumber::operator++ () 00039 { 00040 if (m_current < m_size) { 00041 m_current++; 00042 } 00043 return *this; 00044 } 00045 00046 SerialNumber 00047 00048 SerialNumber::operator++ (int) 00049 { 00050 SerialNumber sn = *this; 00051 ++*this; 00052 return sn; 00053 } 00054 00055 00056 SerialNumber::operator string () 00057 { 00058 std::ostringstream os; 00059 os.setf (std::ios::right); 00060 os.fill ('0'); 00061 00065 os << m_prefix << std::setw (m_width) << m_current << m_postfix; 00066 00067 return os.str (); 00068 } 00069