Skip to content

Commit 05e797e

Browse files
author
Vyacheslav Brover
committed
Data::load(,headerP,,)
1 parent aa1b169 commit 05e797e

File tree

7 files changed

+36
-25
lines changed

7 files changed

+36
-25
lines changed

xml/xml.cpp

Lines changed: 18 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -412,25 +412,29 @@ void Schema::setFlatColumns (const Schema* curTable,
412412

413413
// Data
414414

415-
Data::Data (Names &names_arg,
415+
Data::Data (bool headerP,
416+
Names &names_arg,
416417
TokenInput &ti,
417418
VectorOwn<Data> &markupDeclarations)
418419
: names (names_arg)
419420
, binary (false)
420421
, attribute (false)
421422
{
422-
ti. get ('<');
423-
ti. get ('?');
424-
ti. get ("xml");
425-
for (;;)
423+
if (headerP)
426424
{
427-
const Token t (ti. get ());
428-
if (t. isDelimiter ('>'))
429-
break;
430-
if (t. empty ())
431-
throw runtime_error ("XML header is not finished");
425+
ti. get ('<');
426+
ti. get ('?');
427+
ti. get ("xml");
428+
for (;;)
429+
{
430+
const Token t (ti. get ());
431+
if (t. isDelimiter ('>'))
432+
break;
433+
if (t. empty ())
434+
throw runtime_error ("XML header is not finished");
435+
}
432436
}
433-
437+
434438
for (;;)
435439
{
436440
readInput (ti);
@@ -675,7 +679,8 @@ Data::Data (const Names &names_arg,
675679

676680

677681

678-
Data* Data::load (Names &names,
682+
Data* Data::load (bool headerP,
683+
Names &names,
679684
const string &fName,
680685
VectorOwn<Data> &markupDeclarations)
681686
{
@@ -685,7 +690,7 @@ Data* Data::load (Names &names,
685690
try
686691
{
687692
Unverbose unv;
688-
f. reset (new Xml_sp::Data (names, ti, markupDeclarations));
693+
f. reset (new Xml_sp::Data (headerP, names, ti, markupDeclarations));
689694
}
690695
catch (const TextPos::Error &e)
691696
{ throw e; }

xml/xml.hpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -200,7 +200,8 @@ struct Data : VirtNamed
200200

201201

202202
private:
203-
Data (Names &names_arg,
203+
Data (bool headerP,
204+
Names &names_arg,
204205
TokenInput &tin,
205206
VectorOwn<Data> &markupDeclarations);
206207
// Text
@@ -236,7 +237,8 @@ struct Data : VirtNamed
236237
string &name);
237238
// Update: name
238239
public:
239-
static Data* load (Names &names,
240+
static Data* load (bool headerP,
241+
Names &names,
240242
const string &fName,
241243
VectorOwn<Data> &markupDeclarations);
242244
// Text XML

xml/xml2schema.cpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,13 +46,14 @@ namespace
4646
{
4747

4848

49-
struct ThisApplication : Application
49+
struct ThisApplication final : Application
5050
{
5151
ThisApplication ()
5252
: Application ("Analyze an XML file and print the derived schema")
5353
{
5454
version = VERSION;
5555
addPositional ("xml", "XML file");
56+
addFlag ("no_xml_header", "XML file has no header");
5657
addKey ("print", "Output XML file");
5758
addFlag ("store_values", "Store all field values in schema");
5859
}
@@ -62,13 +63,14 @@ struct ThisApplication : Application
6263
void body () const final
6364
{
6465
const string xmlFName = getArg ("xml");
66+
const bool headerP = ! getFlag ("no_xml_header");
6567
const string printFName = getArg ("print");
6668
const bool storeValues = getFlag ("store_values");
6769

6870

6971
Names names (10000); // PAR
7072
VectorOwn<Xml_sp::Data> markupDeclarations;
71-
unique_ptr<const Xml_sp::Data> xml (Xml_sp::Data::load (names, xmlFName, markupDeclarations));
73+
unique_ptr<const Xml_sp::Data> xml (Xml_sp::Data::load (headerP, names, xmlFName, markupDeclarations));
7274
xml->qc ();
7375

7476
if (! printFName. empty ())

xml/xml_find.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ namespace
4646
{
4747

4848

49-
struct ThisApplication : Application
49+
struct ThisApplication final : Application
5050
{
5151
ThisApplication ()
5252
: Application ("Find an XML context matching query and print values as a .tsv-file")
@@ -75,11 +75,11 @@ Text of query unifying with \"<\" variable_tag \">\" column_name \"</\" variable
7575
Names names (10000); // PAR
7676

7777
VectorOwn<Xml_sp::Data> targetMarkupDeclarations;
78-
unique_ptr<const Xml_sp::Data> target (Xml_sp::Data::load (names, targetFName, targetMarkupDeclarations));
78+
unique_ptr<const Xml_sp::Data> target (Xml_sp::Data::load (true/*PAR*/, names, targetFName, targetMarkupDeclarations));
7979
target->qc ();
8080

8181
VectorOwn<Xml_sp::Data> queryMarkupDeclarations;
82-
unique_ptr<const Xml_sp::Data> query (Xml_sp::Data::load (names, queryFName, queryMarkupDeclarations));
82+
unique_ptr<const Xml_sp::Data> query (Xml_sp::Data::load (true /*??*/, names, queryFName, queryMarkupDeclarations));
8383
query->qc ();
8484
if (verbose ())
8585
{

xml/xml_schema2flat.cpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ namespace
4646
{
4747

4848

49-
struct ThisApplication : Application
49+
struct ThisApplication final : Application
5050
{
5151
ThisApplication ()
5252
: Application ("Generate tab-delimited files for SQL bulk insert from XML files and their XML schema")
@@ -56,6 +56,7 @@ struct ThisApplication : Application
5656
addPositional ("xml_num", "XML file number");
5757
addPositional ("schema", "XML schema file");
5858
addPositional ("out_dir", "Directory for output tab-delimited files");
59+
addFlag ("no_xml_header", "XML file has no header");
5960
}
6061

6162

@@ -66,6 +67,7 @@ struct ThisApplication : Application
6667
const size_t xml_num = str2<size_t> (getArg ("xml_num"));
6768
const string schemaFName = getArg ("schema");
6869
string dirName = getArg ("out_dir");
70+
const bool headerP = ! getFlag ("no_xml_header");
6971

7072
if (! isDirName (dirName))
7173
dirName += '/';
@@ -78,7 +80,7 @@ struct ThisApplication : Application
7880
Names names (10000); // PAR
7981
VectorOwn<Xml_sp::Data> markupDeclarations;
8082
#if 1
81-
unique_ptr<const Xml_sp::Data> xml (Xml_sp::Data::load (names, xmlFName, markupDeclarations));
83+
unique_ptr<const Xml_sp::Data> xml (Xml_sp::Data::load (headerP, names, xmlFName, markupDeclarations));
8284
#else
8385
unique_ptr<const Xml_sp::Data> xml;
8486
{

xml/xml_txt2bin.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ namespace
4646
{
4747

4848

49-
struct ThisApplication : Application
49+
struct ThisApplication final : Application
5050
{
5151
ThisApplication ()
5252
: Application ("Convert text XML to binary XML")
@@ -70,7 +70,7 @@ struct ThisApplication : Application
7070
Names names (10000); // PAR
7171

7272
VectorOwn<Xml_sp::Data> targetMarkupDeclarations;
73-
unique_ptr<const Xml_sp::Data> in (Xml_sp::Data::load (names, fromFName, targetMarkupDeclarations));
73+
unique_ptr<const Xml_sp::Data> in (Xml_sp::Data::load (true /*PAR*/, names, fromFName, targetMarkupDeclarations));
7474
in->qc ();
7575

7676
cxml. reset (new Xml::BinFile (toFName, in->getName ()));

xml/xml_view.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -586,7 +586,7 @@ At line ends: [<# children>|<# nodes in subtree>]\
586586
else
587587
{
588588
VectorOwn<Xml_sp::Data> markupDeclarations;
589-
xml = Xml_sp::Data::load (names, xmlFName, markupDeclarations);
589+
xml = Xml_sp::Data::load (true /*PAR*/, names, xmlFName, markupDeclarations);
590590
}
591591
ASSERT (xml);
592592
xml_. reset (xml);

0 commit comments

Comments
 (0)