Laxkit
0.0.7.1
Main Page
Related Pages
Modules
Namespaces
Classes
Files
File List
lax
attributes.h
1
//
2
//
3
// The Laxkit, a windowing toolkit
4
// Please consult http://laxkit.sourceforge.net about where to send any
5
// correspondence about this software.
6
//
7
// This library is free software; you can redistribute it and/or
8
// modify it under the terms of the GNU Library General Public
9
// License as published by the Free Software Foundation; either
10
// version 2 of the License, or (at your option) any later version.
11
//
12
// This library is distributed in the hope that it will be useful,
13
// but WITHOUT ANY WARRANTY; without even the implied warranty of
14
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15
// Library General Public License for more details.
16
//
17
// You should have received a copy of the GNU Library General Public
18
// License along with this library; if not, write to the Free Software
19
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20
//
21
// Copyright (C) 2004-2013 by Tom Lechner
22
//
23
#ifndef _LAX_ATTRIBUTES_H
24
#define _LAX_ATTRIBUTES_H
25
26
#include <lax/screencolor.h>
27
#include <lax/lists.h>
28
#include <lax/vectors.h>
29
#include <cstdio>
30
31
namespace
LaxFiles {
32
33
//---------------------------------- class Attribute ---------------------------------
34
35
class
Attribute
{
36
public
:
37
char
*name;
38
char
*atttype;
// string, alias to this name, use contents of file "value" as string
39
Laxkit::PtrStack<Attribute>
attributes;
40
41
char
*value;
42
unsigned
int
flags;
43
44
Attribute
() { name=value=atttype=NULL; flags=0; }
45
Attribute
(
const
char
*nn,
const
char
*nval,
const
char
*nt=NULL);
46
virtual
~
Attribute
();
47
virtual
Attribute
*
duplicate
();
48
virtual
Attribute
*
find
(
const
char
*fromname,
int
*i_ret=NULL);
49
virtual
const
char
*
findValue
(
const
char
*fromname,
int
*i_ret=NULL);
50
virtual
double
findDouble
(
const
char
*fromname,
int
*i_ret=NULL);
51
virtual
Attribute
*
pushSubAtt
(
const
char
*nname,
const
char
*nvalue=NULL);
52
virtual
int
push
(
Attribute
*att,
int
where);
53
virtual
int
push
(
const
char
*nname);
54
virtual
int
push
(
const
char
*nname,
const
char
*nval,
int
where=-1);
55
virtual
int
push
(
const
char
*nname,
long
nval,
int
where=-1);
56
virtual
int
push
(
const
char
*nname,
int
nval,
int
where=-1);
57
virtual
int
push
(
const
char
*nname,
double
nval,
int
where=-1);
58
virtual
int
remove
(
int
index);
59
virtual
void
clear
();
60
virtual
int
dump_in
(
const
char
*filename,
Attribute
*defines=NULL);
61
virtual
int
dump_in
(FILE *f,
int
Indent,
Attribute
**stopatsub=NULL);
62
virtual
char
*
dump_in_indented
(FILE *f,
int
indent);
63
virtual
char
*
dump_in_until
(FILE *f,
const
char
*str,
int
indent=0);
64
virtual
void
dump_out
(FILE *f,
int
Indent);
65
virtual
void
dump_out_full
(FILE *f,
int
Indent);
66
};
67
68
69
//---------------------------------- Dump helper functions ---------------------------------
70
void
dump_out_value
(FILE *f,
int
indent,
const
char
*value,
int
noquotes=0);
71
void
dump_out_escaped
(FILE *f,
const
char
*str,
int
n);
72
void
dump_out_indented
(FILE *f,
int
indent,
const
char
*str);
73
74
void
skip_to_next_attribute
(FILE *f,
int
indent);
75
76
//---------------------------------- Value Conversion Routines -----------------------------------
77
int
ByteSizeAttribute
(
const
char
*s,
long
*ll,
char
towhat);
78
double
*
TransformAttribute
(
const
char
*v,
double
*m,
char
**endptr=NULL);
79
int
DoubleAttribute
(
const
char
*v,
double
*d,
char
**endptr=NULL);
80
int
DoubleListAttribute
(
const
char
*v,
double
*d,
int
maxn,
char
**endptr=NULL);
81
int
DoubleListAttribute
(
const
char
*v,
double
**d,
int
*n_ret);
82
int
FloatAttribute
(
const
char
*v,
float
*f,
char
**endptr=NULL);
83
int
IntAttribute
(
const
char
*v,
int
*i,
char
**endptr=NULL);
84
int
UIntAttribute
(
const
char
*v,
unsigned
int
*i,
char
**endptr=NULL);
85
int
LongAttribute
(
const
char
*v,
long
*l,
char
**endptr=NULL);
86
int
ULongAttribute
(
const
char
*v,
unsigned
long
*l,
char
**endptr=NULL);
87
int
IntListAttribute
(
const
char
*v,
int
*i,
int
maxn,
char
**endptr=NULL);
88
int
IntListAttribute
(
const
char
*v,
int
**i,
int
*n_ret,
char
**endptr=NULL);
89
char
*
QuotedAttribute
(
const
char
*v,
char
**endptr=NULL);
90
char
*
WholeQuotedAttribute
(
const
char
*v);
91
int
BooleanAttribute
(
const
char
*v);
92
int
NameValueAttribute
(
const
char
*str,
char
**name,
char
**value,
char
**end_ptr,
93
char
assign=
'='
,
char
delim=0,
const
char
*stopat=NULL);
94
Attribute
*
NameValueToAttribute
(
Attribute
*att,
const
char
*str,
char
assign,
char
delim);
95
int
SimpleColorAttribute
(
const
char
*v,
unsigned
long
*color_ret);
96
int
HexColorAttributeRGB
(
const
char
*v,
unsigned
long
*l,
char
**endptr);
97
int
HexColorAttributeRGB
(
const
char
*v,
Laxkit::ScreenColor
*color,
char
**endptr);
98
int
FlatvectorAttribute
(
const
char
*v,
flatvector
*l,
char
**endptr=NULL);
99
100
101
//---------------------------------- XML Conversion helpers -------------------------------
102
int
AttributeToXMLFile
(FILE *f,
Attribute
*att,
int
indent);
103
int
SubAttributesToXMLFile
(FILE *f,
Attribute
*att,
int
indent);
104
char
*
AttributeToXML
(
Attribute
*att,
char
*&appendtothis,
char
**error_ret);
105
Attribute
*
XMLFileToAttribute
(
Attribute
*att,
const
char
*file,
const
char
**stand_alone_tag_list);
106
Attribute
*
XMLChunkToAttribute
(
Attribute
*att,FILE *f,
const
char
**stand_alone_tag_list);
107
Attribute
*
XMLChunkToAttribute
(
Attribute
*att,
const
char
*buf,
long
n,
108
long
*C,
const
char
*until,
const
char
**stand_alone_tag_list);
109
110
111
//---------------------------------- CSS Conversion helpers -------------------------------
112
int
AttributeToCSSFile
(FILE *f,
Attribute
*att,
int
indent);
113
char
*AttributeToCSS(
Attribute
*att,
char
**appendtothis,
char
**error_ret);
114
Attribute
*
CSSFileToAttribute
(
const
char
*cssfile,
Attribute
*att);
115
Attribute
*CSSToAttribute (
const
char
*css,
Attribute
*att);
116
117
118
}
//namespace LaxFiles
119
120
#endif
121
Mon Feb 17 2014 11:52:56, Laxkit