2008-01-07 09:09:04 +01:00
|
|
|
/*****************************************************************************
|
|
|
|
* Author: Valient Gough <vgough@pobox.com>
|
|
|
|
*
|
|
|
|
*****************************************************************************
|
|
|
|
* Copyright (c) 2004, Valient Gough
|
2012-10-03 07:12:17 +02:00
|
|
|
*
|
|
|
|
* This program is free software: you can redistribute it and/or modify it
|
|
|
|
* under the terms of the GNU Lesser General Public License as published by the
|
|
|
|
* Free Software Foundation, either version 3 of the License, or (at your
|
2013-10-20 00:35:26 +02:00
|
|
|
* option) any later version.
|
2008-01-07 09:09:04 +01:00
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful, but WITHOUT
|
|
|
|
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
2012-10-03 07:12:17 +02:00
|
|
|
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
|
|
|
|
* for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Lesser General Public License
|
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
2008-01-07 09:09:04 +01:00
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef _ConfigVar_incl_
|
|
|
|
#define _ConfigVar_incl_
|
|
|
|
|
|
|
|
#include <string>
|
2013-01-29 04:07:54 +01:00
|
|
|
#include "base/shared_ptr.h"
|
2013-03-05 07:29:58 +01:00
|
|
|
#include "base/types.h"
|
|
|
|
|
|
|
|
namespace encfs {
|
2008-01-07 09:09:04 +01:00
|
|
|
|
2013-10-20 00:35:26 +02:00
|
|
|
class ConfigVar {
|
|
|
|
struct ConfigVarData {
|
|
|
|
std::string buffer;
|
|
|
|
int offset;
|
|
|
|
};
|
2008-01-07 09:09:04 +01:00
|
|
|
|
2013-10-20 00:35:26 +02:00
|
|
|
shared_ptr<ConfigVarData> pd;
|
2008-01-07 09:09:04 +01:00
|
|
|
|
2013-10-20 00:35:26 +02:00
|
|
|
public:
|
|
|
|
ConfigVar();
|
|
|
|
ConfigVar(const std::string &buffer);
|
|
|
|
ConfigVar(const ConfigVar &src);
|
|
|
|
~ConfigVar();
|
2008-01-07 09:09:04 +01:00
|
|
|
|
2013-10-20 00:35:26 +02:00
|
|
|
ConfigVar &operator=(const ConfigVar &src);
|
2008-01-07 09:09:04 +01:00
|
|
|
|
2013-10-20 00:35:26 +02:00
|
|
|
// reset read/write offset..
|
|
|
|
void resetOffset();
|
2008-01-07 09:09:04 +01:00
|
|
|
|
2013-10-20 00:35:26 +02:00
|
|
|
// read bytes
|
|
|
|
int read(byte *buffer, int size) const;
|
2008-01-07 09:09:04 +01:00
|
|
|
|
2013-10-20 00:35:26 +02:00
|
|
|
// write bytes..
|
|
|
|
int write(const byte *data, int size);
|
2008-01-07 09:09:04 +01:00
|
|
|
|
2013-10-20 00:35:26 +02:00
|
|
|
int readInt() const;
|
|
|
|
int readInt(int defaultValue) const;
|
|
|
|
void writeInt(int value);
|
2008-01-07 09:09:04 +01:00
|
|
|
|
2013-10-20 00:35:26 +02:00
|
|
|
bool readBool(bool defaultValue) const;
|
2008-01-07 09:09:04 +01:00
|
|
|
|
2013-10-20 00:35:26 +02:00
|
|
|
void writeString(const char *data, int size);
|
2008-01-07 09:09:04 +01:00
|
|
|
|
2013-10-20 00:35:26 +02:00
|
|
|
// return amount of data in var
|
|
|
|
int size() const;
|
|
|
|
// return data pointer - returns front of data pointer, not the current
|
|
|
|
// position.
|
|
|
|
const char *buffer() const;
|
2008-01-07 09:09:04 +01:00
|
|
|
|
2013-10-20 00:35:26 +02:00
|
|
|
// return current position in data() buffer.
|
|
|
|
int at() const;
|
2008-01-07 09:09:04 +01:00
|
|
|
};
|
|
|
|
|
2013-10-20 00:35:26 +02:00
|
|
|
ConfigVar &operator<<(ConfigVar &, bool);
|
|
|
|
ConfigVar &operator<<(ConfigVar &, int);
|
|
|
|
ConfigVar &operator<<(ConfigVar &, const std::string &str);
|
2008-01-07 09:09:04 +01:00
|
|
|
|
2013-10-20 00:35:26 +02:00
|
|
|
const ConfigVar &operator>>(const ConfigVar &, bool &);
|
|
|
|
const ConfigVar &operator>>(const ConfigVar &, int &);
|
|
|
|
const ConfigVar &operator>>(const ConfigVar &, std::string &str);
|
2008-01-07 09:09:04 +01:00
|
|
|
|
2013-03-05 07:29:58 +01:00
|
|
|
} // namespace encfs
|
|
|
|
|
2008-01-07 09:09:04 +01:00
|
|
|
#endif
|