XAttrs.cpp
author František Kučera <franta-hg@frantovo.cz>
Tue, 08 Oct 2024 22:24:40 +0200
branchv_0
changeset 34 8cf3812a92eb
parent 33 3aae6275b683
permissions -rw-r--r--
improved Makefile + small fixes
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
19
262828ae9682 OOP for Texture
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
     1
/**
262828ae9682 OOP for Texture
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
     2
 * ShaderShark
262828ae9682 OOP for Texture
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
     3
 * Copyright © 2023 František Kučera (Frantovo.cz, GlobalCode.info)
262828ae9682 OOP for Texture
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
     4
 *
262828ae9682 OOP for Texture
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
     5
 * This program is free software: you can redistribute it and/or modify
262828ae9682 OOP for Texture
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
     6
 * it under the terms of the GNU General Public License as published by
262828ae9682 OOP for Texture
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
     7
 * the Free Software Foundation, version 3 of the License.
262828ae9682 OOP for Texture
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
     8
 *
262828ae9682 OOP for Texture
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
     9
 * This program is distributed in the hope that it will be useful,
262828ae9682 OOP for Texture
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    10
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
262828ae9682 OOP for Texture
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    11
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
262828ae9682 OOP for Texture
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    12
 * GNU General Public License for more details.
262828ae9682 OOP for Texture
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    13
 *
262828ae9682 OOP for Texture
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    14
 * You should have received a copy of the GNU General Public License
262828ae9682 OOP for Texture
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    15
 * along with this program. If not, see <http://www.gnu.org/licenses/>.
262828ae9682 OOP for Texture
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    16
 */
262828ae9682 OOP for Texture
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    17
262828ae9682 OOP for Texture
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    18
#include <string>
24
98d033d3ef7c xattr: XAttrs class that read/write/list extended attributes
František Kučera <franta-hg@frantovo.cz>
parents: 22
diff changeset
    19
#include <cstring>
19
262828ae9682 OOP for Texture
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    20
#include <stdexcept>
24
98d033d3ef7c xattr: XAttrs class that read/write/list extended attributes
František Kučera <franta-hg@frantovo.cz>
parents: 22
diff changeset
    21
#include <vector>
98d033d3ef7c xattr: XAttrs class that read/write/list extended attributes
František Kučera <franta-hg@frantovo.cz>
parents: 22
diff changeset
    22
#include <sys/xattr.h>
98d033d3ef7c xattr: XAttrs class that read/write/list extended attributes
František Kučera <franta-hg@frantovo.cz>
parents: 22
diff changeset
    23
98d033d3ef7c xattr: XAttrs class that read/write/list extended attributes
František Kučera <franta-hg@frantovo.cz>
parents: 22
diff changeset
    24
#include "XAttrs.h"
19
262828ae9682 OOP for Texture
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    25
24
98d033d3ef7c xattr: XAttrs class that read/write/list extended attributes
František Kučera <franta-hg@frantovo.cz>
parents: 22
diff changeset
    26
std::string xattrGet(
98d033d3ef7c xattr: XAttrs class that read/write/list extended attributes
František Kučera <franta-hg@frantovo.cz>
parents: 22
diff changeset
    27
		const std::string fileName,
98d033d3ef7c xattr: XAttrs class that read/write/list extended attributes
František Kučera <franta-hg@frantovo.cz>
parents: 22
diff changeset
    28
		const std::string name,
33
3aae6275b683 xattr: tolerate ENOTSUP (behave like there are no attributes when not supported on given FS)
František Kučera <franta-hg@frantovo.cz>
parents: 27
diff changeset
    29
		bool* exists = nullptr,
3aae6275b683 xattr: tolerate ENOTSUP (behave like there are no attributes when not supported on given FS)
František Kučera <franta-hg@frantovo.cz>
parents: 27
diff changeset
    30
		bool* supported = nullptr) {
24
98d033d3ef7c xattr: XAttrs class that read/write/list extended attributes
František Kučera <franta-hg@frantovo.cz>
parents: 22
diff changeset
    31
	std::string buffer;
98d033d3ef7c xattr: XAttrs class that read/write/list extended attributes
František Kučera <franta-hg@frantovo.cz>
parents: 22
diff changeset
    32
	ssize_t size = getxattr(fileName.c_str(), name.c_str(), nullptr, 0);
98d033d3ef7c xattr: XAttrs class that read/write/list extended attributes
František Kučera <franta-hg@frantovo.cz>
parents: 22
diff changeset
    33
	if (size > 0) {
98d033d3ef7c xattr: XAttrs class that read/write/list extended attributes
František Kučera <franta-hg@frantovo.cz>
parents: 22
diff changeset
    34
		buffer.resize(size);
98d033d3ef7c xattr: XAttrs class that read/write/list extended attributes
František Kučera <franta-hg@frantovo.cz>
parents: 22
diff changeset
    35
		getxattr(fileName.c_str(), name.c_str(), buffer.data(), buffer.size());
98d033d3ef7c xattr: XAttrs class that read/write/list extended attributes
František Kučera <franta-hg@frantovo.cz>
parents: 22
diff changeset
    36
		if (exists) *exists = true;
33
3aae6275b683 xattr: tolerate ENOTSUP (behave like there are no attributes when not supported on given FS)
František Kučera <franta-hg@frantovo.cz>
parents: 27
diff changeset
    37
		if (supported) *supported = true;
24
98d033d3ef7c xattr: XAttrs class that read/write/list extended attributes
František Kučera <franta-hg@frantovo.cz>
parents: 22
diff changeset
    38
		return buffer;
98d033d3ef7c xattr: XAttrs class that read/write/list extended attributes
František Kučera <franta-hg@frantovo.cz>
parents: 22
diff changeset
    39
	} else if (size == 0) {
98d033d3ef7c xattr: XAttrs class that read/write/list extended attributes
František Kučera <franta-hg@frantovo.cz>
parents: 22
diff changeset
    40
		if (exists) *exists = true;
33
3aae6275b683 xattr: tolerate ENOTSUP (behave like there are no attributes when not supported on given FS)
František Kučera <franta-hg@frantovo.cz>
parents: 27
diff changeset
    41
		if (supported) *supported = true;
24
98d033d3ef7c xattr: XAttrs class that read/write/list extended attributes
František Kučera <franta-hg@frantovo.cz>
parents: 22
diff changeset
    42
		return "";
98d033d3ef7c xattr: XAttrs class that read/write/list extended attributes
František Kučera <franta-hg@frantovo.cz>
parents: 22
diff changeset
    43
	} else if (errno == ENODATA) {
98d033d3ef7c xattr: XAttrs class that read/write/list extended attributes
František Kučera <franta-hg@frantovo.cz>
parents: 22
diff changeset
    44
		if (exists) *exists = false;
33
3aae6275b683 xattr: tolerate ENOTSUP (behave like there are no attributes when not supported on given FS)
František Kučera <franta-hg@frantovo.cz>
parents: 27
diff changeset
    45
		if (supported) *supported = true;
24
98d033d3ef7c xattr: XAttrs class that read/write/list extended attributes
František Kučera <franta-hg@frantovo.cz>
parents: 22
diff changeset
    46
		return "";
98d033d3ef7c xattr: XAttrs class that read/write/list extended attributes
František Kučera <franta-hg@frantovo.cz>
parents: 22
diff changeset
    47
	} else if (errno == ERANGE) {
98d033d3ef7c xattr: XAttrs class that read/write/list extended attributes
František Kučera <franta-hg@frantovo.cz>
parents: 22
diff changeset
    48
		// rare race condition - the value has changed between the two calls
98d033d3ef7c xattr: XAttrs class that read/write/list extended attributes
František Kučera <franta-hg@frantovo.cz>
parents: 22
diff changeset
    49
		return xattrGet(fileName, name, exists);
33
3aae6275b683 xattr: tolerate ENOTSUP (behave like there are no attributes when not supported on given FS)
František Kučera <franta-hg@frantovo.cz>
parents: 27
diff changeset
    50
	} else if (errno == ENOTSUP) {
3aae6275b683 xattr: tolerate ENOTSUP (behave like there are no attributes when not supported on given FS)
František Kučera <franta-hg@frantovo.cz>
parents: 27
diff changeset
    51
		if (supported) *supported = false;
3aae6275b683 xattr: tolerate ENOTSUP (behave like there are no attributes when not supported on given FS)
František Kučera <franta-hg@frantovo.cz>
parents: 27
diff changeset
    52
		return "";
24
98d033d3ef7c xattr: XAttrs class that read/write/list extended attributes
František Kučera <franta-hg@frantovo.cz>
parents: 22
diff changeset
    53
	} else {
98d033d3ef7c xattr: XAttrs class that read/write/list extended attributes
František Kučera <franta-hg@frantovo.cz>
parents: 22
diff changeset
    54
		throw std::logic_error(
98d033d3ef7c xattr: XAttrs class that read/write/list extended attributes
František Kučera <franta-hg@frantovo.cz>
parents: 22
diff changeset
    55
				std::string("Unable to get extended attribute: ")
98d033d3ef7c xattr: XAttrs class that read/write/list extended attributes
František Kučera <franta-hg@frantovo.cz>
parents: 22
diff changeset
    56
				+ strerror(errno));
98d033d3ef7c xattr: XAttrs class that read/write/list extended attributes
František Kučera <franta-hg@frantovo.cz>
parents: 22
diff changeset
    57
	}
98d033d3ef7c xattr: XAttrs class that read/write/list extended attributes
František Kučera <franta-hg@frantovo.cz>
parents: 22
diff changeset
    58
}
19
262828ae9682 OOP for Texture
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    59
24
98d033d3ef7c xattr: XAttrs class that read/write/list extended attributes
František Kučera <franta-hg@frantovo.cz>
parents: 22
diff changeset
    60
