Author: marvin
Date: Mon May 14 00:01:50 2012
New Revision: 1338008

URL: http://svn.apache.org/viewvc?rev=1338008&view=rev
Log:
Add "version" to CFCParcel.

Add a "version" member to CFCParcel.  Make "version" a required key in
cfp files.

Modified:
    lucy/trunk/clownfish/perl/lib/Clownfish/CFC.pm
    lucy/trunk/clownfish/perl/lib/Clownfish/CFC.xs
    lucy/trunk/clownfish/perl/t/403-parcel.t
    lucy/trunk/clownfish/perl/t/cfsource/Animal.cfp
    lucy/trunk/clownfish/src/CFCParcel.c
    lucy/trunk/clownfish/src/CFCParcel.h
    lucy/trunk/clownfish/src/CFCParseHeader.y

Modified: lucy/trunk/clownfish/perl/lib/Clownfish/CFC.pm
URL: 
http://svn.apache.org/viewvc/lucy/trunk/clownfish/perl/lib/Clownfish/CFC.pm?rev=1338008&r1=1338007&r2=1338008&view=diff
==============================================================================
--- lucy/trunk/clownfish/perl/lib/Clownfish/CFC.pm (original)
+++ lucy/trunk/clownfish/perl/lib/Clownfish/CFC.pm Mon May 14 00:01:50 2012
@@ -320,15 +320,16 @@ BEGIN { XSLoader::load( 'Clownfish::CFC'
     use Carp;
 
     our %new_PARAMS = (
-        name  => undef,
-        cnick => undef,
+        name    => undef,
+        cnick   => undef,
+        version => undef,
     );
 
     sub new {
         my ( $either, %args ) = @_;
         verify_args( \%new_PARAMS, %args ) or confess $@;
         confess "no subclassing allowed" unless $either eq __PACKAGE__;
-        return _new( @args{qw( name cnick )} );
+        return _new( @args{qw( name cnick version )} );
     }
 
     our %new_from_json_PARAMS = (

Modified: lucy/trunk/clownfish/perl/lib/Clownfish/CFC.xs
URL: 
http://svn.apache.org/viewvc/lucy/trunk/clownfish/perl/lib/Clownfish/CFC.xs?rev=1338008&r1=1338007&r2=1338008&view=diff
==============================================================================
--- lucy/trunk/clownfish/perl/lib/Clownfish/CFC.xs (original)
+++ lucy/trunk/clownfish/perl/lib/Clownfish/CFC.xs Mon May 14 00:01:50 2012
@@ -1061,13 +1061,14 @@ PPCODE:
 MODULE = Clownfish::CFC   PACKAGE = Clownfish::CFC::Model::Parcel
 
 SV*
-_new(name_sv, cnick_sv)
+_new(name_sv, cnick_sv, version)
     SV *name_sv;
     SV *cnick_sv;
+    CFCVersion *version;
 CODE:
     const char *name  = SvOK(name_sv)  ? SvPV_nolen(name_sv)  : NULL;
     const char *cnick = SvOK(cnick_sv) ? SvPV_nolen(cnick_sv) : NULL;
-    CFCParcel *self = CFCParcel_new(name, cnick);
+    CFCParcel *self = CFCParcel_new(name, cnick, version);
     RETVAL = S_cfcbase_to_perlref(self);
     CFCBase_decref((CFCBase*)self);
 OUTPUT: RETVAL
@@ -1137,6 +1138,7 @@ ALIAS:
     get_prefix = 6
     get_Prefix = 8
     get_PREFIX = 10
+    get_version = 12
 PPCODE:
 {
     START_SET_OR_GET_SWITCH
@@ -1165,6 +1167,11 @@ PPCODE:
                 retval = newSVpvn(value, strlen(value));
             }
             break;
+        case 12: {
+                CFCVersion *value = CFCParcel_get_version(self);
+                retval = S_cfcbase_to_perlref(value);
+            }
+            break;
     END_SET_OR_GET_SWITCH
 }
 

Modified: lucy/trunk/clownfish/perl/t/403-parcel.t
URL: 
http://svn.apache.org/viewvc/lucy/trunk/clownfish/perl/t/403-parcel.t?rev=1338008&r1=1338007&r2=1338008&view=diff
==============================================================================
--- lucy/trunk/clownfish/perl/t/403-parcel.t (original)
+++ lucy/trunk/clownfish/perl/t/403-parcel.t Mon May 14 00:01:50 2012
@@ -16,7 +16,7 @@
 use strict;
 use warnings;
 
-use Test::More tests => 10;
+use Test::More tests => 11;
 use File::Spec::Functions qw( catfile );
 
 BEGIN { use_ok('Clownfish::CFC::Model::Parcel') }
@@ -27,10 +27,15 @@ isa_ok(
     "new"
 );
 
+my $json = qq|
+        {
+            "name": "Crustacean",
+            "nickname": "Crust",
+            "version": "v0.1.0"
+        }
+|;
 isa_ok(
-    Clownfish::CFC::Model::Parcel->new_from_json(
-        json => ' { "name": "Crustacean", "nickname": "Crust" } ',
-    ),
+    Clownfish::CFC::Model::Parcel->new_from_json( json => $json ),
     "Clownfish::CFC::Model::Parcel",
     "new_from_json"
 );
@@ -44,10 +49,12 @@ isa_ok(
 );
 
 # Register singleton.
-Clownfish::CFC::Model::Parcel->new(
+my $parcel = Clownfish::CFC::Model::Parcel->new(
     name  => 'Crustacean',
     cnick => 'Crust',
-)->register;
+);
+$parcel->register;
+is( $parcel->get_version->get_vstring, 'v0', "get_version" );
 
 my $thing = Clownfish::CFC::Model::Symbol->new(
     micro_sym => 'sym',

Modified: lucy/trunk/clownfish/perl/t/cfsource/Animal.cfp
URL: 
http://svn.apache.org/viewvc/lucy/trunk/clownfish/perl/t/cfsource/Animal.cfp?rev=1338008&r1=1338007&r2=1338008&view=diff
==============================================================================
--- lucy/trunk/clownfish/perl/t/cfsource/Animal.cfp (original)
+++ lucy/trunk/clownfish/perl/t/cfsource/Animal.cfp Mon May 14 00:01:50 2012
@@ -1,3 +1,4 @@
 {
-    "name": "Animal"
+    "name": "Animal",
+    "version": "v0.1.0"
 }

Modified: lucy/trunk/clownfish/src/CFCParcel.c
URL: 
http://svn.apache.org/viewvc/lucy/trunk/clownfish/src/CFCParcel.c?rev=1338008&r1=1338007&r2=1338008&view=diff
==============================================================================
--- lucy/trunk/clownfish/src/CFCParcel.c (original)
+++ lucy/trunk/clownfish/src/CFCParcel.c Mon May 14 00:01:50 2012
@@ -26,12 +26,14 @@
 #define CFC_NEED_BASE_STRUCT_DEF
 #include "CFCBase.h"
 #include "CFCParcel.h"
+#include "CFCVersion.h"
 #include "CFCUtil.h"
 
 struct CFCParcel {
     CFCBase base;
     char *name;
     char *cnick;
+    CFCVersion *version;
     char *prefix;
     char *Prefix;
     char *PREFIX;
@@ -131,13 +133,14 @@ const static CFCMeta CFCPARCEL_META = {
 };
 
 CFCParcel*
-CFCParcel_new(const char *name, const char *cnick) {
+CFCParcel_new(const char *name, const char *cnick, CFCVersion *version) {
     CFCParcel *self = (CFCParcel*)CFCBase_allocate(&CFCPARCEL_META);
-    return CFCParcel_init(self, name, cnick);
+    return CFCParcel_init(self, name, cnick, version);
 }
 
 CFCParcel*
-CFCParcel_init(CFCParcel *self, const char *name, const char *cnick) {
+CFCParcel_init(CFCParcel *self, const char *name, const char *cnick,
+               CFCVersion *version) {
     // Validate name.
     if (!name || !S_validate_name_or_cnick(name)) {
         CFCUtil_die("Invalid name: '%s'", name ? name : "[NULL]");
@@ -156,6 +159,14 @@ CFCParcel_init(CFCParcel *self, const ch
         self->cnick = CFCUtil_strdup(name);
     }
 
+    // Default to version v0.
+    if (version) {
+        self->version = (CFCVersion*)CFCBase_incref((CFCBase*)version);
+    }
+    else {
+        self->version = CFCVersion_new("v0");
+    }
+
     // Derive prefix, Prefix, PREFIX.
     size_t cnick_len  = strlen(self->cnick);
     size_t prefix_len = cnick_len ? cnick_len + 1 : 0;
@@ -190,6 +201,7 @@ S_new_from_json(const char *json, const 
     }
     const char *name     = NULL;
     const char *nickname = NULL;
+    CFCVersion *version  = NULL;
     for (size_t i = 0, max = parsed->num_kids; i < max; i += 2) {
         JSONNode *key   = parsed->kids[i];
         JSONNode *value = parsed->kids[i + 1];
@@ -209,17 +221,29 @@ S_new_from_json(const char *json, const 
             }
             nickname = value->string;
         }
+        else if (strcmp(key->string, "version") == 0) {
+            if (value->type != JSON_STRING) {
+                CFCUtil_die("'version' must be a string (filepath %s)",
+                            path);
+            }
+            version = CFCVersion_new(value->string);
+        }
     }
     if (!name) {
         CFCUtil_die("Missing required key 'name' (filepath '%s')", path);
     }
-    CFCParcel *self = CFCParcel_new(name, nickname);
+    if (!version) {
+        CFCUtil_die("Missing required key 'version' (filepath '%s')", path);
+    }
+    CFCParcel *self = CFCParcel_new(name, nickname, version);
+    CFCBase_decref((CFCBase*)version);
 
     for (size_t i = 0, max = parsed->num_kids; i < max; i += 2) {
         JSONNode *key   = parsed->kids[i];
         JSONNode *value = parsed->kids[i + 1];
         if (strcmp(key->string, "name") == 0
             || strcmp(key->string, "nickname") == 0
+            || strcmp(key->string, "version") == 0
            ) {
             ;
         }
@@ -251,6 +275,7 @@ void
 CFCParcel_destroy(CFCParcel *self) {
     FREEMEM(self->name);
     FREEMEM(self->cnick);
+    CFCBase_decref((CFCBase*)self->version);
     FREEMEM(self->prefix);
     FREEMEM(self->Prefix);
     FREEMEM(self->PREFIX);
@@ -260,7 +285,7 @@ CFCParcel_destroy(CFCParcel *self) {
 CFCParcel*
 CFCParcel_default_parcel(void) {
     if (default_parcel == NULL) {
-        default_parcel = CFCParcel_new("", "");
+        default_parcel = CFCParcel_new("", "", NULL);
     }
     return default_parcel;
 }
@@ -269,8 +294,10 @@ CFCParcel*
 CFCParcel_clownfish_parcel(void) {
     CFCParcel *parcel = CFCParcel_fetch("Lucy");
     if (!parcel) {
-        parcel = CFCParcel_new("Lucy", "Lucy");
+        CFCVersion *version = CFCVersion_new("v0.3.0");
+        parcel = CFCParcel_new("Lucy", "Lucy", version);
         CFCParcel_register(parcel);
+        CFCBase_decref((CFCBase*)version);
         CFCBase_decref((CFCBase*)parcel);
     }
     return parcel;
@@ -280,6 +307,9 @@ int
 CFCParcel_equals(CFCParcel *self, CFCParcel *other) {
     if (strcmp(self->name, other->name)) { return false; }
     if (strcmp(self->cnick, other->cnick)) { return false; }
+    if (CFCVersion_compare_to(self->version, other->version) != 0) {
+        return false;
+    }
     return true;
 }
 
@@ -293,6 +323,11 @@ CFCParcel_get_cnick(CFCParcel *self) {
     return self->cnick;
 }
 
+CFCVersion*
+CFCParcel_get_version(CFCParcel *self) {
+    return self->version;
+}
+
 const char*
 CFCParcel_get_prefix(CFCParcel *self) {
     return self->prefix;

Modified: lucy/trunk/clownfish/src/CFCParcel.h
URL: 
http://svn.apache.org/viewvc/lucy/trunk/clownfish/src/CFCParcel.h?rev=1338008&r1=1338007&r2=1338008&view=diff
==============================================================================
--- lucy/trunk/clownfish/src/CFCParcel.h (original)
+++ lucy/trunk/clownfish/src/CFCParcel.h Mon May 14 00:01:50 2012
@@ -37,6 +37,7 @@ extern "C" {
 #endif
 
 typedef struct CFCParcel CFCParcel;
+struct CFCVersion;
 
 /** Return the parcel which has been registered for <code>name</code>.
  */
@@ -55,7 +56,8 @@ void
 CFCParcel_reap_singletons(void);
 
 CFCParcel*
-CFCParcel_new(const char *name, const char *cnick);
+CFCParcel_new(const char *name, const char *cnick,
+              struct CFCVersion *version);
 
 CFCParcel*
 CFCParcel_new_from_file(const char *path);
@@ -64,7 +66,8 @@ CFCParcel*
 CFCParcel_new_from_json(const char *json);
 
 CFCParcel*
-CFCParcel_init(CFCParcel *self, const char *name, const char *cnick);
+CFCParcel_init(CFCParcel *self, const char *name, const char *cnick,
+               struct CFCVersion *version);
 
 void
 CFCParcel_destroy(CFCParcel *self);
@@ -90,6 +93,9 @@ CFCParcel_get_name(CFCParcel *self);
 const char*
 CFCParcel_get_cnick(CFCParcel *self);
 
+struct CFCVersion*
+CFCParcel_get_version(CFCParcel *self);
+
 /** Return the all-lowercase version of the Parcel's prefix.
  */
 const char*

Modified: lucy/trunk/clownfish/src/CFCParseHeader.y
URL: 
http://svn.apache.org/viewvc/lucy/trunk/clownfish/src/CFCParseHeader.y?rev=1338008&r1=1338007&r2=1338008&view=diff
==============================================================================
--- lucy/trunk/clownfish/src/CFCParseHeader.y (original)
+++ lucy/trunk/clownfish/src/CFCParseHeader.y Mon May 14 00:01:50 2012
@@ -321,7 +321,7 @@ parcel_definition(A) ::= exposure_specif
     }
     A = CFCParcel_fetch(C);
     if (!A) {
-        A = CFCParcel_new(C, NULL);
+        A = CFCParcel_new(C, NULL, NULL);
         CFCParcel_register(A);
         CFCBase_decref((CFCBase*)A);
     }


Reply via email to