1 // Copyright (c) 2005, Rodrigo Braz Monteiro
2 // All rights reserved.
3 //
4 // Redistribution and use in source and binary forms, with or without
5 // modification, are permitted provided that the following conditions are met:
6 //
7 //   * Redistributions of source code must retain the above copyright notice,
8 //     this list of conditions and the following disclaimer.
9 //   * Redistributions in binary form must reproduce the above copyright notice,
10 //     this list of conditions and the following disclaimer in the documentation
11 //     and/or other materials provided with the distribution.
12 //   * Neither the name of the Aegisub Group nor the names of its contributors
13 //     may be used to endorse or promote products derived from this software
14 //     without specific prior written permission.
15 //
16 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
17 // AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18 // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
19 // ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
20 // LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
21 // CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
22 // SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
23 // INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
24 // CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
25 // ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
26 // POSSIBILITY OF SUCH DAMAGE.
27 //
28 // Aegisub Project http://www.aegisub.org/
29 
30 /// @file ass_override.h
31 /// @see ass_override.cpp
32 /// @ingroup subs_storage
33 ///
34 
35 #include <memory>
36 #include <vector>
37 
38 class AssDialogueBlockOverride;
39 
40 /// Type of parameter
41 enum class AssParameterClass {
42 	NORMAL,
43 	ABSOLUTE_SIZE,
44 	ABSOLUTE_POS_X,
45 	ABSOLUTE_POS_Y,
46 	RELATIVE_SIZE_X,
47 	RELATIVE_SIZE_Y,
48 	RELATIVE_TIME_START,
49 	RELATIVE_TIME_END,
50 	KARAOKE,
51 	DRAWING,
52 	ALPHA,
53 	COLOR
54 };
55 
56 enum class VariableDataType {
57 	INT,
58 	FLOAT,
59 	TEXT,
60 	BOOL,
61 	BLOCK
62 };
63 
64 /// A single parameter to an override tag
65 class AssOverrideParameter {
66 	std::string value;
67 	mutable std::unique_ptr<AssDialogueBlockOverride> block;
68 	VariableDataType type;
69 
70 public:
71 	AssOverrideParameter(VariableDataType type, AssParameterClass classification);
72 #ifdef _MSC_VER
73 	AssOverrideParameter(AssOverrideParameter&&);
74 	AssOverrideParameter& operator=(AssOverrideParameter&&);
75 #else
76 	AssOverrideParameter(AssOverrideParameter&&) = default;
77 	AssOverrideParameter& operator=(AssOverrideParameter&&) = default;
78 #endif
79 	~AssOverrideParameter();
80 
81 	/// Type of parameter
82 	AssParameterClass classification;
83 
84 	/// Is this parameter actually present?
85 	bool omitted = true;
86 
GetType()87 	VariableDataType GetType() const { return type; }
88 	template<class T> void Set(T param);
89 	template<class T> T Get() const;
Get(T def)90 	template<class T> T Get(T def) const {
91 		return !omitted ? Get<T>() : def;
92 	}
93 };
94 
95 class AssOverrideTag {
96 	bool valid = false;
97 
98 public:
99 	AssOverrideTag() = default;
100 	AssOverrideTag(std::string const& text);
101 #ifdef _MSC_VER
102 	AssOverrideTag(AssOverrideTag&&);
103 	AssOverrideTag& operator=(AssOverrideTag&&);
104 #else
105 	AssOverrideTag(AssOverrideTag&&) = default;
106 	AssOverrideTag& operator=(AssOverrideTag&&) = default;
107 #endif
108 
109 	std::string Name;
110 	std::vector<AssOverrideParameter> Params;
111 
IsValid()112 	bool IsValid() const { return valid; }
113 	void Clear();
114 	void SetText(const std::string &text);
115 	operator std::string() const;
116 };
117