XAttrs.h
branchv_0
changeset 24 98d033d3ef7c
parent 19 262828ae9682
child 29 dc3c102e1264
equal deleted inserted replaced
23:42341f66de52 24:98d033d3ef7c
       
     1 /**
       
     2  * ShaderShark
       
     3  * Copyright © 2023 František Kučera (Frantovo.cz, GlobalCode.info)
       
     4  *
       
     5  * This program is free software: you can redistribute it and/or modify
       
     6  * it under the terms of the GNU General Public License as published by
       
     7  * the Free Software Foundation, version 3 of the License.
       
     8  *
       
     9  * This program is distributed in the hope that it will be useful,
       
    10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
       
    11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
       
    12  * GNU General Public License for more details.
       
    13  *
       
    14  * You should have received a copy of the GNU General Public License
       
    15  * along with this program. If not, see <http://www.gnu.org/licenses/>.
       
    16  */
       
    17 
       
    18 #pragma once
       
    19 
       
    20 #include <memory>
       
    21 #include <string>
       
    22 
       
    23 #include "Buffer.h"
       
    24 
       
    25 class XAttrs {
       
    26 public:
       
    27 
       
    28 	class Null;
       
    29 
       
    30 	class Attribute {
       
    31 	public:
       
    32 		virtual ~Attribute();
       
    33 		const std::string getName();
       
    34 		const std::string getValue(bool reload = false);
       
    35 		bool exists(bool reload = false);
       
    36 		bool missing(bool reload = false);
       
    37 		Attribute& operator=(const std::string& value);
       
    38 		Attribute& operator=(const Attribute& value);
       
    39 		operator std::string();
       
    40 		friend std::ostream& operator<<(std::ostream& s, Attribute& a);
       
    41 		friend std::ostream& operator>>(Attribute& a, std::ostream& s);
       
    42 	private:
       
    43 		class Impl;
       
    44 		std::shared_ptr<Impl> impl;
       
    45 		Attribute();
       
    46 		friend XAttrs;
       
    47 		friend Null;
       
    48 	};
       
    49 
       
    50 	class Null : public Attribute {
       
    51 	public:
       
    52 		Null();
       
    53 	};
       
    54 
       
    55 	XAttrs(const std::string& fileName, const std::string& nameSpace = "user");
       
    56 	virtual ~XAttrs();
       
    57 	const std::string getFileName() const;
       
    58 	Attribute& operator[](std::string name);
       
    59 	Attribute& operator[](std::size_t index);
       
    60 	size_t size(bool reload = false);
       
    61 	Attribute* begin();
       
    62 	Attribute* end();
       
    63 private:
       
    64 	class Impl;
       
    65 	std::shared_ptr<Impl> impl;
       
    66 	friend Attribute;
       
    67 };