2008-01-07 09:09:04 +01:00
|
|
|
/*****************************************************************************
|
|
|
|
* Author: Valient Gough <vgough@pobox.com>
|
|
|
|
*
|
|
|
|
*****************************************************************************
|
2013-01-29 04:07:54 +01:00
|
|
|
* Copyright (c) 2004-2013, 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
|
|
|
*/
|
2013-10-20 00:35:26 +02:00
|
|
|
|
2013-01-29 04:07:54 +01:00
|
|
|
#include "base/Interface.h"
|
2008-01-07 09:09:04 +01:00
|
|
|
|
2013-01-29 04:07:54 +01:00
|
|
|
#include "base/ConfigVar.h"
|
2008-01-07 09:09:04 +01:00
|
|
|
|
2013-01-29 04:07:54 +01:00
|
|
|
#include <glog/logging.h>
|
|
|
|
#include <ostream>
|
2008-01-07 09:09:04 +01:00
|
|
|
|
2013-03-05 07:29:58 +01:00
|
|
|
namespace encfs {
|
|
|
|
|
2013-10-21 07:38:27 +02:00
|
|
|
using std::string;
|
|
|
|
using std::ostream;
|
|
|
|
|
|
|
|
ostream &operator<<(ostream &out, const Interface &iface) {
|
2013-10-20 00:35:26 +02:00
|
|
|
out << iface.name() << "(" << iface.major() << ":" << iface.minor() << ":"
|
|
|
|
<< iface.age() << ")";
|
2013-01-29 04:07:54 +01:00
|
|
|
return out;
|
|
|
|
}
|
2008-01-07 09:09:04 +01:00
|
|
|
|
2013-10-20 00:35:26 +02:00
|
|
|
bool implements(const Interface &A, const Interface &B) {
|
2013-01-29 04:07:54 +01:00
|
|
|
VLOG(1) << "checking if " << A << " implements " << B;
|
2008-01-07 09:09:04 +01:00
|
|
|
|
2013-10-20 00:35:26 +02:00
|
|
|
if (A.name() != B.name()) return false;
|
2008-01-07 09:09:04 +01:00
|
|
|
|
2012-04-26 04:34:15 +02:00
|
|
|
int currentDiff = A.major() - B.major();
|
2013-10-20 00:35:26 +02:00
|
|
|
return (currentDiff >= 0 && currentDiff <= (int)A.age());
|
2008-01-07 09:09:04 +01:00
|
|
|
}
|
|
|
|
|
2013-10-21 07:38:27 +02:00
|
|
|
Interface makeInterface(const string &name, int major, int minor, int age) {
|
2012-04-26 04:34:15 +02:00
|
|
|
Interface iface;
|
|
|
|
iface.set_name(name);
|
|
|
|
iface.set_major(major);
|
|
|
|
iface.set_minor(minor);
|
|
|
|
iface.set_age(age);
|
|
|
|
return iface;
|
2008-01-07 09:09:04 +01:00
|
|
|
}
|
|
|
|
|
2013-10-20 00:35:26 +02:00
|
|
|
ConfigVar &operator<<(ConfigVar &dst, const Interface &iface) {
|
2013-01-29 04:07:54 +01:00
|
|
|
dst << iface.name() << (int)iface.major() << (int)iface.minor()
|
|
|
|
<< (int)iface.age();
|
2012-04-26 04:34:15 +02:00
|
|
|
return dst;
|
2008-01-07 09:09:04 +01:00
|
|
|
}
|
|
|
|
|
2013-10-20 00:35:26 +02:00
|
|
|
const ConfigVar &operator>>(const ConfigVar &src, Interface &iface) {
|
2012-04-26 04:34:15 +02:00
|
|
|
src >> *iface.mutable_name();
|
|
|
|
int major, minor, age;
|
|
|
|
src >> major >> minor >> age;
|
|
|
|
iface.set_major(major);
|
|
|
|
iface.set_minor(minor);
|
|
|
|
iface.set_age(age);
|
|
|
|
return src;
|
2008-01-07 09:09:04 +01:00
|
|
|
}
|
|
|
|
|
2013-10-20 00:35:26 +02:00
|
|
|
bool operator!=(const Interface &a, const Interface &b) {
|
|
|
|
if (a.major() != b.major()) return true;
|
2008-01-07 09:09:04 +01:00
|
|
|
|
2013-10-20 00:35:26 +02:00
|
|
|
if (a.minor() != b.minor()) return true;
|
2008-01-07 09:09:04 +01:00
|
|
|
|
2012-04-26 04:34:15 +02:00
|
|
|
return false;
|
2008-01-07 09:09:04 +01:00
|
|
|
}
|
|
|
|
|
2013-03-05 07:29:58 +01:00
|
|
|
} // namespace encfs
|