diff options
author | Christian Mollekopf <chrigi_1@fastmail.fm> | 2016-12-19 20:09:53 +0100 |
---|---|---|
committer | Christian Mollekopf <chrigi_1@fastmail.fm> | 2016-12-19 20:09:53 +0100 |
commit | e6820f5b59a3d9615863740bb16cec150206e326 (patch) | |
tree | 3d9805ddb35c2a7e24f754a45cefe266a27e6bf1 | |
parent | 890b12ba3b2889dd0d5331534c8c1f22abf4a80b (diff) | |
download | sink-e6820f5b59a3d9615863740bb16cec150206e326.tar.gz sink-e6820f5b59a3d9615863740bb16cec150206e326.zip |
Compact id representation for sinksh list.
Id clashes are possible but unlikely, but the compact id
can't be used for other operations.
-rw-r--r-- | sinksh/syntax_modules/sink_list.cpp | 26 |
1 files changed, 24 insertions, 2 deletions
diff --git a/sinksh/syntax_modules/sink_list.cpp b/sinksh/syntax_modules/sink_list.cpp index 60a70c1..8c59064 100644 --- a/sinksh/syntax_modules/sink_list.cpp +++ b/sinksh/syntax_modules/sink_list.cpp | |||
@@ -40,6 +40,19 @@ | |||
40 | namespace SinkList | 40 | namespace SinkList |
41 | { | 41 | { |
42 | 42 | ||
43 | static QByteArray compressId(bool compress, const QByteArray &id) | ||
44 | { | ||
45 | if (!compress) { | ||
46 | return id; | ||
47 | } | ||
48 | auto compactId = id.mid(1, id.length() - 2).split('-'); | ||
49 | if (compactId.isEmpty()) { | ||
50 | //Failed to compress id | ||
51 | return id; | ||
52 | } | ||
53 | return compactId.first(); | ||
54 | } | ||
55 | |||
43 | bool list(const QStringList &args_, State &state) | 56 | bool list(const QStringList &args_, State &state) |
44 | { | 57 | { |
45 | if (args_.isEmpty()) { | 58 | if (args_.isEmpty()) { |
@@ -71,6 +84,13 @@ bool list(const QStringList &args_, State &state) | |||
71 | 84 | ||
72 | } | 85 | } |
73 | 86 | ||
87 | bool compact = false; | ||
88 | auto compactIndex = args.indexOf("--compact"); | ||
89 | if (compactIndex >= 0) { | ||
90 | args.removeAt(compactIndex); | ||
91 | compact = true; | ||
92 | } | ||
93 | |||
74 | auto allIndex = args.indexOf("--all"); | 94 | auto allIndex = args.indexOf("--all"); |
75 | if (allIndex >= 0) { | 95 | if (allIndex >= 0) { |
76 | args.removeAt(allIndex); | 96 | args.removeAt(allIndex); |
@@ -102,11 +122,13 @@ bool list(const QStringList &args_, State &state) | |||
102 | 122 | ||
103 | QStringList line; | 123 | QStringList line; |
104 | line << o.resourceInstanceIdentifier(); | 124 | line << o.resourceInstanceIdentifier(); |
105 | line << o.identifier(); | 125 | line << compressId(compact, o.identifier()); |
106 | for (const auto &prop: toPrint) { | 126 | for (const auto &prop: toPrint) { |
107 | const auto value = o.getProperty(prop); | 127 | const auto value = o.getProperty(prop); |
108 | if (value.isValid()) { | 128 | if (value.isValid()) { |
109 | if (value.canConvert<QString>()) { | 129 | if (value.canConvert<Sink::ApplicationDomain::Reference>()) { |
130 | line << compressId(compact, value.toByteArray()); | ||
131 | } else if (value.canConvert<QString>()) { | ||
110 | line << value.toString(); | 132 | line << value.toString(); |
111 | } else if (value.canConvert<QByteArray>()) { | 133 | } else if (value.canConvert<QByteArray>()) { |
112 | line << value.toByteArray(); | 134 | line << value.toByteArray(); |