bool xattrSet(const std::string fileName,
98d033d3ef7c xattr: XAttrs class that read/write/list extended attributes
František Kučera <franta-hg@frantovo.cz>
parents: 22
diff changeset
    61
		const std::string name,
98d033d3ef7c xattr: XAttrs class that read/write/list extended attributes
František Kučera <franta-hg@frantovo.cz>
parents: 22
diff changeset
    62
		const std::string value,
33
3aae6275b683 xattr: tolerate ENOTSUP (behave like there are no attributes when not supported on given FS)
František Kučera <franta-hg@frantovo.cz>
parents: 27
diff changeset
    63
		bool exists = true,
3aae6275b683 xattr: tolerate ENOTSUP (behave like there are no attributes when not supported on given FS)
František Kučera <franta-hg@frantovo.cz>
parents: 27
diff changeset
    64
		bool* supported = nullptr) {
24
98d033d3ef7c xattr: XAttrs class that read/write/list extended attributes
František Kučera <franta-hg@frantovo.cz>
parents: 22
diff changeset
    65
	int result;
98d033d3ef7c xattr: XAttrs class that read/write/list extended attributes
František Kučera <franta-hg@frantovo.cz>
parents: 22
diff changeset
    66
	if (exists) {
98d033d3ef7c xattr: XAttrs class that read/write/list extended attributes
František Kučera <franta-hg@frantovo.cz>
parents: 22
diff changeset
    67
		result = setxattr(
98d033d3ef7c xattr: XAttrs class that read/write/list extended attributes
František Kučera <franta-hg@frantovo.cz>
parents: 22
diff changeset
    68
				fileName.c_str(),
98d033d3ef7c xattr: XAttrs class that read/write/list extended attributes
František Kučera <franta-hg@frantovo.cz>
parents: 22
diff changeset
    69
				name.c_str(),
98d033d3ef7c xattr: XAttrs class that read/write/list extended attributes
František Kučera <franta-hg@frantovo.cz>
parents: 22
diff changeset
    70
				value.c_str(),
98d033d3ef7c xattr: XAttrs class that read/write/list extended attributes
František Kučera <franta-hg@frantovo.cz>
parents: 22
diff changeset
    71
				value.size(),
98d033d3ef7c xattr: XAttrs class that read/write/list extended attributes
František Kučera <franta-hg@frantovo.cz>
parents: 22
diff changeset
    72
				0);
98d033d3ef7c xattr: XAttrs class that read/write/list extended attributes
František Kučera <franta-hg@frantovo.cz>
parents: 22
diff changeset
    73
	} else {
98d033d3ef7c xattr: XAttrs class that read/write/list extended attributes
František Kučera <franta-hg@frantovo.cz>
parents: 22
diff changeset
    74
		result = removexattr(fileName.c_str(), name.c_str());
98d033d3ef7c xattr: XAttrs class that read/write/list extended attributes
František Kučera <franta-hg@frantovo.cz>
parents: 22
diff changeset
    75
		if (result < 0 && errno == ENODATA) return false;
98d033d3ef7c xattr: XAttrs class that read/write/list extended attributes
František Kučera <franta-hg@frantovo.cz>
parents: 22
diff changeset
    76
	}
98d033d3ef7c xattr: XAttrs class that read/write/list extended attributes
František Kučera <franta-hg@frantovo.cz>
parents: 22
diff changeset
    77
33
3aae6275b683 xattr: tolerate ENOTSUP (behave like there are no attributes when not supported on given FS)
František Kučera <franta-hg@frantovo.cz>
parents: 27
diff changeset
    78
	if (result < 0 && errno == ENOTSUP && supported) *supported = false;
3aae6275b683 xattr: tolerate ENOTSUP (behave like there are no attributes when not supported on given FS)
František Kučera <franta-hg@frantovo.cz>
parents: 27
diff changeset
    79
	else if (result < 0) throw std::logic_error(
24
98d033d3ef7c xattr: XAttrs class that read/write/list extended attributes
František Kučera <franta-hg@frantovo.cz>
parents: 22
diff changeset
    80
			std::string("Unable to set extended attribute: ")
98d033d3ef7c xattr: XAttrs class that read/write/list extended attributes
František Kučera <franta-hg@frantovo.cz>
parents: 22
diff changeset
    81
			+ strerror(errno));
33
3aae6275b683 xattr: tolerate ENOTSUP (behave like there are no attributes when not supported on given FS)
František Kučera <franta-hg@frantovo.cz>
parents: 27
diff changeset
    82
3aae6275b683 xattr: tolerate ENOTSUP (behave like there are no attributes when not supported on given FS)
František Kučera <franta-hg@frantovo.cz>
parents: 27
diff changeset
    83
	return true;
24
98d033d3ef7c xattr: XAttrs class that read/write/list extended attributes
František Kučera <franta-hg@frantovo.cz>
parents: 22
diff changeset
    84
}
98d033d3ef7c xattr: XAttrs class that read/write/list extended attributes
František Kučera <franta-hg@frantovo.cz>
parents: 22
diff changeset
    85
