/*
 * (c) 2005 Research Group Dr. Fuhrmann, University of Karlsruhe, Germany
 * All rights reserved.
 *
 * Author:
 *         Stefan Denk <denk@ira.uka.de>
 *
 * $Id: helper.cc,v 1.3 2005/12/27 12:12:33 kutzner Exp $
 *
 */

#include <stdint.h>
#include <assert.h>
#include <string>
#include <sstream>
using namespace std;

/** 
 * casts a given integer to a string.
 * \param from: the integer to cast.
 * \param base: the base of the int (only 10 is allowed as for the others the C++ library produces wrong results).
 * \return string(int);
 */
string uinttostr(uint32_t from, int base)
{
    ostringstream oss;   
    assert(base == 10);
    if (base == 10) oss.setf(ios::dec);
    oss << from;
    return oss.str();
}

/** 
 * casts a string to an integer.
 * \param from: the string to cast.
 * \param base: the base of the int (only 10 is allowed as for the others the C++ library produces wrong results).
 * \return int(string);
 */
uint32_t strtouint(const string& from, int base)
{
    uint to;
    istringstream iss(from);
    assert(base == 10);
    if (base == 10) iss.setf(ios::dec);
    iss >> to;
    return to;
}

/** 
 * casts a given long to a string.
 * \param from: the long to cast.
 * \param base: the base of the long (only 10 is allowed as for the others the C++ library produces wrong results).
 * \return string(long);
 */
string longtostr(long from, int base)
{
    ostringstream oss;    
    assert(base == 10);
    if (base == 10) oss.setf(ios::dec);
    oss << from;
    return oss.str();
}

/** 
 * checks if a given character in a vdr recfile is the beginning of an iframe.
 * \param ptr: the char sitting at a given offset.
 * \return true if it is the beginning of an iframe.
 */
bool iframe(char* ptr) {
	return (*((long*)ptr) == 0x100) && ((((short*)ptr)[2] & 0x38) == 8);
} 



