$include_dir="/home/hyper-archives/boost-commit/include"; include("$include_dir/msg-header.inc") ?>
Subject: [Boost-commit] svn:boost r79638 - in website/public_html/beta: . common/code doc
From: dnljms_at_[hidden]
Date: 2012-07-21 03:19:53
Author: danieljames
Date: 2012-07-21 03:19:52 EDT (Sat, 21 Jul 2012)
New Revision: 79638
URL: http://svn.boost.org/trac/boost/changeset/79638
Log:
Website: Use a class to represent versions of boost.
Added:
   website/public_html/beta/common/code/boost_version.php   (contents, props changed)
Text files modified: 
   website/public_html/beta/common/code/boost.php           |     4 +-                                      
   website/public_html/beta/common/code/boost_archive.php   |     7 +----                                   
   website/public_html/beta/common/code/boost_filters.php   |     9 +------                                 
   website/public_html/beta/common/code/boost_libraries.php |     7 ++++++                                  
   website/public_html/beta/common/code/boost_utility.php   |     6 ----                                    
   website/public_html/beta/doc/display_libs.php            |    28 ------------------------                
   website/public_html/beta/doc/libraries.php               |    44 +-------------------------------------- 
   website/public_html/beta/sitemap.xml.php                 |     3 -                                       
   8 files changed, 18 insertions(+), 90 deletions(-)
