aknlayoutcompiler/src/LayoutWriter.cpp
changeset 0 f58d6ec98e88
child 1 b700e12870ca
equal deleted inserted replaced
-1:000000000000 0:f58d6ec98e88
       
     1 /*
       
     2 * Copyright (c) 2002 Nokia Corporation and/or its subsidiary(-ies).
       
     3 * All rights reserved.
       
     4 * This component and the accompanying materials are made available
       
     5 * under the terms of "Eclipse Public License v1.0"
       
     6 * which accompanies this distribution, and is available
       
     7 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     8 *
       
     9 * Initial Contributors:
       
    10 * Nokia Corporation - initial contribution.
       
    11 *
       
    12 * Contributors:
       
    13 *
       
    14 * Description: 
       
    15 *    
       
    16 *
       
    17 */
       
    18 
       
    19 
       
    20 #include "LayoutWriter.h"
       
    21 #include <iostream>
       
    22 #include <sstream>
       
    23 #include <set>
       
    24 #include <fstream>
       
    25 using namespace std;
       
    26 
       
    27 
       
    28 TLayoutTableWriter::TLayoutTableWriter(TLayoutTable& aTable) : iTable(aTable)
       
    29 	{
       
    30 	}
       
    31 
       
    32 TLayoutTableWriter::~TLayoutTableWriter()
       
    33 	{
       
    34 	}
       
    35 
       
    36 void TLayoutTableWriter::Write(ostream& out)
       
    37 	{
       
    38 	if (IsWindowTable())
       
    39 		{
       
    40 		WriteWindowTable(out);
       
    41 		}
       
    42 	else if (IsTextTable())
       
    43 		{
       
    44 		WriteTextTable(out);
       
    45 		}
       
    46 	else
       
    47 		{
       
    48 		cout << "Unknown " << "Table " << iTable.Name() << endl;
       
    49 		}
       
    50 	}
       
    51 
       
    52 bool TLayoutTableWriter::IsWindowTable()
       
    53 	{
       
    54 	return iTable.iType == TLayoutTable::EWindowTable;
       
    55 	}
       
    56 
       
    57 
       
    58 void TLayoutTableWriter::WriteWindowTable(ostream& out)
       
    59 	{
       
    60 	out << "WindowTable " << iTable.Name();
       
    61 	if (iTable.iParentName.size())
       
    62 		out << " : " << iTable.iParentName;
       
    63 	out << endl;
       
    64 	out << "\t{" << endl;
       
    65 
       
    66 	if (iTable.iAppend)
       
    67 		out << "\t+" << endl;
       
    68 	
       
    69 	for (int i=0; i<iTable.size(); ++i)
       
    70 		{
       
    71 		if (i>0)
       
    72 			out << "," << endl;
       
    73 		WriteWindowLine(out, *iTable[i]);
       
    74 		}
       
    75 
       
    76 	out << endl << "\t}" << endl;
       
    77 	out << endl;
       
    78 	}
       
    79 
       
    80 void TLayoutTableWriter::WriteWindowLine(ostream& out, TLayoutLine& line)
       
    81 	{
       
    82 	out << "\t\t{" << line.Name() << ", ";
       
    83 
       
    84 	for (int i=0; i<7; i++)
       
    85 		{
       
    86 		WriteCell(out, line[KWindowOutputOrder[i]]);
       
    87 		out << ", ";
       
    88 		}
       
    89 
       
    90 	out << line["Remarks"][0] << "}";
       
    91 	}
       
    92 
       
    93 void TLayoutTableWriter::WriteCell(ostream& out, TValues& values)
       
    94 	{
       
    95 	if (values.size() > 1)
       
    96 		out << "{";
       
    97 	
       
    98 	for (TValues::iterator pVal = values.begin(); pVal != values.end(); ++pVal)
       
    99 		{
       
   100 		if (pVal != values.begin())
       
   101 			out << ", ";
       
   102 		out << *pVal;
       
   103 		}
       
   104 
       
   105 	if (values.size() > 1)
       
   106 		out << "}";
       
   107 
       
   108 	if (values.iParam.length())
       
   109 		out << "[" << values.iParam << "]";
       
   110 	}
       
   111 
       
   112 
       
   113 bool TLayoutTableWriter::IsTextTable()
       
   114 	{
       
   115 	return iTable.iType == TLayoutTable::ETextTable;
       
   116 	}
       
   117 
       
   118 void TLayoutTableWriter::WriteTextTable(ostream& out)
       
   119 	{
       
   120 	out << "TextTable " << iTable.Name();
       
   121 	if (iTable.iParentName.size())
       
   122 		out << " : " << iTable.iParentName;
       
   123 	out << endl;
       
   124 	out << "\t{" << endl;
       
   125 
       
   126 	if (iTable.iAppend)
       
   127 		out << "\t+" << endl;
       
   128 	
       
   129 	for (int i=0; i<iTable.size(); ++i)
       
   130 		{
       
   131 		if (i>0)
       
   132 			out << "," << endl;
       
   133 		WriteTextLine(out, *iTable[i]);
       
   134 		}
       
   135 
       
   136 	out << endl << "\t}" << endl;
       
   137 	out << endl;
       
   138 	}
       
   139 
       
   140 void TLayoutTableWriter::WriteTextLine(ostream& out, TLayoutLine& line)
       
   141 	{
       
   142 	out << "\t\t{" << line["Font"][0] << ", ";
       
   143 
       
   144 	for (int i=0; i<6; i++)
       
   145 		{
       
   146 		WriteCell(out, line[KTextOutputOrder[i]]);
       
   147 		out << ", ";
       
   148 		}
       
   149 
       
   150 	out << line["Remarks"][0] << "}";
       
   151 	}
       
   152 
       
   153 
       
   154 TLayoutWriter::TLayoutWriter(TLayout& aLayout, const std::string& aName)
       
   155 : TLayWriterBase(aLayout, aName)
       
   156 	{
       
   157 	}
       
   158 
       
   159 void TLayoutWriter::Write(const std::string&)
       
   160 	{
       
   161 	cout << "writing layout " << iName << endl;
       
   162 	ofstream out(iName.c_str());
       
   163 	for (TLayout::iterator pTab = iLayout.begin(); pTab != iLayout.end(); ++pTab)
       
   164 		{
       
   165 		TLayoutTableWriter writer(**pTab);
       
   166 		writer.Write(out);
       
   167 		}
       
   168 	out.close();
       
   169 	}
       
   170 
       
   171 // End of File