33
3aae6275b683 xattr: tolerate ENOTSUP (behave like there are no attributes when not supported on given FS)
František Kučera <franta-hg@frantovo.cz>
parents: 27
diff changeset
    86
std::vector<std::string>
3aae6275b683 xattr: tolerate ENOTSUP (behave like there are no attributes when not supported on given FS)
František Kučera <franta-hg@frantovo.cz>
parents: 27
diff changeset
    87
xattrList(const std::string fileName, bool* supported = nullptr) {
24
98d033d3ef7c xattr: XAttrs class that read/write/list extended attributes
František Kučera <franta-hg@frantovo.cz>
parents: 22
diff changeset
    88
	std::string buffer;
98d033d3ef7c xattr: XAttrs class that read/write/list extended attributes
František Kučera <franta-hg@frantovo.cz>
parents: 22
diff changeset
    89
	ssize_t size = listxattr(fileName.c_str(), nullptr, 0);
98d033d3ef7c xattr: XAttrs class that read/write/list extended attributes
František Kučera <franta-hg@frantovo.cz>
parents: 22
diff changeset
    90
	if (size >= 0) {
98d033d3ef7c xattr: XAttrs class that read/write/list extended attributes
František Kučera <franta-hg@frantovo.cz>
parents: 22
diff changeset
    91
		buffer.resize(size);
98d033d3ef7c xattr: XAttrs class that read/write/list extended attributes
František Kučera <franta-hg@frantovo.cz>
parents: 22
diff changeset
    92
		listxattr(fileName.c_str(), buffer.data(), buffer.size());
98d033d3ef7c xattr: XAttrs class that read/write/list extended attributes
František Kučera <franta-hg@frantovo.cz>
parents: 22
diff changeset
    93
98d033d3ef7c xattr: XAttrs class that read/write/list extended attributes
František Kučera <franta-hg@frantovo.cz>
parents: 22
diff changeset
    94
		std::vector<std::string> result;
98d033d3ef7c xattr: XAttrs class that read/write/list extended attributes
František Kučera <franta-hg@frantovo.cz>
parents: 22
diff changeset
    95
		for (const char* k = buffer.c_str(); strlen(k); k += strlen(k) + 1) {
98d033d3ef7c xattr: XAttrs class that read/write/list extended attributes
František Kučera <franta-hg@frantovo.cz>
parents: 22
diff changeset
    96
			result.push_back(k);
98d033d3ef7c xattr: XAttrs class that read/write/list extended attributes
František Kučera <franta-hg@frantovo.cz>
parents: 22
diff changeset
    97
		}
33
3aae6275b683 xattr: tolerate ENOTSUP (behave like there are no attributes when not supported on given FS)
František Kučera <franta-hg@frantovo.cz>
parents: 27
diff changeset
    98
		if (supported) *supported = true;
24
98d033d3ef7c xattr: XAttrs class that read/write/list extended attributes
František Kučera <franta-hg@frantovo.cz>
parents: 22
diff changeset
    99
		return result;
98d033d3ef7c xattr: XAttrs class that read/write/list extended attributes
František Kučera <franta-hg@frantovo.cz>
parents: 22
diff changeset
   100
	} else if (errno == ERANGE) {
98d033d3ef7c xattr: XAttrs class that read/write/list extended attributes
František Kučera <franta-hg@frantovo.cz>
parents: 22
diff changeset
   101
		// rare race condition - the list has changed between the two calls
98d033d3ef7c xattr: XAttrs class that read/write/list extended attributes
František Kučera <franta-hg@frantovo.cz>
parents: 22
diff changeset
   102
		return xattrList(fileName);
33
3aae6275b683 xattr: tolerate ENOTSUP (behave like there are no attributes when not supported on given FS)
František Kučera <franta-hg@frantovo.cz>
parents: 27
diff changeset
   103
	} else if (errno == ENOTSUP) {
3aae6275b683 xattr: tolerate ENOTSUP (behave like there are no attributes when not supported on given FS)
František Kučera <franta-hg@frantovo.cz>
parents: 27
diff changeset
   104
		if (supported) *supported = false;
3aae6275b683 xattr: tolerate ENOTSUP (behave like there are no attributes when not supported on given FS)
František Kučera <franta-hg@frantovo.cz>
parents: 27
diff changeset
   105
		return std::vector<std::string>();
24
98d033d3ef7c xattr: XAttrs class that read/write/list extended attributes
František Kučera <franta-hg@frantovo.cz>
parents: 22
diff changeset
   106
	} else {
98d033d3ef7c xattr: XAttrs class that read/write/list extended attributes
František Kučera <franta-hg@frantovo.cz>
parents: 22
diff changeset
   107
		throw std::logic_error(
98d033d3ef7c xattr: XAttrs class that read/write/list extended attributes
František Kučera <franta-hg@frantovo.cz>
parents: 22
diff changeset
   108
				std::string("Unable to list extended attributes: ")
98d033d3ef7c xattr: XAttrs class that read/write/list extended attributes
František Kučera <franta-hg@frantovo.cz>
parents: 22
diff changeset
   109
				+ strerror(errno));
98d033d3ef7c xattr: XAttrs class that read/write/list extended attributes
František Kučera <franta-hg@frantovo.cz>
parents: 22
diff changeset
   110
	}
98d033d3ef7c xattr: XAttrs class that read/write/list extended attributes
František Kučera <franta-hg@frantovo.cz>
parents: 22
diff changeset
   111
}
98d033d3ef7c xattr: XAttrs class that read/write/list extended attributes
František Kučera <franta-hg@frantovo.cz>
parents: 22
diff changeset
   112