Modified: website/public_html/beta/common/code/boost.php
==============================================================================
--- website/public_html/beta/common/code/boost.php	(original)
+++ website/public_html/beta/common/code/boost.php	2012-07-21 03:19:52 EDT (Sat, 21 Jul 2012)
@@ -4,6 +4,6 @@
   Distributed under the Boost Software License, Version 1.0.
   (See accompanying file LICENSE_1_0.txt or http://www.boost.org/LICENSE_1_0.txt)
 */
-$boost_current_version = Array(1,50,0);
 require_once(dirname(__FILE__) . '/boost_config.php');
-?>
+require_once(dirname(__FILE__) . '/boost_version.php');
+boost_set_current_version(1,50,0);
Modified: website/public_html/beta/common/code/boost_archive.php
==============================================================================
--- website/public_html/beta/common/code/boost_archive.php	(original)
+++ website/public_html/beta/common/code/boost_archive.php	2012-07-21 03:19:52 EDT (Sat, 21 Jul 2012)
@@ -246,13 +246,10 @@
 // General purpose render callbacks.
 
 function boost_archive_render_callbacks($content, $params) {
-    $version_title =
-        str_replace('_', ' ',
-            preg_replace('@(?<=\d)_(?=\d)@', '.',
-                ucwords($params['version'])));
+    $version = BoostVersion::from($params['version']);
 
     $charset = $params['charset'] ? $params['charset'] : 'us-ascii';
-    $title = $params['title'] ? "$params[title] - $version_title" : 'Boost C++ Libraries';
+    $title = $params['title'] ? "$params[title] - $version" : 'Boost C++ Libraries';
 
     $head = "<meta http-equiv=\"Content-Type\" content=\"text/html; charset=${charset}\" />\n";
 
Modified: website/public_html/beta/common/code/boost_filters.php
==============================================================================
--- website/public_html/beta/common/code/boost_filters.php	(original)
+++ website/public_html/beta/common/code/boost_filters.php	2012-07-21 03:19:52 EDT (Sat, 21 Jul 2012)
@@ -11,13 +11,8 @@
 
 function alter_title($params, $text)
 {
-    $version_title =
-    	str_replace('_', ' ',
-    		preg_replace('@(?<=\d)_(?=\d)@', '.',
-    			ucwords($params['version'])));
-
-	return str_ireplace('</title>',
-		" - $version_title</title>", $text);
+    $version = BoostVersion::from($params['version']);
+    return str_ireplace('</title>', " - $version</title>", $text);
 }
 
 function html_init(&$params)
Modified: website/public_html/beta/common/code/boost_libraries.php
==============================================================================
--- website/public_html/beta/common/code/boost_libraries.php	(original)
+++ website/public_html/beta/common/code/boost_libraries.php	2012-07-21 03:19:52 EDT (Sat, 21 Jul 2012)
@@ -6,6 +6,7 @@
 */
 
 require_once(dirname(__FILE__) . '/boost_utility.php');
+require_once(dirname(__FILE__) . '/boost_version.php');
 
 class boost_libraries
 {
@@ -66,6 +67,12 @@
                         else { $lib[$val['tag']] = ''; }
                     }
                     break;
+                    case 'boost-version':
+                    {
+                        if (isset($val['value'])) { $lib[$val['tag']] = BoostVersion::from($val['value']); }
+                        else { $lib[$val['tag']] = ''; }
+                    }
+                    break;
                     case 'std-proposal':
                     case 'std-tr1':
                     {
Modified: website/public_html/beta/common/code/boost_utility.php
==============================================================================
--- website/public_html/beta/common/code/boost_utility.php	(original)
+++ website/public_html/beta/common/code/boost_utility.php	2012-07-21 03:19:52 EDT (Sat, 21 Jul 2012)
@@ -29,11 +29,7 @@
 
 function _field_cmp_boost_version_($a,$b)
 {
-    $i = explode('.',$a['boost-version']);
-    $j = explode('.',$b['boost-version']);
-    if ($i[0] == $j[0] && $i[1] == $j[1]) { return _field_cmp_($i[2]-$j[2],$a,$b); }
-    else if ($i[0] == $j[0]) { return _field_cmp_($i[1]-$j[1],$a,$b); }
-    else { return _field_cmp_($i[0]-$j[0],$a,$b); }
+    return $a['boost-version']->compare($b['boost-version']);
 }
 
 function _field_cmp_description_($a,$b)
Added: website/public_html/beta/common/code/boost_version.php
==============================================================================
--- (empty file)
+++ website/public_html/beta/common/code/boost_version.php	2012-07-21 03:19:52 EDT (Sat, 21 Jul 2012)
@@ -0,0 +1,118 @@
+<?php
+/*
+  Copyright 2007 Redshift Software, Inc.
+  Copyright 2012 Redshift Software, Inc.
+  Distributed under the Boost Software License, Version 1.0.
+  (See accompanying file LICENSE_1_0.txt or http://www.boost.org/LICENSE_1_0.txt)
+*/
+
+define('BOOST_VERSION_BETA', 0);
+define('BOOST_VERSION_RELEASED', 1);
+
+class BoostVersion {
+    var $version, $beta;
+    static $current;
+
+    function __construct($major, $minor, $point, $beta = false) {
+        $this->version = Array($major, $minor, $point);
+        $this->beta = $beta;
+    }
+
+    /**
+     * Return a BoostVersion representation of value.
+     * @return BoostVersion
+     */
+    static function from($value) {
+        if ($value instanceof BoostVersion) {
+            return $value;
+        }
+        else if (is_string($value)) {
+            if (preg_match('@(\d+)[._](\d+)[._](\d+)([._ ]?beta(\d*))?@',
+                $value, $matches))
+            {
+                return new BoostVersion(
+                    (int) $matches[1],
+                    (int) $matches[2],
+                    (int) $matches[3],
+                    empty($matches[4]) ? false : (int) $matches[5]
+                );
+            }
+            else
+            {
+                die("Invalid version");
+            }
+        }
+        else {
+            die("Can't convert to BoostVersion.");
+        }
+    }
+
+    /**
+     * The current stable release of boost.
+     * @return BoostVersion
+     */
+    static function current() {
+        if (BoostVersion::$current == null)
+            die("Version not set.");
+        return BoostVersion::$current;
+    }
+
+    /**
+     * The version the current page is displaying.
+     * @return BoostVersion
+     */
+    static function page() {
+        static $boost_version;
+
+        if ($boost_version == null) {
+            $boost_version = isset($_SERVER["PATH_INFO"]) ?
+                BoostVersion::from($_SERVER["PATH_INFO"]) :
+                BoostVersion::current();
+        }
+
+        return $boost_version;
+    }
+
+    /**
+     * Is this a beta version?
+     * @return boolean
+     */
+    function is_beta() {
+        return $this->beta !== false;
+    }
+
+    /**
+     * Compare this verison with another. Ignores the beta field
+     * (i.e. 1.50.0 beta1 == 1.50.0 beta).
+     * @return int, -1 if less than the other version, 0 if the
+     * same, +1 if more
+     */
+    function compare($x) {
+        $x = BoostVersion::from($x);
+        return $this->version < $x->version ? -1 :
+            ($this->version > $x->version ? 1 : 0);
+    }
+
+    /**
+     * A string representation appropriate for output.
+     */
+    function __toString() {
+        return implode('.', $this->version).
+            ($this->is_beta() ? ' beta'. $this->beta : '');
+    }
+
+    /**
+     * The name of the root directory for this version.
+     */
+    function dir() {
+        return 'boost_'.implode('_', $this->version).
+            ($this->is_beta() ? '_beta'. $this->beta : '');
+    }
+}
+
+function boost_set_current_version($major, $minor, $point) {
+    global $boost_current_version;
+    if (BoostVersion::$current != null)
+        die("Setting current version twice.");
+    BoostVersion::$current = new BoostVersion($major, $minor, $point);
+}
Modified: website/public_html/beta/doc/display_libs.php
==============================================================================
--- website/public_html/beta/doc/display_libs.php	(original)
+++ website/public_html/beta/doc/display_libs.php	2012-07-21 03:19:52 EDT (Sat, 21 Jul 2012)
@@ -18,32 +18,6 @@
 
 require_once(dirname(__FILE__) . '/../common/code/boost_archive.php');
 
-function boost_compare_version($version)
-{
-    if ($version && preg_match('@([0-9]+)_([0-9]+)_([0-9]+)@',$version,$vinfo))
-    {
-        array_shift($vinfo);
-
-        global $boost_current_version;
-        $v = $boost_current_version[0];
-        $r = $boost_current_version[1];
-        $p = $boost_current_version[2];
-
-        return
-          $v < $vinfo[0] ? 1 :
-          ($v > $vinfo[0] ? -1 :
-          ($r < $vinfo[1] ? 1 :
-          ($r > $vinfo[1] ? -1 :
-          ($p < $vinfo[2] ? 1 :
-          ($p > $vinfo[2] ? -1
-            : 0)))));
-    }
-    else
-    {
-        return FALSE;
-    }
-}
-
 function add_spirit_analytics($content) {
     $server = $_SERVER['HTTP_HOST'];
     
@@ -81,7 +55,7 @@
 }
 
 $location = get_archive_location('@^[/]([^/]+)[/](.*)$@',$_SERVER["PATH_INFO"],true,false);
-$compare_version = boost_compare_version($location['version']);
+$compare_version = BoostVersion::from($location['version'])->compare(BoostVersion::current());
 
 display_from_archive(
   $location,
Modified: website/public_html/beta/doc/libraries.php
==============================================================================
--- website/public_html/beta/doc/libraries.php	(original)
+++ website/public_html/beta/doc/libraries.php	2012-07-21 03:19:52 EDT (Sat, 21 Jul 2012)
@@ -21,43 +21,6 @@
     }
 }
 
-function boost_version($v,$r,$p)
-{
-    if (isset($_SERVER["PATH_INFO"]))
-    {
-        // PATH_INFO is set for redirects from a versioned URL.
-
-        $vinfo = array();
-        preg_match('@([0-9]+)_([0-9]+)_([0-9]+)@',$_SERVER["PATH_INFO"],$vinfo);
-        if (isset($vinfo[0]))
-        {
-            return
-              ($v < $vinfo[1]) ||
-              ($v == $vinfo[1] && $r < $vinfo[2]) ||
-              ($v == $vinfo[1] && $r == $vinfo[2] && $p <= $vinfo[3]);
-        }
-        else
-        {
-            return FALSE;
-        }
-    }
-    else
-    {
-        // PATH_INFO isn't set, so viewing the plain libraries
-        // page. Only display current libraries.
-
-        global $boost_current_version;
-        return
-            ($v < $boost_current_version[0]) ||
-            ($v == $boost_current_version[0] &&
-                $r < $boost_current_version[1]) || 
-            ($v == $boost_current_version[0] &&
-                $r == $boost_current_version[1] &&
-                $p <= $boost_current_version[2]);
-        return FALSE;
-    }
-}
-
 $libs = USE_SERIALIZED_INFO ?
         unserialize(file_get_contents(dirname(__FILE__) . '/../generated/libraries.txt')) :
         new boost_libraries(dirname(__FILE__) . '/libraries.xml');
@@ -132,9 +95,7 @@
 function library_filter($lib) {
   global $filter_value, $category_value;
 
-  $libversion = explode('.',$lib['boost-version']);
-
-  return boost_version($libversion[0],$libversion[1],$libversion[2]) &&
+  return BoostVersion::page()->compare($lib['boost-version']) >= 0 &&
       (!$filter_value || ($lib[$filter_value] && $lib[$filter_value] !== 'false')) &&
       (!isset($_GET['filter']) || $lib[$_GET['filter']]) &&
       (!$category_value || $category_value === 'all' ||
@@ -153,7 +114,6 @@
     }
     else
     {
-      global $boost_current_version;
       $docref = '/doc/libs/release/'.$lib['documentation'];
     }
     print ''.($lib['name'] ? $lib['name'] : $lib['key']).'';
@@ -169,7 +129,7 @@
 }
 function libavailable($lib)
 {
-  print ($lib['boost-version'] ? $lib['boost-version'] : ' ');
+  print ($lib['boost-version'] ? "{$lib['boost-version']}" : ' ');
 }
 function libstandard($lib)
 {
Modified: website/public_html/beta/sitemap.xml.php
==============================================================================
--- website/public_html/beta/sitemap.xml.php	(original)
+++ website/public_html/beta/sitemap.xml.php	2012-07-21 03:19:52 EDT (Sat, 21 Jul 2012)
@@ -12,8 +12,7 @@
 // Returns true if the library is part of the current release of boost.
 
 function current_version_filter($lib) {
-	global $boost_current_version;
-	return explode('.',$lib['boost-version']) <= $boost_current_version;
+    return BoostVersion::current()->compare($lib['boost-version']) >= 0;
 }
 
 function xmlentities($text) {