Files
Work/yproxy/hold/yheader.hpp
2024-08-07 09:16:27 -04:00

153 lines
2.7 KiB
C++

#ifndef _YPROXY_YHEADER_HPP_
#define _YPROXY_YHEADER_HPP_
#ifndef _COMMON_STRING_HPP_
#include <common/string.hpp>
#endif
class YHeader
{
public:
YHeader();
YHeader(const String &name,int size,int line,int part);
virtual ~YHeader();
bool fromString(String strLine);
const String &getName(void)const;
void setName(const String &name);
int getSize(void)const;
void setSize(int size);
int getLine(void)const;
void setLine(int line);
int getPart(void)const;
void setPart(int part);
private:
String mName;
int mSize;
int mLine;
int mPart;
};
inline
YHeader::YHeader()
: mSize(0), mLine(0), mPart(0)
{
}
inline
YHeader::YHeader(const String &name,int size,int line,int part)
: mName(name), mSize(size), mLine(line), mPart(part)
{
}
inline
YHeader::~YHeader()
{
}
inline
bool YHeader::fromString(String strLine)
{
int pos;
if(-1==(pos=strLine.strpos("=ybegin ")))return false;
if(-1==(pos=strLine.strpos("name=")))return false;
setName(strLine.substr(pos).betweenString('=',0));
if(-1==(pos=strLine.strpos("size=")))return false;
setSize(strLine.substr(pos).betweenString('=',0).toInt());
if(-1==(pos=strLine.strpos("line=")))return false;
setLine(strLine.substr(pos).betweenString('=',0).toInt());
if(-1==(pos=strLine.strpos("part=")))return false;
setPart(strLine.substr(pos).betweenString('=',0).toInt());
return true;
/*
if (aDsp) print("\r\nTrigger: %s\r\n",line);
// Start of a section found
cp=strstr(line,"name=");
if (cp==NULL)
{
eprint("'name=' not found in =ybegin line. (%s)\r\n",line);
errors++;
goto loop; // Error - filename not found
}
strcpy(attname,cp+5); // Store the filename
*cp=0; // throw away the filename
cp=strstr(line,"size=");
if (cp==NULL)
{
eprint("'size=' not found in =ybegin line. (%s)\r\n",line);
errors++;
goto loop; // Error - size not found
}
y_size=atol(cp+5);
cp=strstr(line,"line=");
if (cp==NULL)
{
eprint("'line=' not found in =ybegin line. (%s)\r\n",line);
errors++;
goto loop; // Error - linelength not found
}
y_line=atol(cp+5);
y_part=0;
cp=strstr(line,"part="); // Check if this is a multipart message
if (cp)
{
y_part=atol(cp+5);
// if (y_part != 1) goto loop; // MUST start with the first part for proper decoding
}
*/
}
inline
const String &YHeader::getName(void)const
{
return mName;
}
inline
void YHeader::setName(const String &name)
{
mName=name;
}
inline
int YHeader::getSize(void)const
{
return mSize;
}
inline
void YHeader::setSize(int size)
{
mSize=size;
}
inline
int YHeader::getLine(void)const
{
return mLine;
}
inline
void YHeader::setLine(int line)
{
mLine=line;
}
inline
int YHeader::getPart(void)const
{
return mPart;
}
inline
void YHeader::setPart(int part)
{
mPart=part;
}
#endif