yast2-core
Xmlcode.h
Go to the documentation of this file.
1 /*---------------------------------------------------------------------\
2 | |
3 | __ __ ____ _____ ____ |
4 | \ \ / /_ _/ ___|_ _|___ \ |
5 | \ V / _` \___ \ | | __) | |
6 | | | (_| |___) || | / __/ |
7 | |_|\__,_|____/ |_| |_____| |
8 | |
9 | core system |
10 | (C) SuSE GmbH |
11 \----------------------------------------------------------------------/
12 
13  File: Xmlcode.h
14 
15  Primitive xmlcode I/O functions.
16  Acts as a namespace wrapper.
17 
18  Author: Klaus Kaempf <kkaempf@suse.de>
19  Maintainer: Klaus Kaempf <kkaempf@suse.de>
20 
21 /-*/
22 // -*- c++ -*-
23 
24 #ifndef Xmlcode_h
25 #define Xmlcode_h
26 
27 #include "ycp/YCPValue.h"
28 #include "ycp/YCode.h"
29 #include "ycp/YStatement.h"
30 #include "ycp/YBlock.h"
31 #include "ycp/Type.h"
32 
33 class Y2Namespace;
34 
35 #include <iosfwd>
36 #include <string>
37 #include <map>
38 
39 #include <fstream>
40 
42 class xmlcodeistream : public std::ifstream
43 {
45  public:
46  xmlcodeistream (string filename);
47  bool isVersion (int major, int minor, int revision);
48  bool isVersionAtMost (int major, int minor, int revision);
49 
50  int major () const { return m_major; }
51  int minor () const { return m_minor; }
52  int release () const { return m_release; }
53 };
54 
56 class Xmlcode {
60 
64  bool with_xrefs;
65  };
67  static map<string, YBlockPtr>* m_xmlcodeCache;
68 
69  public:
71  class Invalid {};
72 
73  static string spaces( int count );
74 
75  static string xmlify( const string & s );
76 
77  // bytepointer I/O
78  static std::ostream & writeBytep (std::ostream & streamref, const unsigned char * bytep, unsigned int len);
79  static unsigned char * readBytep (xmlcodeistream & streamref);
80 
81  // Type I/O
82  static std::ostream & writeType (std::ostream & str, constTypePtr type);
83  static TypePtr readType (xmlcodeistream & str);
84 
85  // ycodelist_t * I/O
86  static std::ostream & writeYCodelist (std::ostream & str, const ycodelist_t *codelist);
87  static bool readYCodelist (xmlcodeistream & str, ycodelist_t **anchor);
88 
89  //-----------------------------------------------------------
90  // block nesting handling
91  //
92  static void namespaceInit ();
93  // retrieve ID (nesting level) for namespace
94  static int namespaceId (const Y2Namespace *name_space);
95  // retrieve namespace for ID
96  static const Y2Namespace *namespacePtr (int namespace_id);
97 
98  // push given namespace to id stack, return new id, -1 on error
99  static int pushNamespace (const Y2Namespace *name_space, bool with_xrefs = false);
100 
101  // pop given namespace from id stack, return namespace id, -1 on error
102  static int popNamespace (const Y2Namespace *name_space);
103 
104  // pop all from id stack until given namespace is reached and popped too
105  static void popUptoNamespace (const Y2Namespace *name_space);
106 
107  // reset current namespace stack to 'empty' for module loading
108  // returns a tare id needed later
109  static int tareStack ();
110  static void untareStack (int tare_id);
111 
112  //-----------------------------------------------------------
113  // SymbolEntry pointer (!) handling
114  // the SymbolEntries itself are 'owned' by Y2Namespace (YBlock in YCP) and referenced via pointers
115  // to SymbolEntry. These functions handle stream I/O for SymbolEntry pointers.
116  static std::ostream &writeEntry (std::ostream & str, const SymbolEntryPtr entry);
117  static SymbolEntryPtr readEntry (xmlcodeistream & str);
118 
119  //-----------------------------------------------------------
120  // YCode read.
121  // Must be implemented outside of YCode since we have derived classes to allocate...
122  // see YCode for write
123  static YCodePtr readCode (xmlcodeistream & str);
124 
125  // File I/O
126  // reading and writing complete files is done via separate functions
127  // which add/check a 'magic value' header denoting "YCode" and its version.
128 
129  // read YCode from file in Module path, return YBlock (NULL in case of error)
130  static YBlockPtr readModule (const string & mname);
131 
132  // read YCode from file, return YCode (YError in case of failure)
133  static YCodePtr readFile (const string & filename);
134 
135  // write YCode to file, return true on success (check errno for errors)
136  static bool writeFile (const YCodePtr code, const string & filename);
137 };
138 
139 #endif // Xmlcode_h
Definition: Xmlcode.h:71
#define str
Definition: scanner.cc:1003
bool isVersion(int major, int minor, int revision)
Definition: Xmlcode.cc:115
int minor() const
Definition: Xmlcode.h:51
references to namespaces
Definition: Xmlcode.h:62
const Y2Namespace * name_space
Definition: Xmlcode.h:63
int m_minor
Definition: Xmlcode.h:44
static int m_namespace_tare_level
Definition: Xmlcode.h:59
Definition: YCode.h:58
int m_release
Definition: Xmlcode.h:44
bool isVersionAtMost(int major, int minor, int revision)
Definition: Xmlcode.cc:122
int release() const
Definition: Xmlcode.h:52
static int m_namespace_nesting_array_size
Definition: Xmlcode.h:58
int major() const
Definition: Xmlcode.h:50
Definition: Y2Namespace.h:43
static namespaceentry_t * m_namespace_nesting_array
Definition: Xmlcode.h:66
xmlcodeistream(string filename)
Definition: Xmlcode.cc:87
*.ybc I/O
Definition: Xmlcode.h:56
An istream that remembers some data about the xmlcode.
Definition: Xmlcode.h:42
bool with_xrefs
external references... ???
Definition: Xmlcode.h:64
static int m_namespace_nesting_level
Definition: Xmlcode.h:57
static map< string, YBlockPtr > * m_xmlcodeCache
Definition: Xmlcode.h:67
int m_major
Definition: Xmlcode.h:44

Generated on a sunny day for yast2-core by doxygen 1.8.11