HAL
project_json.cpp
Go to the documentation of this file.
2 #include <QFile>
3 #include <QFileInfo>
4 #include <QDir>
5 
6 namespace hal {
8  : mStatus(NotExisting)
9  {
10  mPathname = QFileInfo(filename).path();
11 
12  QFile ff(filename);
13  if (!ff.exists()) return;
14 
15  mStatus = CannotOpen;
16  if (!ff.open(QIODevice::ReadOnly)) return;
17 
18  mStatus = ParseError;
19  mDocument = QJsonDocument::fromJson(ff.readAll(), &mParseError);
20  if (mParseError.error != QJsonParseError::NoError) return;
21  if (!mDocument.isObject()) return;
22 
23  mStatus = NetlistError;
24  if (!mDocument.object().contains("netlist")) return;
25  mNetlist = mDocument.object()["netlist"].toString();
26  if (mNetlist.isEmpty()) return;
27  if (QFileInfo(mNetlist).isAbsolute())
28  {
29  if (!QFileInfo(mNetlist).exists()) return;
30  }
31  else
32  {
33  if (!QFileInfo(QDir(mPathname).absoluteFilePath(mNetlist)).exists()) return;
34  }
35 
36  mStatus = GatelibError;
37  if (!mDocument.object().contains("gate_library")) return;
38  mGatelib = mDocument.object()["gate_library"].toString();
39  if (mGatelib.isEmpty()) return;
40  if (QFileInfo(mGatelib).isAbsolute())
41  {
42  if (!QFileInfo(mGatelib).exists()) return;
43  }
44  else
45  {
46  if (!QFileInfo(QDir(mPathname).absoluteFilePath(mGatelib)).exists()) return;
47  }
48 
49  mStatus = Ok;
50  }
51 
53  {
54  if (mGatelib == gl) return;
55  mGatelib = gl;
56 
57  QJsonObject obj = mDocument.object();
58  obj.remove("gate_library");
59  obj.insert("gate_library", mGatelib);
60  mDocument = QJsonDocument(obj);
61 
62  QString fname = QDir(mPathname).absoluteFilePath(".project.json");
63  QFile::remove(fname);
64  QFile of(fname);
65  if (of.open(QIODevice::WriteOnly))
66  of.write(mDocument.toJson(QJsonDocument::Compact));
67  }
68 }
Apache License January AND DISTRIBUTION Definitions License shall mean the terms and conditions for and distribution as defined by Sections through of this document Licensor shall mean the copyright owner or entity authorized by the copyright owner that is granting the License Legal Entity shall mean the union of the acting entity and all other entities that control are controlled by or are under common control with that entity For the purposes of this definition control direct or to cause the direction or management of such whether by contract or including but not limited to software source documentation and configuration files Object form shall mean any form resulting from mechanical transformation or translation of a Source including but not limited to compiled object generated and conversions to other media types Work shall mean the work of whether in Source or Object made available under the as indicated by a copyright notice that is included in or attached to the whether in Source or Object that is based or other modifications as a an original work of authorship For the purposes of this Derivative Works shall not include works that remain separable or merely the Work and Derivative Works thereof Contribution shall mean any work of including the original version of the Work and any modifications or additions to that Work or Derivative Works that is intentionally submitted to Licensor for inclusion in the Work by the copyright owner or by an individual or Legal Entity authorized to submit on behalf of the copyright owner For the purposes of this submitted means any form of or written communication sent to the Licensor or its including but not limited to communication on electronic mailing source code control and issue tracking systems that are managed or on behalf of
ProjectJson(const QString &filename)
Definition: project_json.cpp:7
void setGateLibraryFilename(const QString &gl)
QString absoluteFilePath(const QString &fileName) const const
bool remove()
QString path() const const
QJsonDocument fromJson(const QByteArray &json, QJsonParseError *error)
bool isObject() const const
QJsonObject object() const const
QByteArray toJson() const const
bool contains(const QString &key) const const
QJsonObject::iterator insert(const QString &key, const QJsonValue &value)
void remove(const QString &key)
bool isEmpty() const const