98d033d3ef7c xattr: XAttrs class that read/write/list extended attributes
František Kučera <franta-hg@frantovo.cz>
parents: 22
diff changeset
   113
class XAttrs::Attribute::Impl {
19
262828ae9682 OOP for Texture
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
   114
public:
24
98d033d3ef7c xattr: XAttrs class that read/write/list extended attributes
František Kučera <franta-hg@frantovo.cz>
parents: 22
diff changeset
   115
98d033d3ef7c xattr: XAttrs class that read/write/list extended attributes
František Kučera <franta-hg@frantovo.cz>
parents: 22
diff changeset
   116
	Impl() {
98d033d3ef7c xattr: XAttrs class that read/write/list extended attributes
František Kučera <franta-hg@frantovo.cz>
parents: 22
diff changeset
   117
	}
98d033d3ef7c xattr: XAttrs class that read/write/list extended attributes
František Kučera <franta-hg@frantovo.cz>
parents: 22
diff changeset
   118
98d033d3ef7c xattr: XAttrs class that read/write/list extended attributes
František Kučera <franta-hg@frantovo.cz>
parents: 22
diff changeset
   119
	virtual ~Impl() {
98d033d3ef7c xattr: XAttrs class that read/write/list extended attributes
František Kučera <franta-hg@frantovo.cz>
parents: 22
diff changeset
   120
	}
98d033d3ef7c xattr: XAttrs class that read/write/list extended attributes
František Kučera <franta-hg@frantovo.cz>
parents: 22
diff changeset
   121
98d033d3ef7c xattr: XAttrs class that read/write/list extended attributes
František Kučera <franta-hg@frantovo.cz>
parents: 22
diff changeset
   122
	std::shared_ptr<XAttrs::Impl> xattrs;
98d033d3ef7c xattr: XAttrs class that read/write/list extended attributes
František Kučera <franta-hg@frantovo.cz>
parents: 22
diff changeset
   123
	std::string name;
98d033d3ef7c xattr: XAttrs class that read/write/list extended attributes
František Kučera <franta-hg@frantovo.cz>
parents: 22
diff changeset
   124
	std::string value;
98d033d3ef7c xattr: XAttrs class that read/write/list extended attributes
František Kučera <franta-hg@frantovo.cz>
parents: 22
diff changeset
   125
	bool exists = true;
98d033d3ef7c xattr: XAttrs class that read/write/list extended attributes
František Kučera <franta-hg@frantovo.cz>
parents: 22
diff changeset
   126
	bool loaded = false;
34
8cf3812a92eb improved Makefile + small fixes
František Kučera <franta-hg@frantovo.cz>
parents: 33
diff changeset
   127
8cf3812a92eb improved Makefile + small fixes
František Kučera <franta-hg@frantovo.cz>
parents: 33
diff changeset
   128
private:
8cf3812a92eb improved Makefile + small fixes
František Kučera <franta-hg@frantovo.cz>
parents: 33
diff changeset
   129
	Impl(const Impl&) = delete;
8cf3812a92eb improved Makefile + small fixes
František Kučera <franta-hg@frantovo.cz>
parents: 33
diff changeset
   130
	Impl& operator=(const Impl&) = delete;
19
262828ae9682 OOP for Texture
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
   131
};
262828ae9682 OOP for Texture
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
   132
24
98d033d3ef7c xattr: XAttrs class that read/write/list extended attributes
František Kučera <franta-hg@frantovo.cz>
parents: 22
diff changeset
   133
class XAttrs::Impl {
98d033d3ef7c xattr: XAttrs class that read/write/list extended attributes
František Kučera <franta-hg@frantovo.cz>
parents: 22
diff changeset
   134
public:
34
8cf3812a92eb improved Makefile + small fixes
František Kučera <franta-hg@frantovo.cz>
parents: 33
diff changeset
   135
8cf3812a92eb improved Makefile + small fixes
František Kučera <franta-hg@frantovo.cz>
parents: 33
diff changeset
   136
	Impl() {
8cf3812a92eb improved Makefile + small fixes
František Kučera <franta-hg@frantovo.cz>
parents: 33
diff changeset
   137
	}
8cf3812a92eb improved Makefile + small fixes
František Kučera <franta-hg@frantovo.cz>
parents: 33
diff changeset
   138
8cf3812a92eb improved Makefile + small fixes
František Kučera <franta-hg@frantovo.cz>
parents: 33
diff changeset
   139
	virtual ~Impl() {
8cf3812a92eb improved Makefile + small fixes
František Kučera <franta-hg@frantovo.cz>
parents: 33
diff changeset
   140
	}
24
98d033d3ef7c xattr: XAttrs class that read/write/list extended attributes
František Kučera <franta-hg@frantovo.cz>
parents: 22
diff changeset
   141
	std::string nameSpace;
98d033d3ef7c xattr: XAttrs class that read/write/list extended attributes
František Kučera <franta-hg@frantovo.cz>
parents: 22
diff changeset
   142
	std::string fileName;
98d033d3ef7c xattr: XAttrs class that read/write/list extended attributes
František Kučera <franta-hg@frantovo.cz>
parents: 22
diff changeset
   143
	std::vector<Attribute> attributes;
98d033d3ef7c xattr: XAttrs class that read/write/list extended attributes
František Kučera <franta-hg@frantovo.cz>
parents: 22
diff changeset
   144
	bool loaded = false;
98d033d3ef7c xattr: XAttrs class that read/write/list extended attributes
František Kučera <franta-hg@frantovo.cz>
parents: 22
diff changeset
   145
	const XAttrs::Attribute& save(const XAttrs::Attribute& attribute);
98d033d3ef7c xattr: XAttrs class that read/write/list extended attributes
František Kučera <franta-hg@frantovo.cz>
parents: 22
diff changeset
   146
	XAttrs::Attribute& load(XAttrs::Attribute& attribute);
34
8cf3812a92eb improved Makefile + small fixes
František Kučera <franta-hg@frantovo.cz>
parents: 33
diff changeset
   147
8cf3812a92eb improved Makefile + small fixes
František Kučera <franta-hg@frantovo.cz>
parents: 33
diff changeset
   148
private:
8cf3812a92eb improved Makefile + small fixes
František Kučera <franta-hg@frantovo.cz>
parents: 33
diff changeset
   149
	Impl(const Impl&) = delete;
8cf3812a92eb improved Makefile + small fixes
František Kučera <franta-hg@frantovo.cz>
parents: 33
diff changeset
   150
	Impl& operator=(const Impl&) = delete;
24
98d033d3ef7c xattr: XAttrs class that read/write/list extended attributes
František Kučera <franta-hg@frantovo.cz>
parents: 22
diff changeset
   151
};
98d033d3ef7c xattr: XAttrs class that read/write/list extended attributes
František Kučera <franta-hg@frantovo.cz>
parents: 22
diff changeset
   152
