Benoit Sigoure <tsuna(a)lrde.epita.fr> writes:
This allows for separate compilation.
* milena/mln/border/thickness.hh,
* milena/mln/literal/black.hh,
* milena/mln/literal/colors.hh,
* milena/mln/literal/grays.hh,
* milena/mln/literal/one.hh,
* milena/mln/literal/origin.hh,
* milena/mln/literal/white.hh,
* milena/mln/literal/zero.hh,
* milena/mln/tag/init.hh: Here.
* milena/mln/trace/entering.hh: Add a missing `inline'.
* milena/mln/trace/exiting.hh: Kill trailing whitespaces.
Signed-off-by: Benoit Sigoure <tsuna(a)lrde.epita.fr>
---
This patch enables me to use separate compilation with my Markov field
project. I guess there remains other similar cases in the code
though.
Thanks!
By the way, I think that Olena has too many small
headers. Some headers
define only one thing. I would group similar things together to reduce the
number of I/O done by the compiler. My project uses only the most basic
things in Olena (<mln/core/image2d.hh> <mln/value/rgb8.hh>
<mln/border/duplicate.hh> <mln/core/dpoint2d.hh> <mln/io/pgm/save.hh>
<mln/io/ppm/load.hh> <mln/level/stretch.hh> <mln/norm/l2.hh>) and each
compilation brings in 371 Olena headers, on everage (!).
Right, but
1. we don't care for the Olena 1.0 release;
2. we should measure before taking any action; in particular, the
different caches (the one on the hard disk drive and the OS' one at
least) probably amortize (efficiently) the cost of re-reading
multiple headers;
3. this problem is just a facet of a more general issue in Olena (and
other template-based C++ libraries): we re-compile the exact same
things too many times. Good news: I'll probably work on this very
subject next year.
[...]
12 files changed, 40 insertions(+), 56 deletions(-)
Nice!
diff --git a/milena/ChangeLog b/milena/ChangeLog
index 09c6932..f7896cc 100644
--- a/milena/ChangeLog
+++ b/milena/ChangeLog
@@ -1,3 +1,19 @@
+2007-11-29 Benoit Sigoure <tsuna(a)lrde.epita.fr>
+
+ Replace exported global variables with static ones.
+ This allows for separate compilation.
+ * milena/mln/border/thickness.hh,
+ * milena/mln/literal/black.hh,
+ * milena/mln/literal/colors.hh,
+ * milena/mln/literal/grays.hh,
+ * milena/mln/literal/one.hh,
+ * milena/mln/literal/origin.hh,
+ * milena/mln/literal/white.hh,
+ * milena/mln/literal/zero.hh,
+ * milena/mln/tag/init.hh: Here.
+ * milena/mln/trace/entering.hh: Add a missing `inline'.
+ * milena/mln/trace/exiting.hh: Kill trailing whitespaces.
+
2007-11-28 Benoit Sigoure <tsuna(a)lrde.epita.fr>
Add the missing inline keywords.
diff --git a/milena/mln/border/thickness.hh b/milena/mln/border/thickness.hh
index bcb3096..007c0e4 100644
--- a/milena/mln/border/thickness.hh
+++ b/milena/mln/border/thickness.hh
@@ -41,7 +41,7 @@ namespace mln
namespace border
{
- unsigned thickness = 3;
+ static unsigned thickness = 3;
} // end of namespace mln::border
diff --git a/milena/mln/literal/black.hh b/milena/mln/literal/black.hh
index b20dbb2..3f0813e 100644
--- a/milena/mln/literal/black.hh
+++ b/milena/mln/literal/black.hh
@@ -48,14 +48,7 @@ namespace mln
/// Literal black.
- extern const black_t& black;
-
-
-# ifndef MLN_INCLUDE_ONLY
-
- const black_t& black = black_t();
-
-# endif // ! MLN_INCLUDE_ONLY
+ static const black_t black = black_t();
} // end of namespace mln::literal
You should have tagged this with a FIXME.
Note: We still want to use `extern' -- in a later version, with a more
sound design for globals (
https://trac.lrde.org/olena/ticket/43).
diff --git a/milena/mln/literal/colors.hh
b/milena/mln/literal/colors.hh
index adca17f..ea6dc39 100644
--- a/milena/mln/literal/colors.hh
+++ b/milena/mln/literal/colors.hh
@@ -58,21 +58,13 @@ namespace mln
/// Literal red.
- extern const red_t& red;
+ static const red_t red = red_t();
/// Literal green.
- extern const green_t& green;
+ static const green_t green = green_t();
/// Literal blue.
- extern const blue_t& blue;
-
-# ifndef MLN_INCLUDE_ONLY
-
- const red_t& red = red_t();
- const green_t& green = green_t();
- const blue_t& blue = blue_t();
-
-# endif // ! MLN_INCLUDE_ONLY
+ static const blue_t blue = blue_t();
} // end of namespace mln::literal
diff --git a/milena/mln/literal/grays.hh b/milena/mln/literal/grays.hh
index 438de9e..9f61bee 100644
--- a/milena/mln/literal/grays.hh
+++ b/milena/mln/literal/grays.hh
@@ -47,14 +47,7 @@ namespace mln
};
/// Literal medium_gray.
- extern const medium_gray_t& medium_gray;
-
-
-# ifndef MLN_INCLUDE_ONLY
-
- const medium_gray_t& medium_gray = medium_gray_t();
-
-# endif // ! MLN_INCLUDE_ONLY
+ static const medium_gray_t medium_gray = medium_gray_t();
} // end of namespace mln::literal
diff --git a/milena/mln/literal/one.hh b/milena/mln/literal/one.hh
index 3b9d855..3920c1b 100644
--- a/milena/mln/literal/one.hh
+++ b/milena/mln/literal/one.hh
@@ -54,7 +54,7 @@ namespace mln
/// Literal one.
- extern const one_t& one;
+ static const one_t one = one_t();
# ifndef MLN_INCLUDE_ONLY
@@ -67,8 +67,6 @@ namespace mln
return 1;
}
- const one_t& one = one_t();
-
# endif // ! MLN_INCLUDE_ONLY
} // end of namespace mln::literal
diff --git a/milena/mln/literal/origin.hh b/milena/mln/literal/origin.hh
index bceadf7..46a9eb0 100644
--- a/milena/mln/literal/origin.hh
+++ b/milena/mln/literal/origin.hh
@@ -48,14 +48,7 @@ namespace mln
};
/// Literal origin.
- extern const origin_t& origin;
-
-# ifndef MLN_INCLUDE_ONLY
-
- const origin_t& origin = origin_t();
-
-# endif // ! MLN_INCLUDE_ONLY
-
+ static const origin_t origin = origin_t();
} // end of namespace mln::literal
diff --git a/milena/mln/literal/white.hh b/milena/mln/literal/white.hh
index 8fc0336..08740c6 100644
--- a/milena/mln/literal/white.hh
+++ b/milena/mln/literal/white.hh
@@ -48,15 +48,9 @@ namespace mln
/// Literal white.
- extern const white_t& white;
+ static const white_t white = white_t();
-# ifndef MLN_INCLUDE_ONLY
-
- const white_t& white = white_t();
-
-# endif // ! MLN_INCLUDE_ONLY
-
} // end of namespace mln::literal
} // end of namespace mln
diff --git a/milena/mln/literal/zero.hh b/milena/mln/literal/zero.hh
index 88edc7c..008c616 100644
--- a/milena/mln/literal/zero.hh
+++ b/milena/mln/literal/zero.hh
@@ -56,7 +56,7 @@ namespace mln
/// Literal zero.
- extern const zero_t& zero;
+ static const zero_t zero = zero_t();
# ifndef MLN_INCLUDE_ONLY
@@ -69,8 +69,6 @@ namespace mln
return 0;
}
- const zero_t& zero = zero_t();
-
# endif // ! MLN_INCLUDE_ONLY
} // end of namespace mln::literal
diff --git a/milena/mln/tag/init.hh b/milena/mln/tag/init.hh
index 3a63d90..125106c 100644
--- a/milena/mln/tag/init.hh
+++ b/milena/mln/tag/init.hh
@@ -40,11 +40,17 @@ namespace mln
namespace tag
{
- struct image_t {} image;
- struct domain_t {} domain;
- struct bbox_t {} bbox;
- struct border_t {} border;
- struct function_t {} function;
+ struct image_t {};
+ struct domain_t {};
+ struct bbox_t {};
+ struct border_t {};
+ struct function_t {};
+
+ static const image_t image = image_t();
+ static const domain_t domain = domain_t();
+ static const bbox_t bbox = bbox_t();
+ static const border_t border = border_t();
+ static const function_t function = function_t();
} // end of namespace mln::tag
Likewise for these.
diff --git a/milena/mln/trace/entering.hh
b/milena/mln/trace/entering.hh
index 9603ea0..e9d66ce 100644
--- a/milena/mln/trace/entering.hh
+++ b/milena/mln/trace/entering.hh
@@ -49,6 +49,7 @@ namespace mln
# ifndef MLN_INCLUDE_ONLY
+ inline
void entering(const std::string& scope)
{
if (quiet)
@@ -58,7 +59,7 @@ namespace mln
std::cout << scope << " {" << std::endl;
++tab;
}
-
+
# endif // ! MLN_INCLUDE_ONLY
} // end of namespace mln::trace
Thanks!