From 6836c4070af81c4176db8f61dbf41e8f384f75aa Mon Sep 17 00:00:00 2001 From: Gerard Date: Thu, 11 Jun 2020 16:45:43 +0100 Subject: [PATCH] FluidLabelSet: help file review, minor changes and formatting --- release-packaging/Classes/FluidLabelSet.sc | 90 +++++++++---------- .../HelpSource/Classes/FluidDataSet.schelp | 2 +- .../HelpSource/Classes/FluidLabelSet.schelp | 80 +++++++---------- 3 files changed, 76 insertions(+), 96 deletions(-) diff --git a/release-packaging/Classes/FluidLabelSet.sc b/release-packaging/Classes/FluidLabelSet.sc index e4e396c..4c0dc3a 100644 --- a/release-packaging/Classes/FluidLabelSet.sc +++ b/release-packaging/Classes/FluidLabelSet.sc @@ -10,93 +10,89 @@ FluidLabelSet : FluidManipulationClient { serverCaches = FluidServerCache.new; } - *at{ |server, id| - ^serverCaches.tryPerform(\at, server,id) + *at{ |server, name| + ^serverCaches.tryPerform(\at, server, name) } - *new { |server,name| + *new { |server,name| serverCaches.at(server,name) !? { FluidLabelSetExistsError("A FluidLabelSet called % already exists.".format(name)).throw; }; ^super.new(server,*FluidManipulationClient.prServerString(name))!?{|inst|inst.init(name);inst} - } + } - init { |name| + init { |name| id = name; this.cache; - } + } cache { serverCaches.initCache(server); serverCaches.put(server,id,this); } - asString { - ^"FluidLabelSet(%)".format(id).asString; - } + asString { + ^"FluidLabelSet(%)".format(id).asString; + } asSymbol { ^id } + *asUGenInput { |input| + var ascii = input.asString.ascii; + ^[ascii.size].addAll(ascii) + } - - *asUGenInput { |input| - var ascii = input.asString.ascii; - ^[ascii.size].addAll(ascii) - } - - addLabel{|id, label, action| - this.prSendMsg(\addLabel,[id.asString, label.asString],action); - } + addLabel{|id, label, action| + this.prSendMsg(\addLabel, [id.asString, label.asString],action); + } updateLabel{|id, label, action| - this.prSendMsg(\updateLabel,[id.asString, label.asString],action); + this.prSendMsg(\updateLabel, [id.asString, label.asString],action); } + getLabel{|id, action| + this.prSendMsg(\getLabel, [id.asString], action,[string(FluidMessageResponse,_,_)]); + } - getLabel{|id, action| - this.prSendMsg(\getLabel,[id.asString],action,[string(FluidMessageResponse,_,_)]); - } - - deleteLabel{|id, action| - this.prSendMsg(\deleteLabel,[id.asString],action); - } + deleteLabel{|id, action| + this.prSendMsg(\deleteLabel, [id.asString],action); + } - cols {|action| + cols {|action| action ?? {action = postit}; - this.prSendMsg(\cols,[],action,[number(FluidMessageResponse,_,_)]); - } + this.prSendMsg(\cols, [], action, [number(FluidMessageResponse,_,_)]); + } - read{|filename,action| - this.prSendMsg(\read,[filename.asString],action); - } + read{|filename,action| + this.prSendMsg(\read, [filename.asString], action); + } - write{|filename,action| - this.prSendMsg(\write,[filename.asString],action); - } + write{|filename,action| + this.prSendMsg(\write, [filename.asString], action); + } - size { |action| + size {|action| action ?? {action = postit}; - this.prSendMsg(\size,[],action,[number(FluidMessageResponse,_,_)]); - } + this.prSendMsg(\size,[], action, [number(FluidMessageResponse,_,_)]); + } - clear { |action| - this.prSendMsg(\clear,[],action); - } + clear {|action| + this.prSendMsg(\clear,[], action); + } - free { |action| - serverCaches.remove(server,id); + free {|action| + serverCaches.remove(server, id); super.free; } - *freeAll { |server| - serverCaches.do(server,{|x|x.free;}); + *freeAll {|server| + serverCaches.do(server,{|x| x.free;}); } print { |action| action ?? {action = postit}; - this.prSendMsg(\print,[],action,[string(FluidMessageResponse,_,_)]); + this.prSendMsg(\print,[], action, [string(FluidMessageResponse,_,_)]); } - } diff --git a/release-packaging/HelpSource/Classes/FluidDataSet.schelp b/release-packaging/HelpSource/Classes/FluidDataSet.schelp index 8d8f125..8a400b2 100644 --- a/release-packaging/HelpSource/Classes/FluidDataSet.schelp +++ b/release-packaging/HelpSource/Classes/FluidDataSet.schelp @@ -59,7 +59,7 @@ METHOD:: free Destroy the object on the server. METHOD:: read -Read a data set from a JSON file on disk. +Read a data set from a JSON file on disk, replacing the current contents. ​ METHOD:: write Write the data set to disk as a JSON file. diff --git a/release-packaging/HelpSource/Classes/FluidLabelSet.schelp b/release-packaging/HelpSource/Classes/FluidLabelSet.schelp index 77d812c..353729c 100644 --- a/release-packaging/HelpSource/Classes/FluidLabelSet.schelp +++ b/release-packaging/HelpSource/Classes/FluidLabelSet.schelp @@ -9,21 +9,19 @@ FluidLabelSet is a server-side container of associations between labels (from a CLASSMETHODS:: -PRIVATE:: kr - METHOD:: new Make a new instance of a label set, uniquely identified by its name. Creating an instance with a name already in use will throw an exception. Use link::Classes/FluidLabelSet#*at:: or free the existing instance. ARGUMENT:: server -The link::Classes/Server:: on which to create the label set +The link::Classes/Server:: on which to create the label set. ARGUMENT:: name -symbol or string with the label set's name +symbol with the label set's name. METHOD:: at -Retreive a label set from the cache +Retrieve a label set from the cache. ARGUMENT:: server -The link::Classes/Server:: on which to create the label set +The link::Classes/Server:: on which to create the label set. ARGUMENT:: id -symbol or string with the label set's name +symbol or string with the label set's name. INSTANCEMETHODS:: @@ -31,68 +29,54 @@ INSTANCEMETHODS:: PRIVATE:: init, id METHOD:: addLabel -Add a label to the label set +Add a label to the label set. ARGUMENT:: id -symbol or string with the ID for this label +symbol or string with the ID for this label. ARGUMENT:: label -symbol or string with the label to add +symbol or string with the label to add. ARGUMENT:: action -function to run when the operation completes +function to run when the operation completes. METHOD:: updateLabel -Change a label in the label set -ARGUMENT:: id -symbol or string with the ID for this label -ARGUMENT:: label -symbol or string with the label to add -ARGUMENT:: action -function to run when the operation completes +Change a label in the label set. METHOD:: getLabel -Retreive the label associated with an ID. Will report an error if the ID isn't present in the set -ARGUMENT:: id -symbol or string with the ID to retreive. -ARGUMENT:: action -A function to run when the server responds, with the label as its argument +Retrieve the label associated with an ID. Will report an error if the ID isn't present in the set. METHOD:: deleteLabel -Remove a id-label pair from the label set -ARGUMENT:: id -symbol or string with the ID to remove -ARGUMENT:: action -A function to run when the label has been removed +Remove a id-label pair from the label set. METHOD:: clear -Empty the label set -ARGUMENT:: action -Function to run whrn the action completes +Empty the label set. METHOD:: size -Report the number of items in the label set -ARGUMENT:: action -A function to run when the server responds, taking the size as its argument +Report the number of items in the label set. METHOD:: cols -Returns the dimensionality of the link::Classes/FluidDataSet:: associated with this label set -ARGUMENT:: action -A function to run when the server responds, with the dimensionality as its argument +Report the number of labels per point (at the moment only 1 is supported). METHOD:: write Write this label set to disk as a JSON file. -ARGUMENT:: filename -Absolute path of file to write -ARGUMENT:: action -A function to run when the file is written METHOD:: read -Read a label set from a JSON file on disk -ARGUMENT:: filename -Absolute path of the file to read -ARGUMENT:: action -A function to run when the file is read +Read a label set from a JSON file on disk, replacing the current contents. + +METHOD:: dump +Get the contents of the label set as a Dictionary (note: uses a temporary file under the hood); + +METHOD:: load +Fill the label set with the contents of a dictionary, replacing its current contents (note: uses a temporary file under the hood). + +METHOD:: print +Post an abbreviated content of the label set in the window by default, but you can supply a custom action instead. EXAMPLES:: code:: -(some example code) -:: \ No newline at end of file +~ls = FluidLabelSet.new(s,\labelset_example); + +["one", "two", "three"].collect{|x,i| ~ls.addLabel(i, x);}; +~ls.print; + +~ls.free; +::