98d033d3ef7c xattr: XAttrs class that read/write/list extended attributes
František Kučera <franta-hg@frantovo.cz>
parents: 22
diff changeset
   153
XAttrs::XAttrs(const std::string& fileName, const std::string& nameSpace) :
98d033d3ef7c xattr: XAttrs class that read/write/list extended attributes
František Kučera <franta-hg@frantovo.cz>
parents: 22
diff changeset
   154
impl(std::make_shared<Impl>()) {
98d033d3ef7c xattr: XAttrs class that read/write/list extended attributes
František Kučera <franta-hg@frantovo.cz>
parents: 22
diff changeset
   155
	impl->nameSpace = nameSpace;
19
262828ae9682 OOP for Texture
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
   156
	impl->fileName = fileName;
262828ae9682 OOP for Texture
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
   157
}
262828ae9682 OOP for Texture
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
   158
24
98d033d3ef7c xattr: XAttrs class that read/write/list extended attributes
František Kučera <franta-hg@frantovo.cz>
parents: 22
diff changeset
   159
XAttrs::~XAttrs() {
34
8cf3812a92eb improved Makefile + small fixes
František Kučera <franta-hg@frantovo.cz>
parents: 33
diff changeset
   160
	// Break circular dependency (otherwise we have a memory leak),
8cf3812a92eb improved Makefile + small fixes
František Kučera <franta-hg@frantovo.cz>
parents: 33
diff changeset
   161
	// this collection is not needed anymore:
8cf3812a92eb improved Makefile + small fixes
František Kučera <franta-hg@frantovo.cz>
parents: 33
diff changeset
   162
	impl->attributes.clear();
19
262828ae9682 OOP for Texture
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
   163
}
262828ae9682 OOP for Texture
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
   164
24
98d033d3ef7c xattr: XAttrs class that read/write/list extended attributes
František Kučera <franta-hg@frantovo.cz>
parents: 22
diff changeset
   165
const std::string XAttrs::getFileName() const {
19
262828ae9682 OOP for Texture
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
   166
	return impl->fileName;
262828ae9682 OOP for Texture
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
   167
}
262828ae9682 OOP for Texture
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
   168
24
98d033d3ef7c xattr: XAttrs class that read/write/list extended attributes
František Kučera <franta-hg@frantovo.cz>
parents: 22
diff changeset
   169
size_t XAttrs::size(bool reload) {
98d033d3ef7c xattr: XAttrs class that read/write/list extended attributes
František Kučera <franta-hg@frantovo.cz>
parents: 22
diff changeset
   170
	if (reload || !impl->loaded) {
98d033d3ef7c xattr: XAttrs class that read/write/list extended attributes
František Kučera <franta-hg@frantovo.cz>
parents: 22
diff changeset
   171
		impl->attributes.clear();
98d033d3ef7c xattr: XAttrs class that read/write/list extended attributes
František Kučera <franta-hg@frantovo.cz>
parents: 22
diff changeset
   172
		std::vector<std::string> names = xattrList(impl->fileName);
27
2a156cb51479 xattr: list attribute names without the namespace prefix 'user.'
František Kučera <franta-hg@frantovo.cz>
parents: 24
diff changeset
   173
		const std::string prefix = impl->nameSpace + ".";
24
98d033d3ef7c xattr: XAttrs class that read/write/list extended attributes
František Kučera <franta-hg@frantovo.cz>
parents: 22
diff changeset
   174
		for (const std::string& name : names) {
27
2a156cb51479 xattr: list attribute names without the namespace prefix 'user.'
František Kučera <franta-hg@frantovo.cz>
parents: 24
diff changeset
   175
			if (name.starts_with(prefix)) {
2a156cb51479 xattr: list attribute names without the namespace prefix 'user.'
František Kučera <franta-hg@frantovo.cz>
parents: 24
diff changeset
   176
				Attribute a;
2a156cb51479 xattr: list attribute names without the namespace prefix 'user.'
František Kučera <franta-hg@frantovo.cz>
parents: 24
diff changeset
   177
				a.impl->xattrs = impl;
2a156cb51479 xattr: list attribute names without the namespace prefix 'user.'
František Kučera <franta-hg@frantovo.cz>
parents: 24
diff changeset
   178
				a.impl->name = name.substr(prefix.size());
2a156cb51479 xattr: list attribute names without the namespace prefix 'user.'
František Kučera <franta-hg@frantovo.cz>
parents: 24
diff changeset
   179
				a.impl->value = xattrGet(impl->fileName, name, &a.impl->exists);
2a156cb51479 xattr: list attribute names without the namespace prefix 'user.'
František Kučera <franta-hg@frantovo.cz>
parents: 24
diff changeset
   180
				impl->attributes.push_back(a);
2a156cb51479 xattr: list attribute names without the namespace prefix 'user.'
František Kučera <franta-hg@frantovo.cz>
parents: 24
diff changeset
   181
			}
24
98d033d3ef7c xattr: XAttrs class that read/write/list extended attributes
František Kučera <franta-hg@frantovo.cz>
parents: 22
diff changeset
   182
		}
98d033d3ef7c xattr: XAttrs class that read/write/list extended attributes
František Kučera <franta-hg@frantovo.cz>
parents: 22
diff changeset
   183
		impl->loaded = true;
98d033d3ef7c xattr: XAttrs class that read/write/list extended attributes
František Kučera <franta-hg@frantovo.cz>
parents: 22
diff changeset
   184
	}
98d033d3ef7c xattr: XAttrs class that read/write/list extended attributes
František Kučera <franta-hg@frantovo.cz>
parents: 22
diff changeset
   185
	return impl->attributes.size();
98d033d3ef7c xattr: XAttrs class that read/write/list extended attributes
František Kučera <franta-hg@frantovo.cz>
parents: 22
diff changeset
   186
}
98d033d3ef7c xattr: XAttrs class that read/write/list extended attributes
František Kučera <franta-hg@frantovo.cz>
parents: 22
diff changeset
   187
