Support unrar64.dll
[xy_vsfilter.git] / src / subtitles / libssf / Node.h
blobaf48390f1e4a443dd9db4482ca99c82862746682
1 /*
2 * Copyright (C) 2003-2006 Gabest
3 * http://www.gabest.org
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; either version 2, or (at your option)
8 * any later version.
9 *
10 * This Program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with GNU Make; see the file COPYING. If not, write to
17 * the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
18 * http://www.gnu.org/copyleft/gpl.html
22 #pragma once
24 #include "Stream.h"
25 #include "StringMap.h"
27 namespace ssf
29 class Definition;
30 class NodeFactory;
32 enum NodePriority {PLow, PNormal, PHigh};
34 class Node
36 protected:
37 NodeFactory* m_pnf;
39 public:
40 Node* m_parent;
41 CAtlList<Node*> m_nodes;
42 StringMapW<Node*> m_name2node;
43 CStringW m_type, m_name;
44 NodePriority m_priority;
45 bool m_predefined;
47 Node(NodeFactory* pnf, CStringW name);
48 virtual ~Node() {}
50 bool IsNameUnknown();
51 bool IsTypeUnknown();
52 bool IsType(CStringW type);
54 virtual void AddTail(Node* pNode);
55 virtual void GetChildDefs(CAtlList<Definition*>& l, LPCWSTR type = NULL, bool fFirst = true);
56 virtual void Dump(OutputStream& s, int level = 0, bool fLast = false) = 0;
59 class Reference : public Node
61 public:
62 Reference(NodeFactory* pnf, CStringW name);
63 virtual ~Reference();
65 void GetChildDefs(CAtlList<Definition*>& l, LPCWSTR type = NULL, bool fFirst = true);
66 void Dump(OutputStream& s, int level = 0, bool fLast = false);
69 class Definition : public Node
71 public:
72 template<typename T> struct Number {T value; int sign; CStringW unit;};
73 struct Time {Number<float> start, stop;};
75 enum status_t {node, string, number, boolean, block};
77 private:
78 status_t m_status;
79 bool m_autotype;
80 CStringW m_value, m_unit;
81 Number<float> m_num;
82 CStringW m_num_string;
84 StringMapW<Definition*> m_type2def;
85 void RemoveFromCache(LPCWSTR type = NULL);
87 template<typename T>
88 void GetAsNumber(Number<T>& n, StringMapW<T>* n2n = NULL);
90 public:
91 Definition(NodeFactory* pnf, CStringW name);
92 virtual ~Definition();
94 bool IsVisible(Definition* pDef);
96 void AddTail(Node* pNode);
97 void Dump(OutputStream& s, int level = 0, bool fLast = false);
99 Definition& operator[] (LPCWSTR type);
101 bool IsValue(status_t s = (status_t)0);
103 void SetAsValue(status_t s, CStringW v, CStringW u = L"");
104 void SetAsNumber(CStringW v, CStringW u = L"");
106 void GetAsString(CStringW& str);
107 void GetAsNumber(Number<int>& n, StringMapW<int>* n2n = NULL);
108 void GetAsNumber(Number<DWORD>& n, StringMapW<DWORD>* n2n = NULL);
109 void GetAsNumber(Number<float>& n, StringMapW<float>* n2n = NULL);
110 template<typename T>
111 void GetAsNumber(T& t, StringMapW<T>* n2n = NULL) {Number<T> n; GetAsNumber(n, n2n); t = n.value;}
112 void GetAsBoolean(bool& b);
113 bool GetAsTime(Time& t, StringMapW<float>& offset, StringMapW<float>* n2n = NULL, int default_id = 0);
115 operator LPCWSTR();
116 operator float();
117 operator bool();
119 Definition* SetChildAsValue(CStringW path, status_t s, CStringW v, CStringW u = L"");
120 Definition* SetChildAsNumber(CStringW path, CStringW v, CStringW u = L"");