98d033d3ef7c xattr: XAttrs class that read/write/list extended attributes
František Kučera <franta-hg@frantovo.cz>
parents: 22
diff changeset
   188
XAttrs::Attribute* XAttrs::begin() {
98d033d3ef7c xattr: XAttrs class that read/write/list extended attributes
František Kučera <franta-hg@frantovo.cz>
parents: 22
diff changeset
   189
	size();
98d033d3ef7c xattr: XAttrs class that read/write/list extended attributes
František Kučera <franta-hg@frantovo.cz>
parents: 22
diff changeset
   190
	return &impl->attributes[0];
98d033d3ef7c xattr: XAttrs class that read/write/list extended attributes
František Kučera <franta-hg@frantovo.cz>
parents: 22
diff changeset
   191
}
98d033d3ef7c xattr: XAttrs class that read/write/list extended attributes
František Kučera <franta-hg@frantovo.cz>
parents: 22
diff changeset
   192
98d033d3ef7c xattr: XAttrs class that read/write/list extended attributes
František Kučera <franta-hg@frantovo.cz>
parents: 22
diff changeset
   193
XAttrs::Attribute* XAttrs::end() {
98d033d3ef7c xattr: XAttrs class that read/write/list extended attributes
František Kučera <franta-hg@frantovo.cz>
parents: 22
diff changeset
   194
	size();
98d033d3ef7c xattr: XAttrs class that read/write/list extended attributes
František Kučera <franta-hg@frantovo.cz>
parents: 22
diff changeset
   195
	return &impl->attributes[impl->attributes.size()];
19
262828ae9682 OOP for Texture
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
   196
}
262828ae9682 OOP for Texture
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
   197
24
98d033d3ef7c xattr: XAttrs class that read/write/list extended attributes
František Kučera <franta-hg@frantovo.cz>
parents: 22
diff changeset
   198
const XAttrs::Attribute&
98d033d3ef7c xattr: XAttrs class that read/write/list extended attributes
František Kučera <franta-hg@frantovo.cz>
parents: 22
diff changeset
   199
XAttrs::Impl::save(const XAttrs::Attribute& attribute) {
98d033d3ef7c xattr: XAttrs class that read/write/list extended attributes
František Kučera <franta-hg@frantovo.cz>
parents: 22
diff changeset
   200
	xattrSet(
98d033d3ef7c xattr: XAttrs class that read/write/list extended attributes
František Kučera <franta-hg@frantovo.cz>
parents: 22
diff changeset
   201
			fileName,
98d033d3ef7c xattr: XAttrs class that read/write/list extended attributes
František Kučera <franta-hg@frantovo.cz>
parents: 22
diff changeset
   202
			nameSpace + "." + attribute.impl->name,
98d033d3ef7c xattr: XAttrs class that read/write/list extended attributes
František Kučera <franta-hg@frantovo.cz>
parents: 22
diff changeset
   203
			attribute.impl->value,
98d033d3ef7c xattr: XAttrs class that read/write/list extended attributes
František Kučera <franta-hg@frantovo.cz>
parents: 22
diff changeset
   204
			attribute.impl->exists);
98d033d3ef7c xattr: XAttrs class that read/write/list extended attributes
František Kučera <franta-hg@frantovo.cz>
parents: 22
diff changeset
   205
	loaded &= attribute.impl->exists;
98d033d3ef7c xattr: XAttrs class that read/write/list extended attributes
František Kučera <franta-hg@frantovo.cz>
parents: 22
diff changeset
   206
	return attribute;
19
262828ae9682 OOP for Texture
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
   207
}
262828ae9682 OOP for Texture
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
   208
24
98d033d3ef7c xattr: XAttrs class that read/write/list extended attributes
František Kučera <franta-hg@frantovo.cz>
parents: 22
diff changeset
   209
XAttrs::Attribute&
98d033d3ef7c xattr: XAttrs class that read/write/list extended attributes
František Kučera <franta-hg@frantovo.cz>
parents: 22
diff changeset
   210
XAttrs::Impl::load(XAttrs::Attribute& attribute) {
98d033d3ef7c xattr: XAttrs class that read/write/list extended attributes
František Kučera <franta-hg@frantovo.cz>
parents: 22
diff changeset
   211
	attribute.impl->value = xattrGet(fileName,
98d033d3ef7c xattr: XAttrs class that read/write/list extended attributes
František Kučera <franta-hg@frantovo.cz>
parents: 22
diff changeset
   212
			nameSpace + "." + attribute.impl->name, &attribute.impl->exists);
98d033d3ef7c xattr: XAttrs class that read/write/list extended attributes
František Kučera <franta-hg@frantovo.cz>
parents: 22
diff changeset
   213
	return attribute;
98d033d3ef7c xattr: XAttrs class that read/write/list extended attributes
František Kučera <franta-hg@frantovo.cz>
parents: 22
diff changeset
   214
}
98d033d3ef7c xattr: XAttrs class that read/write/list extended attributes
František Kučera <franta-hg@frantovo.cz>
parents: 22
diff changeset
   215
98d033d3ef7c xattr: XAttrs class that read/write/list extended attributes
František Kučera <franta-hg@frantovo.cz>
parents: 22
diff changeset
   216
XAttrs::Attribute& XAttrs::operator[](std::string name) {
98d033d3ef7c xattr: XAttrs class that read/write/list extended attributes
František Kučera <franta-hg@frantovo.cz>
parents: 22
diff changeset
   217
	for (XAttrs::Attribute& a : impl->attributes) {
98d033d3ef7c xattr: XAttrs class that read/write/list extended attributes
František Kučera <franta-hg@frantovo.cz>
parents: 22
diff changeset
   218
		if (a.getName() == name) return a; // impl->load(a);
98d033d3ef7c xattr: XAttrs class that read/write/list extended attributes
František Kučera <franta-hg@frantovo.cz>
parents: 22
diff changeset
   219
	}
98d033d3ef7c xattr: XAttrs class that read/write/list extended attributes
František Kučera <franta-hg@frantovo.cz>
parents: 22
diff changeset
   220
98d033d3ef7c xattr: XAttrs class that read/write/list extended attributes
František Kučera <franta-hg@frantovo.cz>
parents: 22
diff changeset
   221
	XAttrs::Attribute a;
98d033d3ef7c xattr: XAttrs class that read/write/list extended attributes
František Kučera <franta-hg@frantovo.cz>
parents: 22
diff changeset
   222
	a.impl->xattrs = impl;
98d033d3ef7c xattr: XAttrs class that read/write/list extended attributes
František Kučera <franta-hg@frantovo.cz>
parents: 22
diff changeset
   223
	a.impl->name = name;
98d033d3ef7c xattr: XAttrs class that read/write/list extended attributes
František Kučera <franta-hg@frantovo.cz>
parents: 22
diff changeset
   224
	a.impl->exists = false;
98d033d3ef7c xattr: XAttrs class that read/write/list extended attributes
František Kučera <franta-hg@frantovo.cz>
parents: 22
diff changeset
   225
	// impl->load(a);
98d033d3ef7c xattr: XAttrs class that read/write/list extended attributes
František Kučera <franta-hg@frantovo.cz>
parents: 22
diff changeset
   226
98d033d3ef7c xattr: XAttrs class that read/write/list extended attributes
František Kučera <franta-hg@frantovo.cz>
parents: 22
diff changeset
   227
	impl->attributes.push_back(a);
98d033d3ef7c xattr: XAttrs class that read/write/list extended attributes
František Kučera <franta-hg@frantovo.cz>
parents: 22
diff changeset
   228
	return impl->attributes.back();
19
262828ae9682 OOP for Texture
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
   229
}
262828ae9682 OOP for Texture
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
   230
24
98d033d3ef7c xattr: XAttrs class that read/write/list extended attributes
František Kučera <franta-hg@frantovo.cz>
parents: 22
diff changeset
   231
XAttrs::Attribute& XAttrs::operator[](std::size_t index) {
98d033d3ef7c xattr: XAttrs class that read/write/list extended attributes
František Kučera <franta-hg@frantovo.cz>
parents: 22
diff changeset
   232
	if (impl->attributes.empty()) size();
98d033d3ef7c xattr: XAttrs class that read/write/list extended attributes
František Kučera <franta-hg@frantovo.cz>
parents: 22
diff changeset
   233
	return impl->attributes[index];
98d033d3ef7c xattr: XAttrs class that read/write/list extended attributes
František Kučera <franta-hg@frantovo.cz>
parents: 22
diff changeset
   234
}
98d033d3ef7c xattr: XAttrs class that read/write/list extended attributes
František Kučera <franta-hg@frantovo.cz>
parents: 22
diff changeset
   235
98d033d3ef7c xattr: XAttrs class that read/write/list extended attributes
František Kučera <franta-hg@frantovo.cz>
parents: 22
diff changeset
   236
XAttrs::Attribute::Attribute() : impl(std::make_shared<Impl>()) {
98d033d3ef7c xattr: XAttrs class that read/write/list extended attributes
František Kučera <franta-hg@frantovo.cz>
parents: 22
diff changeset
   237
}
98d033d3ef7c xattr: XAttrs class that read/write/list extended attributes
František Kučera <franta-hg@frantovo.cz>
parents: 22
diff changeset
   238
98d033d3ef7c xattr: XAttrs class that read/write/list extended attributes
František Kučera <franta-hg@frantovo.cz>
parents: 22
diff changeset
   239
XAttrs::Attribute::~Attribute() {
98d033d3ef7c xattr: XAttrs class that read/write/list extended attributes
František Kučera <franta-hg@frantovo.cz>
parents: 22
diff changeset
   240
}
19
262828ae9682 OOP for Texture
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
   241
24
98d033d3ef7c xattr: XAttrs class that read/write/list extended attributes
František Kučera <franta-hg@frantovo.cz>
parents: 22
diff changeset
   242
const std::string XAttrs::Attribute::getName() {
98d033d3ef7c xattr: XAttrs class that read/write/list extended attributes
František Kučera <franta-hg@frantovo.cz>
parents: 22
diff changeset
   243
	return impl->name;
98d033d3ef7c xattr: XAttrs class that read/write/list extended attributes
František Kučera <franta-hg@frantovo.cz>
parents: 22
diff changeset
   244
}
98d033d3ef7c xattr: XAttrs class that read/write/list extended attributes
František Kučera <franta-hg@frantovo.cz>
parents: 22
diff changeset
   245
98d033d3ef7c xattr: XAttrs class that read/write/list extended attributes
František Kučera <franta-hg@frantovo.cz>
parents: 22
diff changeset
   246
const std::string XAttrs::Attribute::getValue(bool reload) {
98d033d3ef7c xattr: XAttrs class that read/write/list extended attributes
František Kučera <franta-hg@frantovo.cz>
parents: 22
diff changeset
   247
	if (reload || !impl->loaded) impl->xattrs->load(*this);
98d033d3ef7c xattr: XAttrs class that read/write/list extended attributes
František Kučera <franta-hg@frantovo.cz>
parents: 22
diff changeset
   248
	return impl->value;
98d033d3ef7c xattr: XAttrs class that read/write/list extended attributes
František Kučera <franta-hg@frantovo.cz>
parents: 22
diff changeset
   249
}
98d033d3ef7c xattr: XAttrs class that read/write/list extended attributes
František Kučera <franta-hg@frantovo.cz>
parents: 22
diff changeset
   250
98d033d3ef7c xattr: XAttrs class that read/write/list extended attributes
František Kučera <franta-hg@frantovo.cz>
parents: 22
diff changeset
   251
bool XAttrs::Attribute::exists(bool reload) {
98d033d3ef7c xattr: XAttrs class that read/write/list extended attributes
František Kučera <franta-hg@frantovo.cz>
parents: 22
diff changeset
   252
	if (reload || !impl->loaded) impl->xattrs->load(*this);
98d033d3ef7c xattr: XAttrs class that read/write/list extended attributes
František Kučera <franta-hg@frantovo.cz>
parents: 22
diff changeset
   253
	return impl->exists;
98d033d3ef7c xattr: XAttrs class that read/write/list extended attributes
František Kučera <franta-hg@frantovo.cz>
parents: 22
diff changeset
   254
}
98d033d3ef7c xattr: XAttrs class that read/write/list extended attributes
František Kučera <franta-hg@frantovo.cz>
parents: 22
diff changeset
   255
98d033d3ef7c xattr: XAttrs class that read/write/list extended attributes
František Kučera <franta-hg@frantovo.cz>
parents: 22
diff changeset
   256
bool XAttrs::Attribute::missing(bool reload) {
98d033d3ef7c xattr: XAttrs class that read/write/list extended attributes
František Kučera <franta-hg@frantovo.cz>
parents: 22
diff changeset
   257
	return !exists(reload);
98d033d3ef7c xattr: XAttrs class that read/write/list extended attributes
František Kučera <franta-hg@frantovo.cz>
parents: 22
diff changeset
   258
}
19
262828ae9682 OOP for Texture
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
   259
24
98d033d3ef7c xattr: XAttrs class that read/write/list extended attributes
František Kučera <franta-hg@frantovo.cz>
parents: 22
diff changeset
   260
XAttrs::Attribute& XAttrs::Attribute::operator=(const std::string& value) {
98d033d3ef7c xattr: XAttrs class that read/write/list extended attributes
František Kučera <franta-hg@frantovo.cz>
parents: 22
diff changeset
   261
	impl->value = value;
98d033d3ef7c xattr: XAttrs class that read/write/list extended attributes
František Kučera <franta-hg@frantovo.cz>
parents: 22
diff changeset
   262
	impl->exists = true;
98d033d3ef7c xattr: XAttrs class that read/write/list extended attributes
František Kučera <franta-hg@frantovo.cz>
parents: 22
diff changeset
   263
	impl->xattrs->save(*this);
98d033d3ef7c xattr: XAttrs class that read/write/list extended attributes
František Kučera <franta-hg@frantovo.cz>
parents: 22
diff changeset
   264
	return *this;
98d033d3ef7c xattr: XAttrs class that read/write/list extended attributes
František Kučera <franta-hg@frantovo.cz>
parents: 22
diff changeset
   265
}
98d033d3ef7c xattr: XAttrs class that read/write/list extended attributes
František Kučera <franta-hg@frantovo.cz>
parents: 22
diff changeset
   266
98d033d3ef7c xattr: XAttrs class that read/write/list extended attributes
František Kučera <franta-hg@frantovo.cz>
parents: 22
diff changeset
   267
XAttrs::Attribute& XAttrs::Attribute::
98d033d3ef7c xattr: XAttrs class that read/write/list extended attributes
František Kučera <franta-hg@frantovo.cz>
parents: 22
diff changeset
   268
		operator=(const XAttrs::Attribute& value) {
98d033d3ef7c xattr: XAttrs class that read/write/list extended attributes
František Kučera <franta-hg@frantovo.cz>
parents: 22
diff changeset
   269
	impl->value = value.impl->value;
98d033d3ef7c xattr: XAttrs class that read/write/list extended attributes
František Kučera <franta-hg@frantovo.cz>
parents: 22
diff changeset
   270
	impl->exists = value.impl->exists;
98d033d3ef7c xattr: XAttrs class that read/write/list extended attributes
František Kučera <franta-hg@frantovo.cz>
parents: 22
diff changeset
   271
	impl->xattrs->save(*this);
98d033d3ef7c xattr: XAttrs class that read/write/list extended attributes
František Kučera <franta-hg@frantovo.cz>
parents: 22
diff changeset
   272
	return *this;
19
262828ae9682 OOP for Texture
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
   273
}
24
98d033d3ef7c xattr: XAttrs class that read/write/list extended attributes
František Kučera <franta-hg@frantovo.cz>
parents: 22
diff changeset
   274
98d033d3ef7c xattr: XAttrs class that read/write/list extended attributes
František Kučera <franta-hg@frantovo.cz>
parents: 22
diff changeset
   275
XAttrs::Attribute::operator std::string() {
98d033d3ef7c xattr: XAttrs class that read/write/list extended attributes
František Kučera <franta-hg@frantovo.cz>
parents: 22
diff changeset
   276
	impl->xattrs->load(*this);
98d033d3ef7c xattr: XAttrs class that read/write/list extended attributes
František Kučera <franta-hg@frantovo.cz>
parents: 22
diff changeset
   277
	return impl->value;
98d033d3ef7c xattr: XAttrs class that read/write/list extended attributes
František Kučera <franta-hg@frantovo.cz>
parents: 22
diff changeset
   278
}
98d033d3ef7c xattr: XAttrs class that read/write/list extended attributes
František Kučera <franta-hg@frantovo.cz>
parents: 22
diff changeset
   279
98d033d3ef7c xattr: XAttrs class that read/write/list extended attributes
František Kučera <franta-hg@frantovo.cz>
parents: 22
diff changeset
   280
std::ostream& operator<<(std::ostream& s, XAttrs::Attribute& a) {
98d033d3ef7c xattr: XAttrs class that read/write/list extended attributes
František Kučera <franta-hg@frantovo.cz>
parents: 22
diff changeset
   281
	s << a.getValue().c_str();
98d033d3ef7c xattr: XAttrs class that read/write/list extended attributes
František Kučera <franta-hg@frantovo.cz>
parents: 22
diff changeset
   282
	return s;
98d033d3ef7c xattr: XAttrs class that read/write/list extended attributes
František Kučera <franta-hg@frantovo.cz>
parents: 22
diff changeset
   283
}
98d033d3ef7c xattr: XAttrs class that read/write/list extended attributes
František Kučera <franta-hg@frantovo.cz>
parents: 22
diff changeset
   284
98d033d3ef7c xattr: XAttrs class that read/write/list extended attributes
František Kučera <franta-hg@frantovo.cz>
parents: 22
diff changeset
   285
std::ostream& operator>>(XAttrs::Attribute& a, std::ostream& s) {
98d033d3ef7c xattr: XAttrs class that read/write/list extended attributes
František Kučera <franta-hg@frantovo.cz>
parents: 22
diff changeset
   286
	s << a.getValue().c_str();
98d033d3ef7c xattr: XAttrs class that read/write/list extended attributes
František Kučera <franta-hg@frantovo.cz>
parents: 22
diff changeset
   287
	return s;
98d033d3ef7c xattr: XAttrs class that read/write/list extended attributes
František Kučera <franta-hg@frantovo.cz>
parents: 22
diff changeset
   288
}
98d033d3ef7c xattr: XAttrs class that read/write/list extended attributes
František Kučera <franta-hg@frantovo.cz>
parents: 22
diff changeset
   289
98d033d3ef7c xattr: XAttrs class that read/write/list extended attributes
František Kučera <franta-hg@frantovo.cz>
parents: 22
diff changeset
   290
XAttrs::Null::Null() {
98d033d3ef7c xattr: XAttrs class that read/write/list extended attributes
František Kučera <franta-hg@frantovo.cz>
parents: 22
diff changeset
   291
	impl->exists = false;
98d033d3ef7c xattr: XAttrs class that read/write/list extended attributes
František Kučera <franta-hg@frantovo.cz>
parents: 22
diff changeset
   292
}